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