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 jalview.datamodel.AlignmentI; |
24 |
|
import jalview.datamodel.DBRefSource; |
25 |
|
import jalview.datamodel.GeneLociI; |
26 |
|
import jalview.datamodel.GeneLocus; |
27 |
|
import jalview.datamodel.Mapping; |
28 |
|
import jalview.util.MapList; |
29 |
|
|
30 |
|
import java.io.IOException; |
31 |
|
import java.net.MalformedURLException; |
32 |
|
import java.net.URL; |
33 |
|
import java.util.ArrayList; |
34 |
|
import java.util.Collections; |
35 |
|
import java.util.Iterator; |
36 |
|
import java.util.List; |
37 |
|
import java.util.Map; |
38 |
|
|
39 |
|
import org.json.simple.parser.ParseException; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@author |
49 |
|
@see |
50 |
|
@see |
51 |
|
@see |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 122 (122) |
Complexity: 33 |
Complexity Density: 0.4 |
|
53 |
|
public class EnsemblMap extends EnsemblRestClient |
54 |
|
{ |
55 |
|
private static final String MAPPED = "mapped"; |
56 |
|
|
57 |
|
private static final String MAPPINGS = "mappings"; |
58 |
|
|
59 |
|
private static final String CDS = "cds"; |
60 |
|
|
61 |
|
private static final String CDNA = "cdna"; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0 |
public EnsemblMap()... |
67 |
|
{ |
68 |
0 |
super(); |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@param |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
0 |
public EnsemblMap(String domain)... |
77 |
|
{ |
78 |
0 |
super(domain); |
79 |
|
} |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0 |
@Override... |
82 |
|
public String getDbName() |
83 |
|
{ |
84 |
0 |
return DBRefSource.ENSEMBL; |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
0 |
@Override... |
88 |
|
public AlignmentI getSequenceRecords(String queries) throws Exception |
89 |
|
{ |
90 |
0 |
return null; |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
@param |
99 |
|
@param |
100 |
|
@param |
101 |
|
@param |
102 |
|
@param |
103 |
|
@param |
104 |
|
@return |
105 |
|
@throws |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
107 |
0 |
protected URL getAssemblyMapUrl(String species, String chromosome,... |
108 |
|
String fromRef, String toRef, int startPos, int endPos) |
109 |
|
throws MalformedURLException |
110 |
|
{ |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
0 |
boolean forward = startPos <= endPos; |
115 |
0 |
int start = forward ? startPos : endPos; |
116 |
0 |
int end = forward ? endPos : startPos; |
117 |
0 |
String strand = forward ? "1" : "-1"; |
118 |
0 |
String url = String.format( |
119 |
|
"%s/map/%s/%s/%s:%d..%d:%s/%s?content-type=application/json", |
120 |
|
getDomain(), species, fromRef, chromosome, start, end, strand, |
121 |
|
toRef); |
122 |
0 |
return new URL(url); |
123 |
|
} |
124 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
0 |
@Override... |
126 |
|
protected boolean useGetRequest() |
127 |
|
{ |
128 |
0 |
return true; |
129 |
|
} |
130 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
131 |
0 |
@Override... |
132 |
|
protected URL getUrl(List<String> ids) throws MalformedURLException |
133 |
|
{ |
134 |
0 |
return null; |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
@param |
142 |
|
@param |
143 |
|
@param |
144 |
|
@param |
145 |
|
@param |
146 |
|
@return |
147 |
|
@see |
148 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
149 |
0 |
public int[] getAssemblyMapping(String species, String chromosome,... |
150 |
|
String fromRef, String toRef, int[] queryRange) |
151 |
|
{ |
152 |
0 |
URL url = null; |
153 |
0 |
try |
154 |
|
{ |
155 |
0 |
url = getAssemblyMapUrl(species, chromosome, fromRef, toRef, |
156 |
|
queryRange[0], queryRange[1]); |
157 |
0 |
return (parseAssemblyMappingResponse(url)); |
158 |
|
} catch (Throwable t) |
159 |
|
{ |
160 |
0 |
jalview.bin.Console |
161 |
|
.outPrintln("Error calling " + url + ": " + t.getMessage()); |
162 |
0 |
return null; |
163 |
|
} |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
@param |
179 |
|
@return |
180 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 5 |
Complexity Density: 0.33 |
|
181 |
0 |
@SuppressWarnings("unchecked")... |
182 |
|
protected int[] parseAssemblyMappingResponse(URL url) |
183 |
|
{ |
184 |
0 |
int[] result = null; |
185 |
|
|
186 |
0 |
try |
187 |
|
{ |
188 |
0 |
Iterator<Object> rvals = (Iterator<Object>) getJSON(url, null, -1, |
189 |
|
MODE_ITERATOR, MAPPINGS); |
190 |
0 |
if (rvals == null) |
191 |
|
{ |
192 |
0 |
return null; |
193 |
|
} |
194 |
0 |
while (rvals.hasNext()) |
195 |
|
{ |
196 |
|
|
197 |
0 |
Map<String, Object> val = (Map<String, Object>) rvals.next(); |
198 |
0 |
Map<String, Object> mapped = (Map<String, Object>) val.get(MAPPED); |
199 |
0 |
int start = Integer.parseInt(mapped.get("start").toString()); |
200 |
0 |
int end = Integer.parseInt(mapped.get("end").toString()); |
201 |
0 |
String strand = mapped.get("strand").toString(); |
202 |
0 |
if ("1".equals(strand)) |
203 |
|
{ |
204 |
0 |
result = new int[] { start, end }; |
205 |
|
} |
206 |
|
else |
207 |
|
{ |
208 |
0 |
result = new int[] { end, start }; |
209 |
|
} |
210 |
|
} |
211 |
|
} catch (IOException | ParseException | NumberFormatException e) |
212 |
|
{ |
213 |
|
|
214 |
|
} |
215 |
0 |
return result; |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
@param |
223 |
|
|
224 |
|
@param |
225 |
|
|
226 |
|
@param |
227 |
|
@param |
228 |
|
@return |
229 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
230 |
0 |
public GeneLociI getCdsMapping(String division, String accession,... |
231 |
|
int start, int end) |
232 |
|
{ |
233 |
0 |
return getIdMapping(division, accession, start, end, CDS); |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
@param |
241 |
|
|
242 |
|
@param |
243 |
|
|
244 |
|
@param |
245 |
|
@param |
246 |
|
@return |
247 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
248 |
0 |
public GeneLociI getCdnaMapping(String division, String accession,... |
249 |
|
int start, int end) |
250 |
|
{ |
251 |
0 |
return getIdMapping(division, accession, start, end, CDNA); |
252 |
|
} |
253 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
254 |
0 |
GeneLociI getIdMapping(String division, String accession, int start,... |
255 |
|
int end, String cdsOrCdna) |
256 |
|
{ |
257 |
0 |
URL url = null; |
258 |
0 |
try |
259 |
|
{ |
260 |
0 |
String domain = new EnsemblInfo().getDomain(division); |
261 |
0 |
if (domain != null) |
262 |
|
{ |
263 |
0 |
url = getIdMapUrl(domain, accession, start, end, cdsOrCdna); |
264 |
0 |
return (parseIdMappingResponse(url, accession, domain)); |
265 |
|
} |
266 |
0 |
return null; |
267 |
|
} catch (Throwable t) |
268 |
|
{ |
269 |
0 |
jalview.bin.Console |
270 |
|
.outPrintln("Error calling " + url + ": " + t.getMessage()); |
271 |
0 |
return null; |
272 |
|
} |
273 |
|
} |
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
@param |
281 |
|
@param |
282 |
|
@param |
283 |
|
@param |
284 |
|
@param |
285 |
|
@return |
286 |
|
@throws |
287 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
288 |
0 |
URL getIdMapUrl(String domain, String accession, int start, int end,... |
289 |
|
String cdsOrCdna) throws MalformedURLException |
290 |
|
{ |
291 |
0 |
String url = String.format( |
292 |
|
"%s/map/%s/%s/%d..%d?include_original_region=1&content-type=application/json", |
293 |
|
domain, cdsOrCdna, accession, start, end); |
294 |
0 |
return new URL(url); |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
@param |
313 |
|
@param |
314 |
|
@param |
315 |
|
@return |
316 |
|
|
|
|
| 0% |
Uncovered Elements: 48 (48) |
Complexity: 10 |
Complexity Density: 0.28 |
|
317 |
0 |
@SuppressWarnings("unchecked")... |
318 |
|
GeneLociI parseIdMappingResponse(URL url, String accession, String domain) |
319 |
|
{ |
320 |
|
|
321 |
0 |
try |
322 |
|
{ |
323 |
0 |
Iterator<Object> rvals = (Iterator<Object>) getJSON(url, null, -1, |
324 |
|
MODE_ITERATOR, MAPPINGS); |
325 |
0 |
if (rvals == null) |
326 |
|
{ |
327 |
0 |
return null; |
328 |
|
} |
329 |
0 |
String assembly = null; |
330 |
0 |
String chromosome = null; |
331 |
0 |
int fromEnd = 0; |
332 |
0 |
List<int[]> regions = new ArrayList<>(); |
333 |
|
|
334 |
0 |
while (rvals.hasNext()) |
335 |
|
{ |
336 |
0 |
Map<String, Object> val = (Map<String, Object>) rvals.next(); |
337 |
0 |
Map<String, Object> original = (Map<String, Object>) val |
338 |
|
.get("original"); |
339 |
0 |
fromEnd = Integer.parseInt(original.get("end").toString()); |
340 |
|
|
341 |
0 |
Map<String, Object> mapped = (Map<String, Object>) val.get(MAPPED); |
342 |
0 |
int start = Integer.parseInt(mapped.get("start").toString()); |
343 |
0 |
int end = Integer.parseInt(mapped.get("end").toString()); |
344 |
0 |
String ass = mapped.get("assembly_name").toString(); |
345 |
0 |
if (assembly != null && !assembly.equals(ass)) |
346 |
|
{ |
347 |
0 |
jalview.bin.Console.errPrintln( |
348 |
|
"EnsemblMap found multiple assemblies - can't resolve"); |
349 |
0 |
return null; |
350 |
|
} |
351 |
0 |
assembly = ass; |
352 |
0 |
String chr = mapped.get("seq_region_name").toString(); |
353 |
0 |
if (chromosome != null && !chromosome.equals(chr)) |
354 |
|
{ |
355 |
0 |
jalview.bin.Console.errPrintln( |
356 |
|
"EnsemblMap found multiple chromosomes - can't resolve"); |
357 |
0 |
return null; |
358 |
|
} |
359 |
0 |
chromosome = chr; |
360 |
0 |
String strand = mapped.get("strand").toString(); |
361 |
0 |
if ("-1".equals(strand)) |
362 |
|
{ |
363 |
0 |
regions.add(new int[] { end, start }); |
364 |
|
} |
365 |
|
else |
366 |
|
{ |
367 |
0 |
regions.add(new int[] { start, end }); |
368 |
|
} |
369 |
|
} |
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
0 |
final String species = new EnsemblLookup(domain) |
376 |
|
.getSpecies(accession); |
377 |
0 |
final String as = assembly; |
378 |
0 |
final String chr = chromosome; |
379 |
0 |
List<int[]> fromRange = Collections |
380 |
|
.singletonList(new int[] |
381 |
|
{ 1, fromEnd }); |
382 |
0 |
Mapping mapping = new Mapping(new MapList(fromRange, regions, 1, 1)); |
383 |
0 |
return new GeneLocus(species == null ? "" : species, as, chr, |
384 |
|
mapping); |
385 |
|
} catch (IOException | ParseException | NumberFormatException e) |
386 |
|
{ |
387 |
|
|
388 |
|
} |
389 |
|
|
390 |
0 |
return null; |
391 |
|
} |
392 |
|
|
393 |
|
} |