1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ext.ensembl; |
22 |
|
|
23 |
|
import java.io.IOException; |
24 |
|
import java.net.MalformedURLException; |
25 |
|
import java.net.URL; |
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.Arrays; |
28 |
|
import java.util.Collections; |
29 |
|
import java.util.List; |
30 |
|
import java.util.Map; |
31 |
|
|
32 |
|
import org.json.simple.parser.ParseException; |
33 |
|
|
34 |
|
import jalview.analysis.AlignmentUtils; |
35 |
|
import jalview.analysis.Dna; |
36 |
|
import jalview.bin.Console; |
37 |
|
import jalview.datamodel.Alignment; |
38 |
|
import jalview.datamodel.AlignmentI; |
39 |
|
import jalview.datamodel.DBRefEntry; |
40 |
|
import jalview.datamodel.DBRefSource; |
41 |
|
import jalview.datamodel.Mapping; |
42 |
|
import jalview.datamodel.Sequence; |
43 |
|
import jalview.datamodel.SequenceFeature; |
44 |
|
import jalview.datamodel.SequenceI; |
45 |
|
import jalview.datamodel.features.SequenceFeatures; |
46 |
|
import jalview.exceptions.JalviewException; |
47 |
|
import jalview.io.gff.Gff3Helper; |
48 |
|
import jalview.io.gff.SequenceOntologyFactory; |
49 |
|
import jalview.io.gff.SequenceOntologyI; |
50 |
|
import jalview.util.Comparison; |
51 |
|
import jalview.util.DBRefUtils; |
52 |
|
import jalview.util.IntRangeComparator; |
53 |
|
import jalview.util.MapList; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@see |
59 |
|
@author |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 342 (342) |
Complexity: 85 |
Complexity Density: 0.39 |
|
61 |
|
public abstract class EnsemblSeqProxy extends EnsemblRestClient |
62 |
|
{ |
63 |
|
protected static final String DESCRIPTION = "description"; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
68 |
|
public enum EnsemblSeqType |
69 |
|
{ |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
GENOMIC("genomic"), |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
CDNA("cdna"), |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
CDS("cds"), |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
PROTEIN("protein"); |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
private String type; |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
0 |
EnsemblSeqType(String t)... |
97 |
|
{ |
98 |
0 |
type = t; |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
0 |
public String getType()... |
102 |
|
{ |
103 |
0 |
return type; |
104 |
|
} |
105 |
|
|
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
0 |
public EnsemblSeqProxy()... |
112 |
|
{ |
113 |
0 |
super(); |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
0 |
public EnsemblSeqProxy(String d)... |
120 |
|
{ |
121 |
0 |
super(d); |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 6 |
Complexity Density: 0.27 |
|
128 |
0 |
@Override... |
129 |
|
public AlignmentI getSequenceRecords(String query) throws Exception |
130 |
|
{ |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
0 |
List<String> allIds = Arrays |
136 |
|
.asList(query.split(getAccessionSeparator())); |
137 |
0 |
AlignmentI alignment = null; |
138 |
0 |
inProgress = true; |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
0 |
int maxQueryCount = getMaximumQueryCount(); |
145 |
0 |
for (int v = 0, vSize = allIds.size(); v < vSize; v += maxQueryCount) |
146 |
|
{ |
147 |
0 |
int p = Math.min(vSize, v + maxQueryCount); |
148 |
0 |
List<String> ids = allIds.subList(v, p); |
149 |
0 |
try |
150 |
|
{ |
151 |
0 |
alignment = fetchSequences(ids, alignment); |
152 |
|
} catch (Throwable r) |
153 |
|
{ |
154 |
0 |
inProgress = false; |
155 |
0 |
String msg = "Aborting ID retrieval after " + v |
156 |
|
+ " chunks. Unexpected problem (" + r.getLocalizedMessage() |
157 |
|
+ ")"; |
158 |
0 |
jalview.bin.Console.errPrintln(msg); |
159 |
0 |
r.printStackTrace(); |
160 |
0 |
break; |
161 |
|
} |
162 |
|
} |
163 |
|
|
164 |
0 |
if (alignment == null) |
165 |
|
{ |
166 |
0 |
return null; |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
0 |
for (int i = 0, n = allIds.size(); i < n; i++) |
174 |
|
{ |
175 |
0 |
addFeaturesAndProduct(allIds.get(i), alignment); |
176 |
|
} |
177 |
|
|
178 |
0 |
List<SequenceI> seqs = alignment.getSequences(); |
179 |
0 |
for (int i = 0, n = seqs.size(); i < n; i++) |
180 |
|
{ |
181 |
0 |
getCrossReferences(seqs.get(i)); |
182 |
|
} |
183 |
|
|
184 |
0 |
return alignment; |
185 |
|
} |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
@param |
194 |
|
@param |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 7 |
Complexity Density: 0.5 |
|
196 |
0 |
protected void addFeaturesAndProduct(String accId, AlignmentI alignment)... |
197 |
|
{ |
198 |
0 |
if (alignment == null) |
199 |
|
{ |
200 |
0 |
return; |
201 |
|
} |
202 |
|
|
203 |
0 |
try |
204 |
|
{ |
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
0 |
SequenceI genomicSequence = null; |
210 |
0 |
EnsemblFeatures gffFetcher = new EnsemblFeatures(getDomain()); |
211 |
0 |
EnsemblFeatureType[] features = getFeaturesToFetch(); |
212 |
|
|
213 |
|
|
214 |
|
|
215 |
0 |
AlignmentI geneFeatures = gffFetcher.getSequenceRecords(accId, |
216 |
|
features); |
217 |
0 |
if (geneFeatures != null && geneFeatures.getHeight() > 0) |
218 |
|
{ |
219 |
0 |
genomicSequence = geneFeatures.getSequenceAt(0); |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
0 |
if (genomicSequence != null) |
225 |
|
{ |
226 |
|
|
227 |
|
|
228 |
|
|
229 |
0 |
SequenceI querySeq = alignment.findName(accId, true); |
230 |
0 |
if (transferFeatures(accId, genomicSequence, querySeq)) |
231 |
|
{ |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
0 |
addProteinProduct(querySeq); |
239 |
|
} |
240 |
|
} |
241 |
|
} catch (IOException e) |
242 |
|
{ |
243 |
0 |
jalview.bin.Console.errPrintln( |
244 |
|
"Error transferring Ensembl features: " + e.getMessage()); |
245 |
|
} |
246 |
|
|
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
@return |
256 |
|
|
257 |
|
protected abstract EnsemblFeatureType[] getFeaturesToFetch(); |
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
|
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 9 |
Complexity Density: 0.27 |
|
263 |
0 |
protected void addProteinProduct(SequenceI querySeq)... |
264 |
|
{ |
265 |
0 |
String accId = querySeq.getName(); |
266 |
0 |
try |
267 |
|
{ |
268 |
0 |
jalview.bin.Console.outPrintln("Adding protein product for " + accId); |
269 |
0 |
AlignmentI protein = new EnsemblProtein(getDomain()) |
270 |
|
.getSequenceRecords(accId); |
271 |
0 |
if (protein == null || protein.getHeight() == 0) |
272 |
|
{ |
273 |
0 |
jalview.bin.Console |
274 |
|
.outPrintln("No protein product found for " + accId); |
275 |
0 |
return; |
276 |
|
} |
277 |
0 |
SequenceI proteinSeq = protein.getSequenceAt(0); |
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
0 |
proteinSeq.createDatasetSequence(); |
283 |
0 |
querySeq.createDatasetSequence(); |
284 |
|
|
285 |
0 |
MapList mapList = AlignmentUtils.mapCdsToProtein(querySeq, |
286 |
|
proteinSeq); |
287 |
0 |
if (mapList != null) |
288 |
|
{ |
289 |
|
|
290 |
0 |
SequenceI ds = proteinSeq.getDatasetSequence(); |
291 |
|
|
292 |
0 |
Mapping map = new Mapping(ds, mapList); |
293 |
0 |
DBRefEntry dbr = new DBRefEntry(getDbSource(), |
294 |
|
getEnsemblDataVersion(), proteinSeq.getName(), map); |
295 |
0 |
querySeq.getDatasetSequence().addDBRef(dbr); |
296 |
0 |
List<DBRefEntry> uprots = DBRefUtils.selectRefs(ds.getDBRefs(), |
297 |
|
new String[] |
298 |
|
{ DBRefSource.UNIPROT }); |
299 |
0 |
List<DBRefEntry> upxrefs = DBRefUtils |
300 |
|
.selectRefs(querySeq.getDBRefs(), new String[] |
301 |
|
{ DBRefSource.UNIPROT }); |
302 |
0 |
if (uprots != null) |
303 |
|
{ |
304 |
0 |
for (DBRefEntry up : uprots) |
305 |
|
{ |
306 |
|
|
307 |
0 |
List<DBRefEntry> upx = DBRefUtils.searchRefs(upxrefs, |
308 |
|
up.getAccessionId()); |
309 |
0 |
DBRefEntry upxref; |
310 |
0 |
if (upx.size() != 0) |
311 |
|
{ |
312 |
0 |
upxref = upx.get(0); |
313 |
|
|
314 |
0 |
if (upx.size() > 1) |
315 |
|
{ |
316 |
0 |
Console.warn( |
317 |
|
"Implementation issue - multiple uniprot acc on product sequence."); |
318 |
|
} |
319 |
|
} |
320 |
|
else |
321 |
|
{ |
322 |
0 |
upxref = new DBRefEntry(DBRefSource.UNIPROT, |
323 |
|
getEnsemblDataVersion(), up.getAccessionId()); |
324 |
|
} |
325 |
|
|
326 |
0 |
Mapping newMap = new Mapping(ds, mapList); |
327 |
0 |
upxref.setVersion(getEnsemblDataVersion()); |
328 |
0 |
upxref.setMap(newMap); |
329 |
0 |
if (upx.size() == 0) |
330 |
|
{ |
331 |
|
|
332 |
0 |
querySeq.getDatasetSequence().addDBRef(upxref); |
333 |
|
} |
334 |
|
|
335 |
|
} |
336 |
|
} |
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
} |
345 |
|
} catch (Exception e) |
346 |
|
{ |
347 |
0 |
System.err |
348 |
|
.println(String.format("Error retrieving protein for %s: %s", |
349 |
|
accId, e.getMessage())); |
350 |
|
} |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
@param |
357 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
358 |
0 |
protected void getCrossReferences(SequenceI seq)... |
359 |
|
{ |
360 |
|
|
361 |
|
|
362 |
|
|
363 |
0 |
while (seq.getDatasetSequence() != null) |
364 |
|
{ |
365 |
0 |
seq = seq.getDatasetSequence(); |
366 |
|
} |
367 |
|
|
368 |
|
|
369 |
|
|
370 |
0 |
EnsemblXref xrefFetcher = new EnsemblXref(getDomain(), getDbSource(), |
371 |
|
getEnsemblDataVersion()); |
372 |
0 |
List<DBRefEntry> xrefs = xrefFetcher.getCrossReferences(seq.getName()); |
373 |
|
|
374 |
0 |
for (int i = 0, n = xrefs.size(); i < n; i++) |
375 |
|
{ |
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
|
383 |
0 |
seq.addDBRef(xrefs.get(i)); |
384 |
|
} |
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
|
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
|
393 |
|
|
394 |
0 |
DBRefEntry self = new DBRefEntry(getDbSource(), getEnsemblDataVersion(), |
395 |
|
seq.getName()); |
396 |
|
|
397 |
|
|
398 |
|
|
399 |
0 |
seq.addDBRef(self); |
400 |
|
|
401 |
|
|
402 |
|
} |
403 |
|
|
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
@param |
409 |
|
@param |
410 |
|
@return |
411 |
|
@throws |
412 |
|
@throws |
413 |
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 10 |
Complexity Density: 0.43 |
|
414 |
0 |
protected AlignmentI fetchSequences(List<String> ids,... |
415 |
|
AlignmentI alignment) throws JalviewException, IOException |
416 |
|
{ |
417 |
0 |
if (!isEnsemblAvailable()) |
418 |
|
{ |
419 |
0 |
inProgress = false; |
420 |
0 |
throw new JalviewException("ENSEMBL Rest API not available."); |
421 |
|
} |
422 |
|
|
423 |
|
|
424 |
0 |
List<SequenceI> seqs = parseSequenceJson(ids); |
425 |
0 |
if (seqs == null) |
426 |
0 |
return alignment; |
427 |
|
|
428 |
0 |
if (seqs.isEmpty()) |
429 |
|
{ |
430 |
0 |
throw new IOException("No data returned for " + ids); |
431 |
|
} |
432 |
|
|
433 |
0 |
if (seqs.size() != ids.size()) |
434 |
|
{ |
435 |
0 |
jalview.bin.Console.outPrintln(String.format( |
436 |
|
"Only retrieved %d sequences for %d query strings", |
437 |
|
seqs.size(), ids.size())); |
438 |
|
} |
439 |
|
|
440 |
0 |
if (!seqs.isEmpty()) |
441 |
|
{ |
442 |
0 |
AlignmentI seqal = new Alignment( |
443 |
|
seqs.toArray(new SequenceI[seqs.size()])); |
444 |
0 |
for (SequenceI seq : seqs) |
445 |
|
{ |
446 |
0 |
if (seq.getDescription() == null) |
447 |
|
{ |
448 |
0 |
seq.setDescription(getDbName()); |
449 |
|
} |
450 |
0 |
String name = seq.getName(); |
451 |
0 |
if (ids.contains(name) |
452 |
|
|| ids.contains(name.replace("ENSP", "ENST"))) |
453 |
|
{ |
454 |
|
|
455 |
0 |
DBRefEntry dbref = DBRefUtils.parseToDbRef(seq, getDbSource(), |
456 |
|
getEnsemblDataVersion(), name); |
457 |
0 |
seq.addDBRef(dbref); |
458 |
|
} |
459 |
|
} |
460 |
0 |
if (alignment == null) |
461 |
|
{ |
462 |
0 |
alignment = seqal; |
463 |
|
} |
464 |
|
else |
465 |
|
{ |
466 |
0 |
alignment.append(seqal); |
467 |
|
} |
468 |
|
} |
469 |
0 |
return alignment; |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
|
474 |
|
|
475 |
|
@param |
476 |
|
@return |
477 |
|
@see |
478 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 7 |
Complexity Density: 0.41 |
|
479 |
0 |
@SuppressWarnings("unchecked")... |
480 |
|
protected List<SequenceI> parseSequenceJson(List<String> ids) |
481 |
|
{ |
482 |
0 |
List<SequenceI> result = new ArrayList<>(); |
483 |
0 |
try |
484 |
|
{ |
485 |
|
|
486 |
|
|
487 |
|
|
488 |
|
|
489 |
|
|
490 |
0 |
Map<String, Object> val = (Map<String, Object>) getJSON(null, ids, -1, |
491 |
|
MODE_MAP, null); |
492 |
0 |
if (val == null) |
493 |
0 |
return null; |
494 |
0 |
Object s = val.get("desc"); |
495 |
0 |
String desc = s == null ? null : s.toString(); |
496 |
0 |
s = val.get("id"); |
497 |
0 |
String id = s == null ? null : s.toString(); |
498 |
0 |
s = val.get("seq"); |
499 |
0 |
String seq = s == null ? null : s.toString(); |
500 |
0 |
Sequence sequence = new Sequence(id, seq); |
501 |
0 |
if (desc != null) |
502 |
|
{ |
503 |
0 |
sequence.setDescription(desc); |
504 |
|
} |
505 |
|
|
506 |
|
|
507 |
|
|
508 |
|
|
509 |
|
|
510 |
0 |
result.add(sequence); |
511 |
|
} catch (ParseException | IOException e) |
512 |
|
{ |
513 |
0 |
jalview.bin.Console.errPrintln( |
514 |
|
"Error processing JSON response: " + e.toString()); |
515 |
|
|
516 |
|
} |
517 |
|
|
518 |
0 |
return result; |
519 |
|
} |
520 |
|
|
521 |
|
|
522 |
|
|
523 |
|
|
524 |
|
@return |
525 |
|
@throws |
526 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
527 |
0 |
@Override... |
528 |
|
protected URL getUrl(List<String> ids) throws MalformedURLException |
529 |
|
{ |
530 |
|
|
531 |
|
|
532 |
|
|
533 |
|
|
534 |
0 |
StringBuffer urlstring = new StringBuffer(128); |
535 |
0 |
urlstring.append(getDomain() + "/sequence/id"); |
536 |
0 |
if (ids.size() == 1) |
537 |
|
{ |
538 |
0 |
urlstring.append("/").append(ids.get(0)); |
539 |
|
} |
540 |
|
|
541 |
0 |
urlstring.append("?type=").append(getSourceEnsemblType().getType()); |
542 |
0 |
urlstring.append(("&Accept=application/json")); |
543 |
0 |
urlstring.append(("&content-type=application/json")); |
544 |
|
|
545 |
0 |
String objectType = getObjectType(); |
546 |
0 |
if (objectType != null) |
547 |
|
{ |
548 |
0 |
urlstring.append("&").append(OBJECT_TYPE).append("=") |
549 |
|
.append(objectType); |
550 |
|
} |
551 |
|
|
552 |
0 |
URL url = new URL(urlstring.toString()); |
553 |
0 |
return url; |
554 |
|
} |
555 |
|
|
556 |
|
|
557 |
|
|
558 |
|
|
559 |
|
@return |
560 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
561 |
0 |
protected String getObjectType()... |
562 |
|
{ |
563 |
0 |
return null; |
564 |
|
} |
565 |
|
|
566 |
|
|
567 |
|
|
568 |
|
|
569 |
|
@see |
570 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
571 |
0 |
@Override... |
572 |
|
public int getMaximumQueryCount() |
573 |
|
{ |
574 |
0 |
return 50; |
575 |
|
} |
576 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
577 |
0 |
@Override... |
578 |
|
protected boolean useGetRequest() |
579 |
|
{ |
580 |
0 |
return false; |
581 |
|
} |
582 |
|
|
583 |
|
|
584 |
|
|
585 |
|
@return |
586 |
|
|
587 |
|
protected abstract EnsemblSeqType getSourceEnsemblType(); |
588 |
|
|
589 |
|
|
590 |
|
|
591 |
|
|
592 |
|
|
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
|
597 |
|
|
598 |
|
|
599 |
|
|
600 |
|
|
601 |
|
|
602 |
|
|
603 |
|
|
604 |
|
|
605 |
|
|
606 |
|
|
607 |
|
|
608 |
|
|
609 |
|
@param |
610 |
|
@param |
611 |
|
@param |
612 |
|
|
613 |
|
@return |
614 |
|
|
|
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 8 |
Complexity Density: 0.32 |
|
615 |
0 |
protected MapList getGenomicRangesFromFeatures(SequenceI sourceSequence,... |
616 |
|
String accId, int start) |
617 |
|
{ |
618 |
0 |
List<SequenceFeature> sfs = getIdentifyingFeatures(sourceSequence, |
619 |
|
accId); |
620 |
0 |
if (sfs.isEmpty()) |
621 |
|
{ |
622 |
0 |
return null; |
623 |
|
} |
624 |
|
|
625 |
|
|
626 |
|
|
627 |
|
|
628 |
|
|
629 |
0 |
List<int[]> regions = new ArrayList<>(100); |
630 |
0 |
int mappedLength = 0; |
631 |
0 |
int direction = 1; |
632 |
0 |
boolean directionSet = false; |
633 |
|
|
634 |
0 |
for (SequenceFeature sf : sfs) |
635 |
|
{ |
636 |
0 |
int strand = sf.getStrand(); |
637 |
0 |
strand = strand == 0 ? 1 : strand; |
638 |
|
|
639 |
0 |
if (directionSet && strand != direction) |
640 |
|
{ |
641 |
|
|
642 |
0 |
System.err |
643 |
|
.println("Error: forward and backward strand for " + accId); |
644 |
0 |
return null; |
645 |
|
} |
646 |
0 |
direction = strand; |
647 |
0 |
directionSet = true; |
648 |
|
|
649 |
|
|
650 |
|
|
651 |
|
|
652 |
0 |
if (strand < 0) |
653 |
|
{ |
654 |
0 |
regions.add(0, new int[] { sf.getEnd(), sf.getBegin() }); |
655 |
|
} |
656 |
|
else |
657 |
|
{ |
658 |
0 |
regions.add(new int[] { sf.getBegin(), sf.getEnd() }); |
659 |
|
} |
660 |
0 |
mappedLength += Math.abs(sf.getEnd() - sf.getBegin() + 1); |
661 |
|
} |
662 |
|
|
663 |
0 |
if (regions.isEmpty()) |
664 |
|
{ |
665 |
0 |
jalview.bin.Console |
666 |
|
.outPrintln("Failed to identify target sequence for " + accId |
667 |
|
+ " from genomic features"); |
668 |
0 |
return null; |
669 |
|
} |
670 |
|
|
671 |
|
|
672 |
|
|
673 |
|
|
674 |
|
|
675 |
0 |
Collections.sort(regions, direction == 1 ? IntRangeComparator.ASCENDING |
676 |
|
: IntRangeComparator.DESCENDING); |
677 |
|
|
678 |
0 |
List<int[]> to = Arrays |
679 |
|
.asList(new int[] |
680 |
|
{ start, start + mappedLength - 1 }); |
681 |
|
|
682 |
0 |
return new MapList(regions, to, 1, 1); |
683 |
|
} |
684 |
|
|
685 |
|
|
686 |
|
|
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
|
691 |
|
|
692 |
|
@param |
693 |
|
@param |
694 |
|
@return |
695 |
|
|
696 |
|
protected abstract List<SequenceFeature> getIdentifyingFeatures( |
697 |
|
SequenceI seq, String accId); |
698 |
|
|
699 |
|
int bhtest = 0; |
700 |
|
|
701 |
|
|
702 |
|
|
703 |
|
|
704 |
|
|
705 |
|
|
706 |
|
@param |
707 |
|
@param |
708 |
|
@param |
709 |
|
|
710 |
|
|
711 |
|
@param |
712 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
713 |
0 |
protected void transferFeature(SequenceFeature sf,... |
714 |
|
SequenceI targetSequence, MapList mapping, boolean forwardStrand) |
715 |
|
{ |
716 |
0 |
int start = sf.getBegin(); |
717 |
0 |
int end = sf.getEnd(); |
718 |
0 |
int[] mappedRange = mapping.locateInTo(start, end); |
719 |
|
|
720 |
0 |
if (mappedRange != null) |
721 |
|
{ |
722 |
|
|
723 |
0 |
String group = sf.getFeatureGroup(); |
724 |
0 |
if (".".equals(group)) |
725 |
|
{ |
726 |
0 |
group = getDbSource(); |
727 |
|
} |
728 |
0 |
int newBegin = Math.min(mappedRange[0], mappedRange[1]); |
729 |
0 |
int newEnd = Math.max(mappedRange[0], mappedRange[1]); |
730 |
|
|
731 |
0 |
bhtest++; |
732 |
|
|
733 |
0 |
SequenceFeature copy = new SequenceFeature(sf, newBegin, newEnd, |
734 |
|
group, sf.getScore()); |
735 |
|
|
736 |
0 |
targetSequence.addSequenceFeature(copy); |
737 |
|
|
738 |
|
|
739 |
|
|
740 |
|
|
741 |
|
|
742 |
0 |
if (!forwardStrand && SequenceOntologyFactory.getInstance() |
743 |
|
.isA(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT)) |
744 |
|
{ |
745 |
0 |
reverseComplementAlleles(copy); |
746 |
|
} |
747 |
|
} |
748 |
|
} |
749 |
|
|
750 |
|
|
751 |
|
|
752 |
|
|
753 |
|
|
754 |
|
@param |
755 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
756 |
0 |
static void reverseComplementAlleles(SequenceFeature sf)... |
757 |
|
{ |
758 |
0 |
final String alleles = (String) sf.getValue(Gff3Helper.ALLELES); |
759 |
0 |
if (alleles == null) |
760 |
|
{ |
761 |
0 |
return; |
762 |
|
} |
763 |
0 |
StringBuilder complement = new StringBuilder(alleles.length()); |
764 |
0 |
for (String allele : alleles.split(",")) |
765 |
|
{ |
766 |
0 |
reverseComplementAllele(complement, allele); |
767 |
|
} |
768 |
0 |
String comp = complement.toString(); |
769 |
0 |
sf.setValue(Gff3Helper.ALLELES, comp); |
770 |
0 |
sf.setDescription(comp); |
771 |
|
} |
772 |
|
|
773 |
|
|
774 |
|
|
775 |
|
|
776 |
|
|
777 |
|
@param |
778 |
|
@param |
779 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
780 |
0 |
static void reverseComplementAllele(StringBuilder complement,... |
781 |
|
String allele) |
782 |
|
{ |
783 |
0 |
if (complement.length() > 0) |
784 |
|
{ |
785 |
0 |
complement.append(","); |
786 |
|
} |
787 |
|
|
788 |
|
|
789 |
|
|
790 |
|
|
791 |
|
|
792 |
|
|
793 |
0 |
if (!Comparison.isNucleotideSequence(allele, true)) |
794 |
|
{ |
795 |
0 |
complement.append(allele); |
796 |
|
} |
797 |
|
else |
798 |
|
{ |
799 |
0 |
for (int i = allele.length() - 1; i >= 0; i--) |
800 |
|
{ |
801 |
0 |
complement.append(Dna.getComplement(allele.charAt(i))); |
802 |
|
} |
803 |
|
} |
804 |
|
} |
805 |
|
|
806 |
|
|
807 |
|
|
808 |
|
|
809 |
|
@param |
810 |
|
@param |
811 |
|
@param |
812 |
|
@return |
813 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
814 |
0 |
protected boolean transferFeatures(String accessionId,... |
815 |
|
SequenceI sourceSequence, SequenceI targetSequence) |
816 |
|
{ |
817 |
0 |
if (sourceSequence == null || targetSequence == null) |
818 |
|
{ |
819 |
0 |
return false; |
820 |
|
} |
821 |
|
|
822 |
|
|
823 |
0 |
List<SequenceFeature> sfs = sourceSequence.getFeatures() |
824 |
|
.getPositionalFeatures(); |
825 |
0 |
MapList mapping = getGenomicRangesFromFeatures(sourceSequence, |
826 |
|
accessionId, targetSequence.getStart()); |
827 |
0 |
if (mapping == null) |
828 |
|
{ |
829 |
0 |
return false; |
830 |
|
} |
831 |
|
|
832 |
|
|
833 |
|
|
834 |
0 |
boolean result = transferFeatures(sfs, targetSequence, mapping, |
835 |
|
accessionId); |
836 |
|
|
837 |
|
|
838 |
|
|
839 |
|
|
840 |
|
|
841 |
0 |
return result; |
842 |
|
} |
843 |
|
|
844 |
|
|
845 |
|
|
846 |
|
|
847 |
|
|
848 |
|
|
849 |
|
@param |
850 |
|
@param |
851 |
|
@param |
852 |
|
@param |
853 |
|
@return |
854 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
855 |
0 |
protected boolean transferFeatures(List<SequenceFeature> sfs,... |
856 |
|
SequenceI targetSequence, MapList mapping, String parentId) |
857 |
|
{ |
858 |
0 |
final boolean forwardStrand = mapping.isFromForwardStrand(); |
859 |
|
|
860 |
|
|
861 |
|
|
862 |
|
|
863 |
|
|
864 |
|
|
865 |
0 |
SequenceFeatures.sortFeatures(sfs, forwardStrand); |
866 |
|
|
867 |
0 |
boolean transferred = false; |
868 |
|
|
869 |
0 |
for (int i = 0, n = sfs.size(); i < n; i++) |
870 |
|
{ |
871 |
|
|
872 |
|
|
873 |
|
|
874 |
|
|
875 |
|
|
876 |
|
|
877 |
|
|
878 |
0 |
SequenceFeature sf = sfs.get(i); |
879 |
0 |
if (retainFeature(sf, parentId)) |
880 |
|
{ |
881 |
0 |
transferFeature(sf, targetSequence, mapping, forwardStrand); |
882 |
0 |
transferred = true; |
883 |
|
} |
884 |
|
} |
885 |
|
|
886 |
0 |
return transferred; |
887 |
|
} |
888 |
|
|
889 |
|
|
890 |
|
|
891 |
|
|
892 |
|
|
893 |
|
|
894 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
895 |
0 |
@SuppressWarnings("unused")... |
896 |
|
protected boolean retainFeature(SequenceFeature sf, String accessionId) |
897 |
|
{ |
898 |
0 |
return true; |
899 |
|
} |
900 |
|
|
901 |
|
|
902 |
|
|
903 |
|
|
904 |
|
|
905 |
|
|
906 |
|
@param |
907 |
|
@param |
908 |
|
@return |
909 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
910 |
0 |
protected boolean featureMayBelong(SequenceFeature sf, String identifier)... |
911 |
|
{ |
912 |
0 |
String parent = (String) sf.getValue(PARENT); |
913 |
0 |
if (parent != null && !parent.equalsIgnoreCase(identifier)) |
914 |
|
{ |
915 |
|
|
916 |
0 |
return false; |
917 |
|
} |
918 |
0 |
return true; |
919 |
|
} |
920 |
|
|
921 |
|
|
922 |
|
|
923 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
924 |
0 |
@Override... |
925 |
|
public String getDescription() |
926 |
|
{ |
927 |
0 |
return "Ensembl " + getSourceEnsemblType().getType() |
928 |
|
+ " sequence with variant features"; |
929 |
|
} |
930 |
|
|
931 |
|
|
932 |
|
|
933 |
|
|
934 |
|
|
935 |
|
|
936 |
|
@param |
937 |
|
@param |
938 |
|
@param |
939 |
|
@return |
940 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
941 |
0 |
protected List<SequenceFeature> findFeatures(SequenceI sequence,... |
942 |
|
String term, String parentId) |
943 |
|
{ |
944 |
0 |
List<SequenceFeature> result = new ArrayList<>(); |
945 |
|
|
946 |
0 |
List<SequenceFeature> sfs = sequence.getFeatures() |
947 |
|
.getFeaturesByOntology(term); |
948 |
0 |
for (SequenceFeature sf : sfs) |
949 |
|
{ |
950 |
0 |
String parent = (String) sf.getValue(PARENT); |
951 |
0 |
if (parent != null && parent.equalsIgnoreCase(parentId)) |
952 |
|
{ |
953 |
0 |
result.add(sf); |
954 |
|
} |
955 |
|
} |
956 |
|
|
957 |
0 |
return result; |
958 |
|
} |
959 |
|
|
960 |
|
|
961 |
|
|
962 |
|
|
963 |
|
|
964 |
|
|
965 |
|
|
966 |
|
|
967 |
|
|
968 |
|
|
969 |
|
|
970 |
|
|
971 |
|
@param |
972 |
|
@return |
973 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
974 |
0 |
public static boolean isTranscript(String featureType)... |
975 |
|
{ |
976 |
0 |
return SequenceOntologyI.NMD_TRANSCRIPT_VARIANT.equals(featureType) |
977 |
|
|| SequenceOntologyFactory.getInstance().isA(featureType, |
978 |
|
SequenceOntologyI.TRANSCRIPT); |
979 |
|
} |
980 |
|
} |