1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import jalview.analysis.AlignmentUtils; |
24 |
|
import jalview.analysis.CrossRef; |
25 |
|
import jalview.api.AlignmentViewPanel; |
26 |
|
import jalview.api.FeatureSettingsModelI; |
27 |
|
import jalview.bin.Cache; |
28 |
|
import jalview.datamodel.Alignment; |
29 |
|
import jalview.datamodel.AlignmentI; |
30 |
|
import jalview.datamodel.DBRefEntry; |
31 |
|
import jalview.datamodel.DBRefSource; |
32 |
|
import jalview.datamodel.GeneLociI; |
33 |
|
import jalview.datamodel.SequenceI; |
34 |
|
import jalview.ext.ensembl.EnsemblInfo; |
35 |
|
import jalview.ext.ensembl.EnsemblMap; |
36 |
|
import jalview.io.gff.SequenceOntologyI; |
37 |
|
import jalview.structure.StructureSelectionManager; |
38 |
|
import jalview.util.DBRefUtils; |
39 |
|
import jalview.util.MapList; |
40 |
|
import jalview.util.MappingUtils; |
41 |
|
import jalview.util.MessageManager; |
42 |
|
import jalview.viewmodel.seqfeatures.FeatureRendererModel; |
43 |
|
import jalview.ws.SequenceFetcher; |
44 |
|
|
45 |
|
import java.util.ArrayList; |
46 |
|
import java.util.HashMap; |
47 |
|
import java.util.List; |
48 |
|
import java.util.Map; |
49 |
|
import java.util.Set; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@author |
56 |
|
|
57 |
|
|
|
|
| 51.4% |
Uncovered Elements: 107 (220) |
Complexity: 55 |
Complexity Density: 0.39 |
|
58 |
|
public class CrossRefAction implements Runnable |
59 |
|
{ |
60 |
|
private AlignFrame alignFrame; |
61 |
|
|
62 |
|
private SequenceI[] sel; |
63 |
|
|
64 |
|
private final boolean _odna; |
65 |
|
|
66 |
|
private String source; |
67 |
|
|
68 |
|
List<AlignmentViewPanel> xrefViews = new ArrayList<>(); |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0 |
List<AlignmentViewPanel> getXrefViews()... |
71 |
|
{ |
72 |
0 |
return xrefViews; |
73 |
|
} |
74 |
|
|
|
|
| 69.6% |
Uncovered Elements: 28 (92) |
Complexity: 20 |
Complexity Density: 0.33 |
|
75 |
2 |
@Override... |
76 |
|
public void run() |
77 |
|
{ |
78 |
2 |
final long sttime = System.currentTimeMillis(); |
79 |
2 |
alignFrame.setProgressBar(MessageManager.formatMessage( |
80 |
|
"status.searching_for_sequences_from", new Object[] |
81 |
|
{ source }), sttime); |
82 |
2 |
try |
83 |
|
{ |
84 |
2 |
AlignmentI alignment = alignFrame.getViewport().getAlignment(); |
85 |
2 |
AlignmentI dataset = alignment.getDataset() == null ? alignment |
86 |
|
: alignment.getDataset(); |
87 |
2 |
boolean dna = alignment.isNucleotide(); |
88 |
2 |
if (_odna != dna) |
89 |
|
{ |
90 |
0 |
System.err |
91 |
|
.println("Conflict: showProducts for alignment originally " |
92 |
0 |
+ "thought to be " + (_odna ? "DNA" : "Protein") |
93 |
0 |
+ " now searching for " + (dna ? "DNA" : "Protein") |
94 |
|
+ " Context."); |
95 |
|
} |
96 |
2 |
AlignmentI xrefs = new CrossRef(sel, dataset) |
97 |
|
.findXrefSequences(source, dna); |
98 |
2 |
if (xrefs == null) |
99 |
|
{ |
100 |
0 |
return; |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
2 |
findGeneLoci(xrefs.getSequences()); |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
2 |
FeatureSettingsModelI featureColourScheme = new SequenceFetcher() |
113 |
|
.getFeatureColourScheme(source); |
114 |
|
|
115 |
2 |
if (dna && AlignmentUtils.looksLikeEnsembl(alignment)) |
116 |
|
{ |
117 |
|
|
118 |
2 |
featureColourScheme = new SequenceFetcher() |
119 |
|
.getFeatureColourScheme(DBRefSource.ENSEMBL); |
120 |
|
} |
121 |
|
|
122 |
2 |
AlignmentI xrefsAlignment = makeCrossReferencesAlignment(dataset, |
123 |
|
xrefs); |
124 |
2 |
if (!dna) |
125 |
|
{ |
126 |
0 |
xrefsAlignment = AlignmentUtils.makeCdsAlignment( |
127 |
|
xrefsAlignment.getSequencesArray(), dataset, sel); |
128 |
0 |
xrefsAlignment.alignAs(alignment); |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
2 |
AlignmentI copyAlignment = null; |
136 |
|
|
137 |
2 |
if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true)) |
138 |
|
{ |
139 |
2 |
copyAlignment = copyAlignmentForSplitFrame(alignment, dataset, dna, |
140 |
|
xrefs, xrefsAlignment); |
141 |
2 |
if (copyAlignment == null) |
142 |
|
{ |
143 |
0 |
return; |
144 |
|
} |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
2 |
AlignFrame newFrame = new AlignFrame(xrefsAlignment, |
151 |
|
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); |
152 |
2 |
if (Cache.getDefault("HIDE_INTRONS", true)) |
153 |
|
{ |
154 |
2 |
newFrame.hideFeatureColumns(SequenceOntologyI.EXON, false); |
155 |
|
} |
156 |
2 |
String newtitle = String.format("%s %s %s", |
157 |
2 |
dna ? MessageManager.getString("label.proteins") |
158 |
|
: MessageManager.getString("label.nucleotides"), |
159 |
|
MessageManager.getString("label.for"), alignFrame.getTitle()); |
160 |
2 |
newFrame.setTitle(newtitle); |
161 |
|
|
162 |
2 |
if (copyAlignment == null) |
163 |
|
{ |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
0 |
Desktop.addInternalFrame(newFrame, newtitle, |
168 |
|
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); |
169 |
0 |
xrefViews.add(newFrame.alignPanel); |
170 |
0 |
return; |
171 |
|
} |
172 |
|
|
173 |
2 |
AlignFrame copyThis = new AlignFrame(copyAlignment, |
174 |
|
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); |
175 |
2 |
copyThis.setTitle(alignFrame.getTitle()); |
176 |
|
|
177 |
2 |
boolean showSequenceFeatures = alignFrame.getViewport() |
178 |
|
.isShowSequenceFeatures(); |
179 |
2 |
newFrame.setShowSeqFeatures(showSequenceFeatures); |
180 |
2 |
copyThis.setShowSeqFeatures(showSequenceFeatures); |
181 |
2 |
FeatureRendererModel myFeatureStyling = alignFrame.alignPanel |
182 |
|
.getSeqPanel().seqCanvas.getFeatureRenderer(); |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
2 |
FeatureRendererModel fr1 = newFrame.alignPanel.getSeqPanel().seqCanvas |
188 |
|
.getFeatureRenderer(); |
189 |
2 |
fr1.transferSettings(myFeatureStyling); |
190 |
2 |
fr1.findAllFeatures(true); |
191 |
2 |
FeatureRendererModel fr2 = copyThis.alignPanel.getSeqPanel().seqCanvas |
192 |
|
.getFeatureRenderer(); |
193 |
2 |
fr2.transferSettings(myFeatureStyling); |
194 |
2 |
fr2.findAllFeatures(true); |
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
2 |
newFrame.getViewport().applyFeaturesStyle(featureColourScheme); |
202 |
2 |
copyThis.getViewport().applyFeaturesStyle(featureColourScheme); |
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
2 |
for (AlignmentViewPanel origpanel: alignFrame.getAlignPanels()) { |
209 |
2 |
origpanel.getAlignViewport() |
210 |
|
.mergeFeaturesStyle(featureColourScheme); |
211 |
|
} |
212 |
|
|
213 |
2 |
SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame, |
214 |
2 |
dna ? newFrame : copyThis); |
215 |
|
|
216 |
2 |
newFrame.setVisible(true); |
217 |
2 |
copyThis.setVisible(true); |
218 |
2 |
String linkedTitle = MessageManager |
219 |
|
.getString("label.linked_view_title"); |
220 |
2 |
Desktop.addInternalFrame(sf, linkedTitle, -1, -1); |
221 |
2 |
sf.adjustInitialLayout(); |
222 |
|
|
223 |
|
|
224 |
2 |
xrefViews.add(dna ? copyThis.alignPanel : newFrame.alignPanel); |
225 |
2 |
xrefViews.add(!dna ? copyThis.alignPanel : newFrame.alignPanel); |
226 |
|
|
227 |
|
} catch (OutOfMemoryError e) |
228 |
|
{ |
229 |
0 |
new OOMWarning("whilst fetching crossreferences", e); |
230 |
|
} catch (Throwable e) |
231 |
|
{ |
232 |
0 |
Cache.log.error("Error when finding crossreferences", e); |
233 |
|
} finally |
234 |
|
{ |
235 |
2 |
alignFrame.setProgressBar(MessageManager.formatMessage( |
236 |
|
"status.finished_searching_for_sequences_from", new Object[] |
237 |
|
{ source }), sttime); |
238 |
|
} |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
@param |
263 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
264 |
2 |
public static void findGeneLoci(List<SequenceI> sequences)... |
265 |
|
{ |
266 |
2 |
Map<DBRefEntry, GeneLociI> retrievedLoci = new HashMap<>(); |
267 |
2 |
for (SequenceI seq : sequences) |
268 |
|
{ |
269 |
22 |
findGeneLoci(seq, retrievedLoci); |
270 |
|
} |
271 |
|
} |
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
@param |
282 |
|
@param |
283 |
|
|
|
|
| 10% |
Uncovered Elements: 27 (30) |
Complexity: 11 |
Complexity Density: 0.61 |
|
284 |
22 |
static void findGeneLoci(SequenceI seq,... |
285 |
|
Map<DBRefEntry, GeneLociI> retrievedLoci) |
286 |
|
{ |
287 |
|
|
288 |
|
|
289 |
|
|
290 |
22 |
if (seq == null || seq.isProtein() || seq.getGeneLoci() != null |
291 |
|
|| seq.getDBRefs() == null) |
292 |
|
{ |
293 |
22 |
return; |
294 |
|
} |
295 |
|
|
296 |
0 |
Set<String> ensemblDivisions = new EnsemblInfo().getDivisions(); |
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
0 |
String[] divisionsArray = ensemblDivisions |
302 |
|
.toArray(new String[ensemblDivisions.size()]); |
303 |
0 |
List<DBRefEntry> seqRefs = seq.getDBRefs(); |
304 |
0 |
List<DBRefEntry> directEnsemblRefs = DBRefUtils.selectRefs(seqRefs, |
305 |
|
divisionsArray); |
306 |
0 |
if (directEnsemblRefs != null) |
307 |
|
{ |
308 |
0 |
for (DBRefEntry ensemblRef : directEnsemblRefs) |
309 |
|
{ |
310 |
0 |
if (fetchGeneLoci(seq, ensemblRef, retrievedLoci)) |
311 |
|
{ |
312 |
0 |
return; |
313 |
|
} |
314 |
|
} |
315 |
|
} |
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
0 |
for (DBRefEntry dbref : seq.getDBRefs()) |
321 |
|
{ |
322 |
0 |
if (dbref.getMap() != null && dbref.getMap().getTo() != null) |
323 |
|
{ |
324 |
0 |
List<DBRefEntry> dbrefs = dbref.getMap().getTo().getDBRefs(); |
325 |
0 |
List<DBRefEntry> indirectEnsemblRefs = DBRefUtils.selectRefs(dbrefs, |
326 |
|
divisionsArray); |
327 |
0 |
if (indirectEnsemblRefs != null) |
328 |
|
{ |
329 |
0 |
for (DBRefEntry ensemblRef : indirectEnsemblRefs) |
330 |
|
{ |
331 |
0 |
if (fetchGeneLoci(seq, ensemblRef, retrievedLoci)) |
332 |
|
{ |
333 |
0 |
return; |
334 |
|
} |
335 |
|
} |
336 |
|
} |
337 |
|
} |
338 |
|
} |
339 |
|
} |
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
@param |
348 |
|
@param |
349 |
|
@param |
350 |
|
@return |
351 |
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 6 |
Complexity Density: 0.27 |
|
352 |
0 |
static boolean fetchGeneLoci(SequenceI seq, DBRefEntry dbref,... |
353 |
|
Map<DBRefEntry, GeneLociI> retrievedLoci) |
354 |
|
{ |
355 |
0 |
String accession = dbref.getAccessionId(); |
356 |
0 |
String division = dbref.getSource(); |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
0 |
if (accession.startsWith("ENSP")) |
364 |
|
{ |
365 |
0 |
return false; |
366 |
|
} |
367 |
0 |
EnsemblMap mapper = new EnsemblMap(); |
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
0 |
GeneLociI geneLoci = mapper.getCdsMapping(division, accession, 1, |
373 |
|
seq.getLength()); |
374 |
0 |
if (geneLoci != null) |
375 |
|
{ |
376 |
0 |
MapList map = geneLoci.getMapping(); |
377 |
0 |
int mappedFromLength = MappingUtils.getLength(map.getFromRanges()); |
378 |
0 |
if (mappedFromLength == seq.getLength()) |
379 |
|
{ |
380 |
0 |
seq.setGeneLoci(geneLoci.getSpeciesId(), geneLoci.getAssemblyId(), |
381 |
|
geneLoci.getChromosomeId(), map); |
382 |
0 |
retrievedLoci.put(dbref, geneLoci); |
383 |
0 |
return true; |
384 |
|
} |
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
|
|
389 |
|
|
390 |
0 |
geneLoci = mapper.getCdnaMapping(division, accession, 1, |
391 |
|
seq.getLength()); |
392 |
0 |
if (geneLoci != null) |
393 |
|
{ |
394 |
0 |
MapList map = geneLoci.getMapping(); |
395 |
0 |
int mappedFromLength = MappingUtils.getLength(map.getFromRanges()); |
396 |
0 |
if (mappedFromLength == seq.getLength()) |
397 |
|
{ |
398 |
0 |
seq.setGeneLoci(geneLoci.getSpeciesId(), geneLoci.getAssemblyId(), |
399 |
|
geneLoci.getChromosomeId(), map); |
400 |
0 |
retrievedLoci.put(dbref, geneLoci); |
401 |
0 |
return true; |
402 |
|
} |
403 |
|
} |
404 |
|
|
405 |
0 |
return false; |
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
|
@param |
410 |
|
@param |
411 |
|
@param |
412 |
|
@param |
413 |
|
@param |
414 |
|
@return |
415 |
|
|
|
|
| 57.1% |
Uncovered Elements: 15 (35) |
Complexity: 10 |
Complexity Density: 0.43 |
|
416 |
2 |
protected AlignmentI copyAlignmentForSplitFrame(AlignmentI alignment,... |
417 |
|
AlignmentI dataset, boolean dna, AlignmentI xrefs, |
418 |
|
AlignmentI xrefsAlignment) |
419 |
|
{ |
420 |
2 |
AlignmentI copyAlignment; |
421 |
2 |
boolean copyAlignmentIsAligned = false; |
422 |
2 |
if (dna) |
423 |
|
{ |
424 |
2 |
copyAlignment = AlignmentUtils.makeCdsAlignment(sel, dataset, |
425 |
|
xrefsAlignment.getSequencesArray()); |
426 |
2 |
if (copyAlignment.getHeight() == 0) |
427 |
|
{ |
428 |
0 |
JvOptionPane.showMessageDialog(alignFrame, |
429 |
|
MessageManager.getString("label.cant_map_cds"), |
430 |
|
MessageManager.getString("label.operation_failed"), |
431 |
|
JvOptionPane.OK_OPTION); |
432 |
0 |
System.err.println("Failed to make CDS alignment"); |
433 |
0 |
return null; |
434 |
|
} |
435 |
|
|
436 |
|
|
437 |
|
|
438 |
|
|
439 |
|
|
440 |
|
|
441 |
2 |
if (DBRefSource.ENSEMBL.equalsIgnoreCase(source) |
442 |
|
|| AlignmentUtils.looksLikeEnsembl(alignment)) |
443 |
|
{ |
444 |
2 |
copyAlignment.alignAs(alignment); |
445 |
2 |
copyAlignmentIsAligned = true; |
446 |
|
} |
447 |
|
} |
448 |
|
else |
449 |
|
{ |
450 |
0 |
copyAlignment = AlignmentUtils.makeCopyAlignment(sel, |
451 |
|
xrefs.getSequencesArray(), dataset); |
452 |
|
} |
453 |
2 |
copyAlignment |
454 |
|
.setGapCharacter(alignFrame.viewport.getGapCharacter()); |
455 |
|
|
456 |
2 |
StructureSelectionManager ssm = StructureSelectionManager |
457 |
|
.getStructureSelectionManager(Desktop.instance); |
458 |
|
|
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
|
463 |
2 |
ssm.registerMappings(dataset.getCodonFrames()); |
464 |
|
|
465 |
2 |
if (copyAlignment.getHeight() <= 0) |
466 |
|
{ |
467 |
0 |
System.err.println( |
468 |
|
"No Sequences generated for xRef type " + source); |
469 |
0 |
return null; |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
|
474 |
|
|
475 |
2 |
if (dna && copyAlignmentIsAligned) |
476 |
|
{ |
477 |
2 |
xrefsAlignment.alignAs(copyAlignment); |
478 |
|
} |
479 |
|
else |
480 |
|
{ |
481 |
|
|
482 |
|
|
483 |
|
|
484 |
|
|
485 |
|
|
486 |
0 |
if (dna && DBRefSource.ENSEMBL.equalsIgnoreCase(source)) |
487 |
|
{ |
488 |
0 |
copyAlignment.alignAs(xrefsAlignment); |
489 |
|
} |
490 |
|
} |
491 |
|
|
492 |
2 |
return copyAlignment; |
493 |
|
} |
494 |
|
|
495 |
|
|
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
@param |
502 |
|
@param |
503 |
|
@return |
504 |
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
505 |
2 |
protected AlignmentI makeCrossReferencesAlignment(AlignmentI dataset,... |
506 |
|
AlignmentI seqs) |
507 |
|
{ |
508 |
2 |
SequenceI[] sprods = new SequenceI[seqs.getHeight()]; |
509 |
24 |
for (int s = 0; s < sprods.length; s++) |
510 |
|
{ |
511 |
22 |
sprods[s] = (seqs.getSequenceAt(s)).deriveSequence(); |
512 |
22 |
if (dataset.getSequences() == null || !dataset.getSequences() |
513 |
|
.contains(sprods[s].getDatasetSequence())) |
514 |
|
{ |
515 |
0 |
dataset.addSequence(sprods[s].getDatasetSequence()); |
516 |
|
} |
517 |
22 |
sprods[s].updatePDBIds(); |
518 |
|
} |
519 |
2 |
Alignment al = new Alignment(sprods); |
520 |
2 |
al.setDataset(dataset); |
521 |
2 |
return al; |
522 |
|
} |
523 |
|
|
524 |
|
|
525 |
|
|
526 |
|
|
527 |
|
@param |
528 |
|
@param |
529 |
|
@param |
530 |
|
@param |
531 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
532 |
2 |
CrossRefAction(AlignFrame af, SequenceI[] seqs, boolean fromDna,... |
533 |
|
String dbSource) |
534 |
|
{ |
535 |
2 |
this.alignFrame = af; |
536 |
2 |
this.sel = seqs; |
537 |
2 |
this._odna = fromDna; |
538 |
2 |
this.source = dbSource; |
539 |
|
} |
540 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
541 |
2 |
public static CrossRefAction getHandlerFor(final SequenceI[] sel,... |
542 |
|
final boolean fromDna, final String source, |
543 |
|
final AlignFrame alignFrame) |
544 |
|
{ |
545 |
2 |
return new CrossRefAction(alignFrame, sel, fromDna, source); |
546 |
|
} |
547 |
|
|
548 |
|
} |