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 |
|
|
|
|
| 0% |
Uncovered Elements: 239 (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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
0 |
public ContactListI getContactList(int column)... |
47 |
|
{ |
48 |
0 |
return mappedMatrix.getContactList(column); |
49 |
|
} |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
0 |
public float getMin()... |
52 |
|
{ |
53 |
0 |
return mappedMatrix.getMin(); |
54 |
|
} |
55 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
0 |
public float getMax()... |
57 |
|
{ |
58 |
0 |
return mappedMatrix.getMax(); |
59 |
|
} |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
0 |
public int getWidth()... |
62 |
|
{ |
63 |
0 |
return mappedMatrix.getWidth(); |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0 |
public int getHeight()... |
67 |
|
{ |
68 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
@Override... |
78 |
|
public GroupSetI getGroupSet() |
79 |
|
{ |
80 |
0 |
return mappedMatrix.getGroupSet(); |
81 |
|
}; |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
0 |
@Override... |
84 |
|
public void setGroupSet(GroupSet makeGroups) |
85 |
|
{ |
86 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
0 |
@Override... |
103 |
|
public boolean hasReferenceSeq() |
104 |
|
{ |
105 |
0 |
return (refSeq != null); |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
0 |
@Override... |
109 |
|
public SequenceI getReferenceSeq() |
110 |
|
{ |
111 |
0 |
return refSeq; |
112 |
|
} |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 6 |
Complexity Density: 0.75 |
|
114 |
0 |
@Override... |
115 |
|
public MapList getMapFor(SequenceI mapSeq) |
116 |
|
{ |
117 |
0 |
if (refSeq != null) |
118 |
|
{ |
119 |
0 |
while (mapSeq != refSeq && mapSeq.getDatasetSequence() != null) |
120 |
|
{ |
121 |
0 |
mapSeq = mapSeq.getDatasetSequence(); |
122 |
|
} |
123 |
0 |
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 |
0 |
return toSeq; |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
@param |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
146 |
0 |
public void setRefSeq(SequenceI _refSeq)... |
147 |
|
{ |
148 |
0 |
refSeq = _refSeq; |
149 |
0 |
while (refSeq.getDatasetSequence() != null) |
150 |
|
{ |
151 |
0 |
refSeq = refSeq.getDatasetSequence(); |
152 |
|
} |
153 |
0 |
length = _refSeq.getEnd() - _refSeq.getStart() + 1; |
154 |
|
|
155 |
|
{ |
156 |
0 |
toSeq = new MapList( |
157 |
|
new int[] |
158 |
|
{ _refSeq.getStart(), _refSeq.getEnd() }, |
159 |
|
new int[] |
160 |
|
{ 0, length - 1 }, 1, 1); |
161 |
|
} |
162 |
|
} |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 10 |
Complexity Density: 0.37 |
|
164 |
0 |
public T liftOver(SequenceI newRefSeq, Mapping sp2sq)... |
165 |
|
{ |
166 |
0 |
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 |
0 |
boolean mapIsTo = (sp2sq != null) ? (sp2sq.getTo() == refSeq) : false; |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
0 |
int[] refMap = toSeq.locateInFrom(0, length - 1); |
179 |
0 |
ArrayList<Integer> newFromMap = new ArrayList<Integer>(); |
180 |
0 |
int last = -1; |
181 |
0 |
for (int i = 0; i < refMap.length; i += 2) |
182 |
|
{ |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
0 |
int[] sp2map = mapIsTo |
187 |
|
? sp2sq.getMap().locateInFrom(refMap[i], refMap[i + 1]) |
188 |
|
: sp2sq.getMap().locateInTo(refMap[i], refMap[i + 1]); |
189 |
0 |
if (sp2map == null) |
190 |
|
{ |
191 |
0 |
continue; |
192 |
|
} |
193 |
|
|
194 |
0 |
for (int spm = 0; spm < sp2map.length; spm += 2) |
195 |
|
{ |
196 |
|
|
197 |
0 |
if (last > -1) |
198 |
|
{ |
199 |
0 |
if (sp2map[spm] != last + 1) |
200 |
|
{ |
201 |
0 |
newFromMap.add(sp2map[spm]); |
202 |
|
} |
203 |
|
else |
204 |
|
{ |
205 |
0 |
newFromMap.remove(newFromMap.size() - 1); |
206 |
|
} |
207 |
|
} |
208 |
|
else |
209 |
|
{ |
210 |
0 |
newFromMap.add(sp2map[spm]); |
211 |
|
} |
212 |
0 |
last = sp2map[spm + 1]; |
213 |
0 |
newFromMap.add(last); |
214 |
|
} |
215 |
|
} |
216 |
0 |
if ((newFromMap.size() % 2) != 0) |
217 |
|
{ |
218 |
|
|
219 |
0 |
throw new Error("PAEMatrix liftover failed."); |
220 |
|
} |
221 |
0 |
int fromIntMap[] = new int[newFromMap.size()]; |
222 |
0 |
int ipos = 0; |
223 |
0 |
for (Integer i : newFromMap) |
224 |
|
{ |
225 |
0 |
fromIntMap[ipos++] = i; |
226 |
|
} |
227 |
0 |
MapList newFromMapList = new MapList(fromIntMap, |
228 |
|
new int[] |
229 |
|
{ 0, length - 1 }, 1, 1); |
230 |
|
|
231 |
0 |
T newCM = newMappableContactMatrix(newRefSeq, newFromMapList); |
232 |
0 |
return newCM; |
233 |
|
} |
234 |
|
|
235 |
|
protected abstract T newMappableContactMatrix(SequenceI newRefSeq, |
236 |
|
MapList newFromMapList); |
237 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
238 |
0 |
@Override... |
239 |
|
public int[] getMappedPositionsFor(final SequenceI localFrame, |
240 |
|
final int column) |
241 |
|
{ |
242 |
0 |
return getMappedPositionsFor(localFrame, column, column); |
243 |
|
} |
244 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 9 |
Complexity Density: 0.56 |
|
245 |
0 |
@Override... |
246 |
|
public int[] getMappedPositionsFor(final SequenceI localFrame, int from, |
247 |
|
int to) |
248 |
|
{ |
249 |
0 |
if (localFrame == null) |
250 |
|
{ |
251 |
0 |
throw new Error("Unimplemented when no local sequence given."); |
252 |
|
} |
253 |
0 |
SequenceI lf = localFrame, uf = refSeq; |
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
0 |
while (lf.getDatasetSequence() != null |
259 |
|
|| uf.getDatasetSequence() != null) |
260 |
|
{ |
261 |
0 |
if (lf.getDatasetSequence() != null) |
262 |
|
{ |
263 |
0 |
lf = lf.getDatasetSequence(); |
264 |
|
} |
265 |
0 |
if (uf.getDatasetSequence() != null) |
266 |
|
{ |
267 |
0 |
uf = uf.getDatasetSequence(); |
268 |
|
} |
269 |
|
} |
270 |
0 |
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 |
0 |
if (toSeq == null) |
281 |
|
{ |
282 |
|
|
283 |
0 |
return new int[] { from, to }; |
284 |
|
} |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
0 |
int[] mappedPositions = toSeq.locateInFrom(from, to); |
289 |
0 |
if (mappedPositions == null) |
290 |
|
{ |
291 |
0 |
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 |
0 |
return mappedPositions; |
317 |
|
} |
318 |
|
|
|
|
| 0% |
Uncovered Elements: 48 (48) |
Complexity: 16 |
Complexity Density: 0.57 |
|
319 |
0 |
@Override... |
320 |
|
public ContactListI getMappableContactList(final SequenceI localFrame, |
321 |
|
final int column) |
322 |
|
{ |
323 |
0 |
final int _column; |
324 |
0 |
final int _lcolumn; |
325 |
0 |
if (localFrame == null) |
326 |
|
{ |
327 |
0 |
throw new Error("Unimplemented when no local sequence given."); |
328 |
|
} |
329 |
|
|
330 |
|
|
331 |
|
|
332 |
0 |
final MappableContactMatrix us = this; |
333 |
0 |
_lcolumn = localFrame.findPosition(column); |
334 |
|
|
335 |
0 |
if (toSeq != null) |
336 |
|
{ |
337 |
0 |
SequenceI lf = localFrame, uf = refSeq; |
338 |
|
|
339 |
|
|
340 |
|
|
341 |
0 |
while (lf.getDatasetSequence() != null |
342 |
|
|| uf.getDatasetSequence() != null) |
343 |
|
{ |
344 |
0 |
if (lf.getDatasetSequence() != null) |
345 |
|
{ |
346 |
0 |
lf = lf.getDatasetSequence(); |
347 |
|
} |
348 |
0 |
if (uf.getDatasetSequence() != null) |
349 |
|
{ |
350 |
0 |
uf = uf.getDatasetSequence(); |
351 |
|
} |
352 |
|
} |
353 |
0 |
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 |
0 |
int[] word = toSeq.locateInTo(_lcolumn, _lcolumn); |
362 |
0 |
if (word == null) |
363 |
|
{ |
364 |
0 |
return null; |
365 |
|
} |
366 |
0 |
_column = word[0]; |
367 |
|
} |
368 |
|
else |
369 |
|
{ |
370 |
|
|
371 |
0 |
_column = _lcolumn; |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
0 |
if (_column < 0 || ((toSeq != null && _column > toSeq.getToHighest()) |
376 |
|
|| (toSeq == null && getHeight() <= _column))) |
377 |
|
{ |
378 |
0 |
return null; |
379 |
|
} |
380 |
|
|
381 |
|
|
382 |
0 |
final int[] matrixRange = toSeq == null |
383 |
|
? new int[] |
384 |
|
{ localFrame.getStart(), localFrame.getEnd() } |
385 |
|
: toSeq.locateInTo(localFrame.getStart(), localFrame.getEnd()); |
386 |
|
|
387 |
0 |
int h = 0; |
388 |
0 |
for (int p = 0; p < matrixRange.length; p += 2) |
389 |
|
{ |
390 |
0 |
h += 1 + Math.abs(matrixRange[p + 1] - matrixRange[p]); |
391 |
|
} |
392 |
0 |
final int rangeHeight = h; |
393 |
|
|
394 |
|
|
395 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
409 |
0 |
@Override... |
410 |
|
public int getContactHeight() |
411 |
|
{ |
412 |
0 |
return rangeHeight; |
413 |
|
} |
414 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
415 |
0 |
@Override... |
416 |
|
public double getContactAt(int mcolumn) |
417 |
|
{ |
418 |
0 |
if (mcolumn < 0 || mcolumn >= rangeHeight) |
419 |
|
{ |
420 |
0 |
return -1; |
421 |
|
} |
422 |
0 |
return getElementAt(_column, locateInRange(mcolumn)); |
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
} |
435 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 8 |
Complexity Density: 0.57 |
|
436 |
0 |
@Override... |
437 |
|
public int[] getMappedPositionsFor(int cStart, int cEnd) |
438 |
|
{ |
439 |
0 |
if (!hasReferenceSeq()) |
440 |
|
{ |
441 |
0 |
return ContactListProviderI.super.getMappedPositionsFor(cStart, |
442 |
|
cEnd); |
443 |
|
} |
444 |
|
|
445 |
0 |
int realCstart = locateInRange(cStart); |
446 |
0 |
int realCend = locateInRange(cEnd); |
447 |
|
|
448 |
|
|
449 |
|
|
450 |
0 |
int[] mappedPositions = toSeq.locateInFrom(realCstart, realCend); |
451 |
0 |
if (mappedPositions != null) |
452 |
|
{ |
453 |
0 |
int s = -1, e = -1; |
454 |
0 |
for (int p = 0; p < mappedPositions.length; p++) |
455 |
|
{ |
456 |
0 |
if (s == -1 && mappedPositions[p] >= localFrame.getStart()) |
457 |
|
{ |
458 |
0 |
s = p; |
459 |
|
} |
460 |
0 |
if (e == -1 || mappedPositions[p] <= localFrame.getEnd()) |
461 |
|
{ |
462 |
|
|
463 |
0 |
e = p; |
464 |
|
|
465 |
0 |
mappedPositions[p] = localFrame.findIndex(mappedPositions[p]); |
466 |
|
} |
467 |
|
} |
468 |
|
} |
469 |
0 |
return mappedPositions; |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
@return |
474 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
475 |
0 |
private int locateInRange(int mcolumn)... |
476 |
|
{ |
477 |
|
|
478 |
0 |
int h = 0, p = 0; |
479 |
0 |
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 |
0 |
return matrixRange[p] + mcolumn - h; |
485 |
|
} |
486 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
487 |
0 |
@Override... |
488 |
|
public Color getColourForGroup() |
489 |
|
{ |
490 |
0 |
BitSet gp = us.getGroupsFor(_column); |
491 |
0 |
Color col = us.getColourForGroup(gp); |
492 |
0 |
return col; |
493 |
|
} |
494 |
|
}); |
495 |
|
} |
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
|
502 |
|
@param |
503 |
|
@param |
504 |
|
@return |
505 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
506 |
0 |
public double getElementAt(int _column, int i)... |
507 |
|
{ |
508 |
0 |
return mappedMatrix.getElementAt(_column, i); |
509 |
|
} |
510 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 4 |
Complexity Density: 4 |
|
511 |
0 |
@Override... |
512 |
|
public int hashCode() |
513 |
|
{ |
514 |
0 |
return 7 * (refSeq != null ? refSeq.hashCode() : 0) |
515 |
0 |
+ 11 * (toSeq != null ? toSeq.hashCode() : 0) |
516 |
0 |
+ 13 * (mappedMatrix != null ? mappedMatrix.hashCode() : 0) |
517 |
|
+ length * 3; |
518 |
|
} |
519 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
520 |
0 |
@Override... |
521 |
|
public boolean equals(Object obj) |
522 |
|
{ |
523 |
0 |
if (obj == null || !(obj.getClass().equals(getClass()))) |
524 |
|
{ |
525 |
0 |
return false; |
526 |
|
} |
527 |
0 |
T them = (T) obj; |
528 |
0 |
return mappedMatrix == them.mappedMatrix && length == them.length |
529 |
|
&& refSeq == them.refSeq && toSeq.equals(them.toSeq); |
530 |
|
|
531 |
|
} |
532 |
|
} |