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