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.Cache; |
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 |
|
|
|
|
| 19% |
Uncovered Elements: 277 (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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
32 |
public EnsemblSeqProxy()... |
112 |
|
{ |
113 |
32 |
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 |
System.err.println(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 |
System.err.println( |
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 |
System.out.println("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 |
System.out.println("No protein product found for " + accId); |
274 |
0 |
return; |
275 |
|
} |
276 |
0 |
SequenceI proteinSeq = protein.getSequenceAt(0); |
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
0 |
proteinSeq.createDatasetSequence(); |
282 |
0 |
querySeq.createDatasetSequence(); |
283 |
|
|
284 |
0 |
MapList mapList = AlignmentUtils.mapCdsToProtein(querySeq, |
285 |
|
proteinSeq); |
286 |
0 |
if (mapList != null) |
287 |
|
{ |
288 |
|
|
289 |
0 |
SequenceI ds = proteinSeq.getDatasetSequence(); |
290 |
|
|
291 |
0 |
Mapping map = new Mapping(ds, mapList); |
292 |
0 |
DBRefEntry dbr = new DBRefEntry(getDbSource(), |
293 |
|
getEnsemblDataVersion(), proteinSeq.getName(), map); |
294 |
0 |
querySeq.getDatasetSequence().addDBRef(dbr); |
295 |
0 |
List<DBRefEntry> uprots = DBRefUtils.selectRefs(ds.getDBRefs(), |
296 |
|
new String[] |
297 |
|
{ DBRefSource.UNIPROT }); |
298 |
0 |
List<DBRefEntry> upxrefs = DBRefUtils.selectRefs(querySeq.getDBRefs(), |
299 |
|
new String[] |
300 |
|
{ DBRefSource.UNIPROT }); |
301 |
0 |
if (uprots != null) |
302 |
|
{ |
303 |
0 |
for (DBRefEntry up : uprots) |
304 |
|
{ |
305 |
|
|
306 |
0 |
List<DBRefEntry> upx = DBRefUtils.searchRefs(upxrefs, |
307 |
|
up.getAccessionId()); |
308 |
0 |
DBRefEntry upxref; |
309 |
0 |
if (upx.size() != 0) |
310 |
|
{ |
311 |
0 |
upxref = upx.get(0); |
312 |
|
|
313 |
0 |
if (upx.size() > 1) |
314 |
|
{ |
315 |
0 |
Cache.log.warn( |
316 |
|
"Implementation issue - multiple uniprot acc on product sequence."); |
317 |
|
} |
318 |
|
} |
319 |
|
else |
320 |
|
{ |
321 |
0 |
upxref = new DBRefEntry(DBRefSource.UNIPROT, |
322 |
|
getEnsemblDataVersion(), up.getAccessionId()); |
323 |
|
} |
324 |
|
|
325 |
0 |
Mapping newMap = new Mapping(ds, mapList); |
326 |
0 |
upxref.setVersion(getEnsemblDataVersion()); |
327 |
0 |
upxref.setMap(newMap); |
328 |
0 |
if (upx.size() == 0) |
329 |
|
{ |
330 |
|
|
331 |
0 |
querySeq.getDatasetSequence().addDBRef(upxref); |
332 |
|
} |
333 |
|
|
334 |
|
} |
335 |
|
} |
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
} |
344 |
|
} catch (Exception e) |
345 |
|
{ |
346 |
0 |
System.err |
347 |
|
.println(String.format("Error retrieving protein for %s: %s", |
348 |
|
accId, e.getMessage())); |
349 |
|
} |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
@param |
356 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
357 |
0 |
protected void getCrossReferences(SequenceI seq)... |
358 |
|
{ |
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 |
0 |
seq.addDBRef(xrefs.get(i)); |
382 |
|
} |
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
|
389 |
|
|
390 |
|
|
391 |
0 |
DBRefEntry self = new DBRefEntry(getDbSource(), getEnsemblDataVersion(), |
392 |
|
seq.getName()); |
393 |
|
|
394 |
|
|
395 |
|
|
396 |
0 |
seq.addDBRef(self); |
397 |
|
|
398 |
|
|
399 |
|
} |
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
|
405 |
|
@param |
406 |
|
@param |
407 |
|
@return |
408 |
|
@throws |
409 |
|
@throws |
410 |
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 10 |
Complexity Density: 0.43 |
|
411 |
0 |
protected AlignmentI fetchSequences(List<String> ids,... |
412 |
|
AlignmentI alignment) throws JalviewException, IOException |
413 |
|
{ |
414 |
0 |
if (!isEnsemblAvailable()) |
415 |
|
{ |
416 |
0 |
inProgress = false; |
417 |
0 |
throw new JalviewException("ENSEMBL Rest API not available."); |
418 |
|
} |
419 |
|
|
420 |
|
|
421 |
0 |
List<SequenceI> seqs = parseSequenceJson(ids); |
422 |
0 |
if (seqs == null) |
423 |
0 |
return alignment; |
424 |
|
|
425 |
0 |
if (seqs.isEmpty()) |
426 |
|
{ |
427 |
0 |
throw new IOException("No data returned for " + ids); |
428 |
|
} |
429 |
|
|
430 |
0 |
if (seqs.size() != ids.size()) |
431 |
|
{ |
432 |
0 |
System.out.println(String.format( |
433 |
|
"Only retrieved %d sequences for %d query strings", |
434 |
|
seqs.size(), ids.size())); |
435 |
|
} |
436 |
|
|
437 |
0 |
if (!seqs.isEmpty()) |
438 |
|
{ |
439 |
0 |
AlignmentI seqal = new Alignment( |
440 |
|
seqs.toArray(new SequenceI[seqs.size()])); |
441 |
0 |
for (SequenceI seq : seqs) |
442 |
|
{ |
443 |
0 |
if (seq.getDescription() == null) |
444 |
|
{ |
445 |
0 |
seq.setDescription(getDbName()); |
446 |
|
} |
447 |
0 |
String name = seq.getName(); |
448 |
0 |
if (ids.contains(name) |
449 |
|
|| ids.contains(name.replace("ENSP", "ENST"))) |
450 |
|
{ |
451 |
|
|
452 |
0 |
DBRefEntry dbref = DBRefUtils.parseToDbRef(seq, getDbSource(), |
453 |
|
getEnsemblDataVersion(), name); |
454 |
0 |
seq.addDBRef(dbref); |
455 |
|
} |
456 |
|
} |
457 |
0 |
if (alignment == null) |
458 |
|
{ |
459 |
0 |
alignment = seqal; |
460 |
|
} |
461 |
|
else |
462 |
|
{ |
463 |
0 |
alignment.append(seqal); |
464 |
|
} |
465 |
|
} |
466 |
0 |
return alignment; |
467 |
|
} |
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
|
@param |
473 |
|
@return |
474 |
|
@see |
475 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 7 |
Complexity Density: 0.41 |
|
476 |
0 |
@SuppressWarnings("unchecked")... |
477 |
|
protected List<SequenceI> parseSequenceJson(List<String> ids) |
478 |
|
{ |
479 |
0 |
List<SequenceI> result = new ArrayList<>(); |
480 |
0 |
try |
481 |
|
{ |
482 |
|
|
483 |
|
|
484 |
|
|
485 |
|
|
486 |
|
|
487 |
0 |
Map<String, Object> val = (Map<String, Object>) getJSON(null, ids, -1, MODE_MAP, null); |
488 |
0 |
if (val == null) |
489 |
0 |
return null; |
490 |
0 |
Object s = val.get("desc"); |
491 |
0 |
String desc = s == null ? null : s.toString(); |
492 |
0 |
s = val.get("id"); |
493 |
0 |
String id = s == null ? null : s.toString(); |
494 |
0 |
s = val.get("seq"); |
495 |
0 |
String seq = s == null ? null : s.toString(); |
496 |
0 |
Sequence sequence = new Sequence(id, seq); |
497 |
0 |
if (desc != null) |
498 |
|
{ |
499 |
0 |
sequence.setDescription(desc); |
500 |
|
} |
501 |
|
|
502 |
|
|
503 |
|
|
504 |
|
|
505 |
|
|
506 |
0 |
result.add(sequence); |
507 |
|
} catch (ParseException | IOException e) |
508 |
|
{ |
509 |
0 |
System.err.println("Error processing JSON response: " + e.toString()); |
510 |
|
|
511 |
|
} |
512 |
|
|
513 |
0 |
return result; |
514 |
|
} |
515 |
|
|
516 |
|
|
517 |
|
|
518 |
|
|
519 |
|
@return |
520 |
|
@throws |
521 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
522 |
0 |
@Override... |
523 |
|
protected URL getUrl(List<String> ids) throws MalformedURLException |
524 |
|
{ |
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
|
529 |
0 |
StringBuffer urlstring = new StringBuffer(128); |
530 |
0 |
urlstring.append(getDomain() + "/sequence/id"); |
531 |
0 |
if (ids.size() == 1) |
532 |
|
{ |
533 |
0 |
urlstring.append("/").append(ids.get(0)); |
534 |
|
} |
535 |
|
|
536 |
0 |
urlstring.append("?type=").append(getSourceEnsemblType().getType()); |
537 |
0 |
urlstring.append(("&Accept=application/json")); |
538 |
0 |
urlstring.append(("&content-type=application/json")); |
539 |
|
|
540 |
0 |
String objectType = getObjectType(); |
541 |
0 |
if (objectType != null) |
542 |
|
{ |
543 |
0 |
urlstring.append("&").append(OBJECT_TYPE).append("=") |
544 |
|
.append(objectType); |
545 |
|
} |
546 |
|
|
547 |
0 |
URL url = new URL(urlstring.toString()); |
548 |
0 |
return url; |
549 |
|
} |
550 |
|
|
551 |
|
|
552 |
|
|
553 |
|
|
554 |
|
@return |
555 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
556 |
0 |
protected String getObjectType()... |
557 |
|
{ |
558 |
0 |
return null; |
559 |
|
} |
560 |
|
|
561 |
|
|
562 |
|
|
563 |
|
|
564 |
|
@see |
565 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
566 |
0 |
@Override... |
567 |
|
public int getMaximumQueryCount() |
568 |
|
{ |
569 |
0 |
return 50; |
570 |
|
} |
571 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
572 |
0 |
@Override... |
573 |
|
protected boolean useGetRequest() |
574 |
|
{ |
575 |
0 |
return false; |
576 |
|
} |
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
@return |
581 |
|
|
582 |
|
protected abstract EnsemblSeqType getSourceEnsemblType(); |
583 |
|
|
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
|
|
591 |
|
|
592 |
|
|
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
|
597 |
|
|
598 |
|
|
599 |
|
|
600 |
|
|
601 |
|
|
602 |
|
|
603 |
|
|
604 |
|
@param |
605 |
|
@param |
606 |
|
@param |
607 |
|
|
608 |
|
@return |
609 |
|
|
|
|
| 81.1% |
Uncovered Elements: 7 (37) |
Complexity: 8 |
Complexity Density: 0.32 |
|
610 |
7 |
protected MapList getGenomicRangesFromFeatures(SequenceI sourceSequence,... |
611 |
|
String accId, int start) |
612 |
|
{ |
613 |
7 |
List<SequenceFeature> sfs = getIdentifyingFeatures(sourceSequence, |
614 |
|
accId); |
615 |
7 |
if (sfs.isEmpty()) |
616 |
|
{ |
617 |
1 |
return null; |
618 |
|
} |
619 |
|
|
620 |
|
|
621 |
|
|
622 |
|
|
623 |
|
|
624 |
6 |
List<int[]> regions = new ArrayList<>(100); |
625 |
6 |
int mappedLength = 0; |
626 |
6 |
int direction = 1; |
627 |
6 |
boolean directionSet = false; |
628 |
|
|
629 |
6 |
for (SequenceFeature sf : sfs) |
630 |
|
{ |
631 |
11 |
int strand = sf.getStrand(); |
632 |
11 |
strand = strand == 0 ? 1 : strand; |
633 |
|
|
634 |
11 |
if (directionSet && strand != direction) |
635 |
|
{ |
636 |
|
|
637 |
0 |
System.err |
638 |
|
.println("Error: forward and backward strand for " + accId); |
639 |
0 |
return null; |
640 |
|
} |
641 |
11 |
direction = strand; |
642 |
11 |
directionSet = true; |
643 |
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
11 |
if (strand < 0) |
648 |
|
{ |
649 |
2 |
regions.add(0, new int[] { sf.getEnd(), sf.getBegin() }); |
650 |
|
} |
651 |
|
else |
652 |
|
{ |
653 |
9 |
regions.add(new int[] { sf.getBegin(), sf.getEnd() }); |
654 |
|
} |
655 |
11 |
mappedLength += Math.abs(sf.getEnd() - sf.getBegin() + 1); |
656 |
|
} |
657 |
|
|
658 |
6 |
if (regions.isEmpty()) |
659 |
|
{ |
660 |
0 |
System.out.println("Failed to identify target sequence for " + accId |
661 |
|
+ " from genomic features"); |
662 |
0 |
return null; |
663 |
|
} |
664 |
|
|
665 |
|
|
666 |
|
|
667 |
|
|
668 |
|
|
669 |
6 |
Collections.sort(regions, direction == 1 ? IntRangeComparator.ASCENDING |
670 |
|
: IntRangeComparator.DESCENDING); |
671 |
|
|
672 |
6 |
List<int[]> to = Arrays |
673 |
|
.asList(new int[] |
674 |
|
{ start, start + mappedLength - 1 }); |
675 |
|
|
676 |
6 |
return new MapList(regions, to, 1, 1); |
677 |
|
} |
678 |
|
|
679 |
|
|
680 |
|
|
681 |
|
|
682 |
|
|
683 |
|
|
684 |
|
|
685 |
|
|
686 |
|
@param |
687 |
|
@param |
688 |
|
@return |
689 |
|
|
690 |
|
protected abstract List<SequenceFeature> getIdentifyingFeatures( |
691 |
|
SequenceI seq, String accId); |
692 |
|
|
693 |
|
int bhtest = 0; |
694 |
|
|
695 |
|
|
696 |
|
|
697 |
|
|
698 |
|
|
699 |
|
|
700 |
|
@param |
701 |
|
@param |
702 |
|
@param |
703 |
|
|
704 |
|
|
705 |
|
@param |
706 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
707 |
0 |
protected void transferFeature(SequenceFeature sf,... |
708 |
|
SequenceI targetSequence, MapList mapping, boolean forwardStrand) |
709 |
|
{ |
710 |
0 |
int start = sf.getBegin(); |
711 |
0 |
int end = sf.getEnd(); |
712 |
0 |
int[] mappedRange = mapping.locateInTo(start, end); |
713 |
|
|
714 |
0 |
if (mappedRange != null) |
715 |
|
{ |
716 |
|
|
717 |
0 |
String group = sf.getFeatureGroup(); |
718 |
0 |
if (".".equals(group)) |
719 |
|
{ |
720 |
0 |
group = getDbSource(); |
721 |
|
} |
722 |
0 |
int newBegin = Math.min(mappedRange[0], mappedRange[1]); |
723 |
0 |
int newEnd = Math.max(mappedRange[0], mappedRange[1]); |
724 |
|
|
725 |
0 |
bhtest++; |
726 |
|
|
727 |
0 |
SequenceFeature copy = new SequenceFeature(sf, newBegin, newEnd, group, sf.getScore()); |
728 |
|
|
729 |
0 |
targetSequence.addSequenceFeature(copy); |
730 |
|
|
731 |
|
|
732 |
|
|
733 |
|
|
734 |
|
|
735 |
0 |
if (!forwardStrand && SequenceOntologyFactory.getInstance() |
736 |
|
.isA(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT)) |
737 |
|
{ |
738 |
0 |
reverseComplementAlleles(copy); |
739 |
|
} |
740 |
|
} |
741 |
|
} |
742 |
|
|
743 |
|
|
744 |
|
|
745 |
|
|
746 |
|
|
747 |
|
@param |
748 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
749 |
1 |
static void reverseComplementAlleles(SequenceFeature sf)... |
750 |
|
{ |
751 |
1 |
final String alleles = (String) sf.getValue(Gff3Helper.ALLELES); |
752 |
1 |
if (alleles == null) |
753 |
|
{ |
754 |
0 |
return; |
755 |
|
} |
756 |
1 |
StringBuilder complement = new StringBuilder(alleles.length()); |
757 |
1 |
for (String allele : alleles.split(",")) |
758 |
|
{ |
759 |
5 |
reverseComplementAllele(complement, allele); |
760 |
|
} |
761 |
1 |
String comp = complement.toString(); |
762 |
1 |
sf.setValue(Gff3Helper.ALLELES, comp); |
763 |
1 |
sf.setDescription(comp); |
764 |
|
} |
765 |
|
|
766 |
|
|
767 |
|
|
768 |
|
|
769 |
|
|
770 |
|
@param |
771 |
|
@param |
772 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
773 |
13 |
static void reverseComplementAllele(StringBuilder complement,... |
774 |
|
String allele) |
775 |
|
{ |
776 |
13 |
if (complement.length() > 0) |
777 |
|
{ |
778 |
10 |
complement.append(","); |
779 |
|
} |
780 |
|
|
781 |
|
|
782 |
|
|
783 |
|
|
784 |
|
|
785 |
|
|
786 |
13 |
if (!Comparison.isNucleotideSequence(allele, true)) |
787 |
|
{ |
788 |
3 |
complement.append(allele); |
789 |
|
} |
790 |
|
else |
791 |
|
{ |
792 |
29 |
for (int i = allele.length() - 1; i >= 0; i--) |
793 |
|
{ |
794 |
19 |
complement.append(Dna.getComplement(allele.charAt(i))); |
795 |
|
} |
796 |
|
} |
797 |
|
} |
798 |
|
|
799 |
|
|
800 |
|
|
801 |
|
|
802 |
|
@param |
803 |
|
@param |
804 |
|
@param |
805 |
|
@return |
806 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
807 |
0 |
protected boolean transferFeatures(String accessionId,... |
808 |
|
SequenceI sourceSequence, SequenceI targetSequence) |
809 |
|
{ |
810 |
0 |
if (sourceSequence == null || targetSequence == null) |
811 |
|
{ |
812 |
0 |
return false; |
813 |
|
} |
814 |
|
|
815 |
|
|
816 |
0 |
List<SequenceFeature> sfs = sourceSequence.getFeatures() |
817 |
|
.getPositionalFeatures(); |
818 |
0 |
MapList mapping = getGenomicRangesFromFeatures(sourceSequence, |
819 |
|
accessionId, targetSequence.getStart()); |
820 |
0 |
if (mapping == null) |
821 |
|
{ |
822 |
0 |
return false; |
823 |
|
} |
824 |
|
|
825 |
|
|
826 |
|
|
827 |
0 |
boolean result = transferFeatures(sfs, targetSequence, mapping, |
828 |
|
accessionId); |
829 |
|
|
830 |
|
|
831 |
|
|
832 |
|
|
833 |
0 |
return result; |
834 |
|
} |
835 |
|
|
836 |
|
|
837 |
|
|
838 |
|
|
839 |
|
|
840 |
|
|
841 |
|
@param |
842 |
|
@param |
843 |
|
@param |
844 |
|
@param |
845 |
|
@return |
846 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
847 |
0 |
protected boolean transferFeatures(List<SequenceFeature> sfs,... |
848 |
|
SequenceI targetSequence, MapList mapping, String parentId) |
849 |
|
{ |
850 |
0 |
final boolean forwardStrand = mapping.isFromForwardStrand(); |
851 |
|
|
852 |
|
|
853 |
|
|
854 |
|
|
855 |
|
|
856 |
|
|
857 |
0 |
SequenceFeatures.sortFeatures(sfs, forwardStrand); |
858 |
|
|
859 |
0 |
boolean transferred = false; |
860 |
|
|
861 |
0 |
for (int i = 0, n = sfs.size(); i < n; i++) |
862 |
|
{ |
863 |
|
|
864 |
|
|
865 |
|
|
866 |
|
|
867 |
|
|
868 |
|
|
869 |
0 |
SequenceFeature sf = sfs.get(i); |
870 |
0 |
if (retainFeature(sf, parentId)) |
871 |
|
{ |
872 |
0 |
transferFeature(sf, targetSequence, mapping, forwardStrand); |
873 |
0 |
transferred = true; |
874 |
|
} |
875 |
|
} |
876 |
|
|
877 |
0 |
return transferred; |
878 |
|
} |
879 |
|
|
880 |
|
|
881 |
|
|
882 |
|
|
883 |
|
|
884 |
|
|
885 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
886 |
0 |
@SuppressWarnings("unused")... |
887 |
|
protected boolean retainFeature(SequenceFeature sf, String accessionId) |
888 |
|
{ |
889 |
0 |
return true; |
890 |
|
} |
891 |
|
|
892 |
|
|
893 |
|
|
894 |
|
|
895 |
|
|
896 |
|
|
897 |
|
@param |
898 |
|
@param |
899 |
|
@return |
900 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
901 |
10 |
protected boolean featureMayBelong(SequenceFeature sf, String identifier)... |
902 |
|
{ |
903 |
10 |
String parent = (String) sf.getValue(PARENT); |
904 |
10 |
if (parent != null |
905 |
|
&& !parent.equalsIgnoreCase(identifier)) |
906 |
|
{ |
907 |
|
|
908 |
3 |
return false; |
909 |
|
} |
910 |
7 |
return true; |
911 |
|
} |
912 |
|
|
913 |
|
|
914 |
|
|
915 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
916 |
0 |
@Override... |
917 |
|
public String getDescription() |
918 |
|
{ |
919 |
0 |
return "Ensembl " + getSourceEnsemblType().getType() |
920 |
|
+ " sequence with variant features"; |
921 |
|
} |
922 |
|
|
923 |
|
|
924 |
|
|
925 |
|
|
926 |
|
|
927 |
|
|
928 |
|
@param |
929 |
|
@param |
930 |
|
@param |
931 |
|
@return |
932 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
933 |
0 |
protected List<SequenceFeature> findFeatures(SequenceI sequence,... |
934 |
|
String term, String parentId) |
935 |
|
{ |
936 |
0 |
List<SequenceFeature> result = new ArrayList<>(); |
937 |
|
|
938 |
0 |
List<SequenceFeature> sfs = sequence.getFeatures() |
939 |
|
.getFeaturesByOntology(term); |
940 |
0 |
for (SequenceFeature sf : sfs) |
941 |
|
{ |
942 |
0 |
String parent = (String) sf.getValue(PARENT); |
943 |
0 |
if (parent != null && parent.equalsIgnoreCase(parentId)) |
944 |
|
{ |
945 |
0 |
result.add(sf); |
946 |
|
} |
947 |
|
} |
948 |
|
|
949 |
0 |
return result; |
950 |
|
} |
951 |
|
|
952 |
|
|
953 |
|
|
954 |
|
|
955 |
|
|
956 |
|
|
957 |
|
|
958 |
|
|
959 |
|
|
960 |
|
|
961 |
|
|
962 |
|
|
963 |
|
@param |
964 |
|
@return |
965 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
966 |
18 |
public static boolean isTranscript(String featureType)... |
967 |
|
{ |
968 |
18 |
return SequenceOntologyI.NMD_TRANSCRIPT_VARIANT.equals(featureType) |
969 |
|
|| SequenceOntologyFactory.getInstance().isA(featureType, |
970 |
|
SequenceOntologyI.TRANSCRIPT); |
971 |
|
} |
972 |
|
} |