1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ws.datamodel.alphafold; |
22 |
|
|
23 |
|
import java.awt.Color; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.BitSet; |
26 |
|
|
27 |
|
import jalview.datamodel.ContactListI; |
28 |
|
import jalview.datamodel.ContactListImpl; |
29 |
|
import jalview.datamodel.ContactListProviderI; |
30 |
|
import jalview.datamodel.ContactMatrixI; |
31 |
|
import jalview.datamodel.GroupSet; |
32 |
|
import jalview.datamodel.GroupSetI; |
33 |
|
import jalview.datamodel.Mapping; |
34 |
|
import jalview.datamodel.SequenceI; |
35 |
|
import jalview.util.MapList; |
36 |
|
import jalview.ws.datamodel.MappableContactMatrixI; |
37 |
|
|
|
|
| 77% |
Uncovered Elements: 55 (239) |
Complexity: 80 |
Complexity Density: 0.62 |
|
38 |
|
public abstract class MappableContactMatrix<T extends MappableContactMatrix<T>> |
39 |
|
implements MappableContactMatrixI |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
protected ContactMatrixI mappedMatrix = null; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
3917 |
public ContactListI getContactList(int column)... |
47 |
|
{ |
48 |
3917 |
return mappedMatrix.getContactList(column); |
49 |
|
} |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
120 |
public float getMin()... |
52 |
|
{ |
53 |
120 |
return mappedMatrix.getMin(); |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
127 |
public float getMax()... |
57 |
|
{ |
58 |
127 |
return mappedMatrix.getMax(); |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
2142 |
public int getWidth()... |
62 |
|
{ |
63 |
2142 |
return mappedMatrix.getWidth(); |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
103448 |
public int getHeight()... |
67 |
|
{ |
68 |
103448 |
return mappedMatrix.getHeight(); |
69 |
|
} |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0 |
@Override... |
72 |
|
public ContactMatrixI getMappedMatrix() |
73 |
|
{ |
74 |
0 |
return mappedMatrix; |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
14706 |
@Override... |
78 |
|
public GroupSetI getGroupSet() |
79 |
|
{ |
80 |
14706 |
return mappedMatrix.getGroupSet(); |
81 |
|
}; |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
2 |
@Override... |
84 |
|
public void setGroupSet(GroupSet makeGroups) |
85 |
|
{ |
86 |
2 |
mappedMatrix.setGroupSet(makeGroups); |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
SequenceI refSeq = null; |
94 |
|
|
95 |
|
MapList toSeq = null; |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
int length; |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
146593 |
@Override... |
103 |
|
public boolean hasReferenceSeq() |
104 |
|
{ |
105 |
146593 |
return (refSeq != null); |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
118 |
@Override... |
109 |
|
public SequenceI getReferenceSeq() |
110 |
|
{ |
111 |
118 |
return refSeq; |
112 |
|
} |
113 |
|
|
|
|
| 56.2% |
Uncovered Elements: 7 (16) |
Complexity: 6 |
Complexity Density: 0.75 |
|
114 |
11 |
@Override... |
115 |
|
public MapList getMapFor(SequenceI mapSeq) |
116 |
|
{ |
117 |
11 |
if (refSeq != null) |
118 |
|
{ |
119 |
14 |
while (mapSeq != refSeq && mapSeq.getDatasetSequence() != null) |
120 |
|
{ |
121 |
3 |
mapSeq = mapSeq.getDatasetSequence(); |
122 |
|
} |
123 |
11 |
if (mapSeq != refSeq) |
124 |
|
{ |
125 |
0 |
return null; |
126 |
|
} |
127 |
|
} |
128 |
|
else |
129 |
|
{ |
130 |
0 |
if (mapSeq != null) |
131 |
|
{ |
132 |
|
|
133 |
0 |
return null; |
134 |
|
} |
135 |
|
} |
136 |
|
|
137 |
11 |
return toSeq; |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
@param |
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
146 |
161 |
public void setRefSeq(SequenceI _refSeq)... |
147 |
|
{ |
148 |
161 |
refSeq = _refSeq; |
149 |
163 |
while (refSeq.getDatasetSequence() != null) |
150 |
|
{ |
151 |
2 |
refSeq = refSeq.getDatasetSequence(); |
152 |
|
} |
153 |
161 |
length = _refSeq.getEnd() - _refSeq.getStart() + 1; |
154 |
|
|
155 |
|
{ |
156 |
161 |
toSeq = new MapList( |
157 |
|
new int[] |
158 |
|
{ _refSeq.getStart(), _refSeq.getEnd() }, |
159 |
|
new int[] |
160 |
|
{ 0, length - 1 }, 1, 1); |
161 |
|
} |
162 |
|
} |
163 |
|
|
|
|
| 80% |
Uncovered Elements: 9 (45) |
Complexity: 10 |
Complexity Density: 0.37 |
|
164 |
40 |
public T liftOver(SequenceI newRefSeq, Mapping sp2sq)... |
165 |
|
{ |
166 |
40 |
if (sp2sq.getMappedWidth() != sp2sq.getWidth()) |
167 |
|
{ |
168 |
|
|
169 |
|
|
170 |
0 |
throw new Error( |
171 |
|
"liftOver currently not implemented for transfer of annotation between different types of seqeunce"); |
172 |
|
} |
173 |
40 |
boolean mapIsTo = (sp2sq != null) ? (sp2sq.getTo() == refSeq) : false; |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
40 |
int[] refMap = toSeq.locateInFrom(0, length - 1); |
179 |
40 |
ArrayList<Integer> newFromMap = new ArrayList<Integer>(); |
180 |
40 |
int last = -1; |
181 |
80 |
for (int i = 0; i < refMap.length; i += 2) |
182 |
|
{ |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
40 |
int[] sp2map = mapIsTo |
187 |
|
? sp2sq.getMap().locateInFrom(refMap[i], refMap[i + 1]) |
188 |
|
: sp2sq.getMap().locateInTo(refMap[i], refMap[i + 1]); |
189 |
40 |
if (sp2map == null) |
190 |
|
{ |
191 |
0 |
continue; |
192 |
|
} |
193 |
|
|
194 |
81 |
for (int spm = 0; spm < sp2map.length; spm += 2) |
195 |
|
{ |
196 |
|
|
197 |
41 |
if (last > -1) |
198 |
|
{ |
199 |
1 |
if (sp2map[spm] != last + 1) |
200 |
|
{ |
201 |
1 |
newFromMap.add(sp2map[spm]); |
202 |
|
} |
203 |
|
else |
204 |
|
{ |
205 |
0 |
newFromMap.remove(newFromMap.size() - 1); |
206 |
|
} |
207 |
|
} |
208 |
|
else |
209 |
|
{ |
210 |
40 |
newFromMap.add(sp2map[spm]); |
211 |
|
} |
212 |
41 |
last = sp2map[spm + 1]; |
213 |
41 |
newFromMap.add(last); |
214 |
|
} |
215 |
|
} |
216 |
40 |
if ((newFromMap.size() % 2) != 0) |
217 |
|
{ |
218 |
|
|
219 |
0 |
throw new Error("PAEMatrix liftover failed."); |
220 |
|
} |
221 |
40 |
int fromIntMap[] = new int[newFromMap.size()]; |
222 |
40 |
int ipos = 0; |
223 |
40 |
for (Integer i : newFromMap) |
224 |
|
{ |
225 |
82 |
fromIntMap[ipos++] = i; |
226 |
|
} |
227 |
40 |
MapList newFromMapList = new MapList(fromIntMap, |
228 |
|
new int[] |
229 |
|
{ 0, length - 1 }, 1, 1); |
230 |
|
|
231 |
40 |
T newCM = newMappableContactMatrix(newRefSeq, newFromMapList); |
232 |
40 |
return newCM; |
233 |
|
} |
234 |
|
|
235 |
|
protected abstract T newMappableContactMatrix(SequenceI newRefSeq, |
236 |
|
MapList newFromMapList); |
237 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
238 |
5 |
@Override... |
239 |
|
public int[] getMappedPositionsFor(final SequenceI localFrame, |
240 |
|
final int column) |
241 |
|
{ |
242 |
5 |
return getMappedPositionsFor(localFrame, column, column); |
243 |
|
} |
244 |
|
|
|
|
| 70% |
Uncovered Elements: 9 (30) |
Complexity: 9 |
Complexity Density: 0.56 |
|
245 |
5 |
@Override... |
246 |
|
public int[] getMappedPositionsFor(final SequenceI localFrame, int from, |
247 |
|
int to) |
248 |
|
{ |
249 |
5 |
if (localFrame == null) |
250 |
|
{ |
251 |
0 |
throw new Error("Unimplemented when no local sequence given."); |
252 |
|
} |
253 |
5 |
SequenceI lf = localFrame, uf = refSeq; |
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
6 |
while (lf.getDatasetSequence() != null |
259 |
|
|| uf.getDatasetSequence() != null) |
260 |
|
{ |
261 |
1 |
if (lf.getDatasetSequence() != null) |
262 |
|
{ |
263 |
1 |
lf = lf.getDatasetSequence(); |
264 |
|
} |
265 |
1 |
if (uf.getDatasetSequence() != null) |
266 |
|
{ |
267 |
0 |
uf = uf.getDatasetSequence(); |
268 |
|
} |
269 |
|
} |
270 |
5 |
if (lf != uf) |
271 |
|
{ |
272 |
|
|
273 |
0 |
throw new Error("This Matrix associated with '" + refSeq.getName() |
274 |
|
+ "' is not mappable for the given localFrame sequence. (" |
275 |
|
+ localFrame.getName() + ")"); |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
|
|
280 |
5 |
if (toSeq == null) |
281 |
|
{ |
282 |
|
|
283 |
0 |
return new int[] { from, to }; |
284 |
|
} |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
5 |
int[] mappedPositions = toSeq.locateInFrom(from, to); |
289 |
5 |
if (mappedPositions == null) |
290 |
|
{ |
291 |
2 |
return null; |
292 |
|
} |
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
3 |
return mappedPositions; |
317 |
|
} |
318 |
|
|
|
|
| 79.2% |
Uncovered Elements: 10 (48) |
Complexity: 16 |
Complexity Density: 0.57 |
|
319 |
3789 |
@Override... |
320 |
|
public ContactListI getMappableContactList(final SequenceI localFrame, |
321 |
|
final int column) |
322 |
|
{ |
323 |
3789 |
final int _column; |
324 |
3789 |
final int _lcolumn; |
325 |
3789 |
if (localFrame == null) |
326 |
|
{ |
327 |
0 |
throw new Error("Unimplemented when no local sequence given."); |
328 |
|
} |
329 |
|
|
330 |
|
|
331 |
|
|
332 |
3789 |
final MappableContactMatrix us = this; |
333 |
3789 |
_lcolumn = localFrame.findPosition(column); |
334 |
|
|
335 |
3789 |
if (toSeq != null) |
336 |
|
{ |
337 |
3789 |
SequenceI lf = localFrame, uf = refSeq; |
338 |
|
|
339 |
|
|
340 |
|
|
341 |
7458 |
while (lf.getDatasetSequence() != null |
342 |
|
|| uf.getDatasetSequence() != null) |
343 |
|
{ |
344 |
3669 |
if (lf.getDatasetSequence() != null) |
345 |
|
{ |
346 |
3669 |
lf = lf.getDatasetSequence(); |
347 |
|
} |
348 |
3669 |
if (uf.getDatasetSequence() != null) |
349 |
|
{ |
350 |
2 |
uf = uf.getDatasetSequence(); |
351 |
|
} |
352 |
|
} |
353 |
3789 |
if (lf != uf) |
354 |
|
{ |
355 |
|
|
356 |
0 |
throw new Error("This Matrix associated with '" + refSeq.getName() |
357 |
|
+ "' is not mappable for the given localFrame sequence. (" |
358 |
|
+ localFrame.getName() + ")"); |
359 |
|
} |
360 |
|
|
361 |
3789 |
int[] word = toSeq.locateInTo(_lcolumn, _lcolumn); |
362 |
3789 |
if (word == null) |
363 |
|
{ |
364 |
11 |
return null; |
365 |
|
} |
366 |
3778 |
_column = word[0]; |
367 |
|
} |
368 |
|
else |
369 |
|
{ |
370 |
|
|
371 |
0 |
_column = _lcolumn; |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
3778 |
if (_column < 0 || ((toSeq != null && _column > toSeq.getToHighest()) |
376 |
|
|| (toSeq == null && getHeight() <= _column))) |
377 |
|
{ |
378 |
0 |
return null; |
379 |
|
} |
380 |
|
|
381 |
|
|
382 |
3778 |
final int[] matrixRange = toSeq == null |
383 |
|
? new int[] |
384 |
|
{ localFrame.getStart(), localFrame.getEnd() } |
385 |
|
: toSeq.locateInTo(localFrame.getStart(), localFrame.getEnd()); |
386 |
|
|
387 |
3778 |
int h = 0; |
388 |
7556 |
for (int p = 0; p < matrixRange.length; p += 2) |
389 |
|
{ |
390 |
3778 |
h += 1 + Math.abs(matrixRange[p + 1] - matrixRange[p]); |
391 |
|
} |
392 |
3778 |
final int rangeHeight = h; |
393 |
|
|
394 |
|
|
395 |
3778 |
return new ContactListImpl(new ContactListProviderI() |
396 |
|
{ |
397 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
398 |
0 |
public int getColumn()... |
399 |
|
{ |
400 |
0 |
return column; |
401 |
|
} |
402 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
403 |
0 |
@Override... |
404 |
|
public int getPosition() |
405 |
|
{ |
406 |
0 |
return _column; |
407 |
|
} |
408 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
409 |
291560 |
@Override... |
410 |
|
public int getContactHeight() |
411 |
|
{ |
412 |
291560 |
return rangeHeight; |
413 |
|
} |
414 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
415 |
459787 |
@Override... |
416 |
|
public double getContactAt(int mcolumn) |
417 |
|
{ |
418 |
459787 |
if (mcolumn < 0 || mcolumn >= rangeHeight) |
419 |
|
{ |
420 |
0 |
return -1; |
421 |
|
} |
422 |
459787 |
return getElementAt(_column, locateInRange(mcolumn)); |
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
} |
435 |
|
|
|
|
| 83.3% |
Uncovered Elements: 4 (24) |
Complexity: 8 |
Complexity Density: 0.57 |
|
436 |
146474 |
@Override... |
437 |
|
public int[] getMappedPositionsFor(int cStart, int cEnd) |
438 |
|
{ |
439 |
146474 |
if (!hasReferenceSeq()) |
440 |
|
{ |
441 |
0 |
return ContactListProviderI.super.getMappedPositionsFor(cStart, |
442 |
|
cEnd); |
443 |
|
} |
444 |
|
|
445 |
146474 |
int realCstart = locateInRange(cStart); |
446 |
146474 |
int realCend = locateInRange(cEnd); |
447 |
|
|
448 |
|
|
449 |
|
|
450 |
146474 |
int[] mappedPositions = toSeq.locateInFrom(realCstart, realCend); |
451 |
146466 |
if (mappedPositions != null) |
452 |
|
{ |
453 |
146466 |
int s = -1, e = -1; |
454 |
439389 |
for (int p = 0; p < mappedPositions.length; p++) |
455 |
|
{ |
456 |
292950 |
if (s == -1 && mappedPositions[p] >= localFrame.getStart()) |
457 |
|
{ |
458 |
146472 |
s = p; |
459 |
|
} |
460 |
292896 |
if (e == -1 || mappedPositions[p] <= localFrame.getEnd()) |
461 |
|
{ |
462 |
|
|
463 |
292896 |
e = p; |
464 |
|
|
465 |
292896 |
mappedPositions[p] = localFrame.findIndex(mappedPositions[p]); |
466 |
|
} |
467 |
|
} |
468 |
|
} |
469 |
146474 |
return mappedPositions; |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
@return |
474 |
|
|
|
|
| 57.1% |
Uncovered Elements: 3 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
475 |
751465 |
private int locateInRange(int mcolumn)... |
476 |
|
{ |
477 |
|
|
478 |
751470 |
int h = 0, p = 0; |
479 |
751492 |
while (h < mcolumn && p + 2 < matrixRange.length) |
480 |
|
{ |
481 |
0 |
h += 1 + Math.abs(matrixRange[p + 1] - matrixRange[p]); |
482 |
0 |
p += 2; |
483 |
|
} |
484 |
751499 |
return matrixRange[p] + mcolumn - h; |
485 |
|
} |
486 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
487 |
3661 |
@Override... |
488 |
|
public Color getColourForGroup() |
489 |
|
{ |
490 |
3661 |
BitSet gp = us.getGroupsFor(_column); |
491 |
3661 |
Color col = us.getColourForGroup(gp); |
492 |
3661 |
return col; |
493 |
|
} |
494 |
|
}); |
495 |
|
} |
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
|
502 |
|
@param |
503 |
|
@param |
504 |
|
@return |
505 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
506 |
459708 |
public double getElementAt(int _column, int i)... |
507 |
|
{ |
508 |
459708 |
return mappedMatrix.getElementAt(_column, i); |
509 |
|
} |
510 |
|
|
|
|
| 57.1% |
Uncovered Elements: 3 (7) |
Complexity: 4 |
Complexity Density: 4 |
|
511 |
33 |
@Override... |
512 |
|
public int hashCode() |
513 |
|
{ |
514 |
33 |
return 7 * (refSeq != null ? refSeq.hashCode() : 0) |
515 |
33 |
+ 11 * (toSeq != null ? toSeq.hashCode() : 0) |
516 |
33 |
+ 13 * (mappedMatrix != null ? mappedMatrix.hashCode() : 0) |
517 |
|
+ length * 3; |
518 |
|
} |
519 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
520 |
3 |
@Override... |
521 |
|
public boolean equals(Object obj) |
522 |
|
{ |
523 |
3 |
if (obj == null || !(obj.getClass().equals(getClass()))) |
524 |
|
{ |
525 |
0 |
return false; |
526 |
|
} |
527 |
3 |
T them = (T) obj; |
528 |
3 |
return mappedMatrix == them.mappedMatrix && length == them.length |
529 |
|
&& refSeq == them.refSeq && toSeq.equals(them.toSeq); |
530 |
|
|
531 |
|
} |
532 |
|
} |