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.Alignment; |
24 |
|
import jalview.datamodel.AlignmentI; |
25 |
|
import jalview.datamodel.Sequence; |
26 |
|
import jalview.datamodel.SequenceFeature; |
27 |
|
import jalview.datamodel.SequenceI; |
28 |
|
import jalview.io.gff.SequenceOntologyI; |
29 |
|
import jalview.util.JSONUtils; |
30 |
|
import jalview.util.Platform; |
31 |
|
|
32 |
|
import java.io.BufferedReader; |
33 |
|
import java.io.IOException; |
34 |
|
import java.net.MalformedURLException; |
35 |
|
import java.net.URL; |
36 |
|
import java.util.ArrayList; |
37 |
|
import java.util.Iterator; |
38 |
|
import java.util.List; |
39 |
|
import java.util.Map; |
40 |
|
|
41 |
|
import org.json.simple.parser.ParseException; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@author |
48 |
|
@see |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 98 (98) |
Complexity: 25 |
Complexity Density: 0.39 |
|
50 |
|
class EnsemblFeatures extends EnsemblRestClient |
51 |
|
{ |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
private EnsemblFeatureType[] featuresWanted = { EnsemblFeatureType.cds, |
57 |
|
EnsemblFeatureType.exon, EnsemblFeatureType.variation }; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0 |
public EnsemblFeatures()... |
63 |
|
{ |
64 |
0 |
super(); |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
@param |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
0 |
public EnsemblFeatures(String d)... |
73 |
|
{ |
74 |
0 |
super(d); |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
@Override... |
78 |
|
public String getDbName() |
79 |
|
{ |
80 |
0 |
return "ENSEMBL (features)"; |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
90 |
0 |
@Override... |
91 |
|
public AlignmentI getSequenceRecords(String query) throws IOException |
92 |
|
{ |
93 |
|
|
94 |
|
|
95 |
0 |
List<String> queries = new ArrayList<>(); |
96 |
0 |
queries.add(query); |
97 |
0 |
SequenceI seq = parseFeaturesJson(queries); |
98 |
0 |
if (seq == null) |
99 |
0 |
return null; |
100 |
0 |
return new Alignment(new SequenceI[] { seq }); |
101 |
|
|
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
@param |
109 |
|
@return |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 9 |
Complexity Density: 0.27 |
|
111 |
0 |
@SuppressWarnings("unchecked")... |
112 |
|
private SequenceI parseFeaturesJson(List<String> queries) |
113 |
|
{ |
114 |
0 |
SequenceI seq = new Sequence("Dummy", ""); |
115 |
0 |
try |
116 |
|
{ |
117 |
0 |
Iterator<Object> rvals = (Iterator<Object>) getJSON(null, queries, -1, |
118 |
|
MODE_ITERATOR, null); |
119 |
0 |
if (rvals == null) |
120 |
|
{ |
121 |
0 |
return null; |
122 |
|
} |
123 |
0 |
while (rvals.hasNext()) |
124 |
|
{ |
125 |
0 |
try |
126 |
|
{ |
127 |
0 |
Map<String, Object> obj = (Map<String, Object>) rvals.next(); |
128 |
0 |
String type = obj.get("feature_type").toString(); |
129 |
0 |
int start = Integer.parseInt(obj.get("start").toString()); |
130 |
0 |
int end = Integer.parseInt(obj.get("end").toString()); |
131 |
0 |
String source = obj.get("source").toString(); |
132 |
0 |
String strand = obj.get("strand").toString(); |
133 |
0 |
Object phase = obj.get("phase"); |
134 |
0 |
String alleles = JSONUtils |
135 |
|
.arrayToStringList((List<Object>) obj.get("alleles")); |
136 |
0 |
String clinSig = JSONUtils.arrayToStringList( |
137 |
|
(List<Object>) obj.get("clinical_significance")); |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
0 |
if ("variation".equals(type)) |
145 |
|
{ |
146 |
0 |
type = SequenceOntologyI.SEQUENCE_VARIANT; |
147 |
|
} |
148 |
0 |
else if (SequenceOntologyI.CDS.equalsIgnoreCase((type))) |
149 |
|
{ |
150 |
0 |
type = SequenceOntologyI.CDS; |
151 |
|
} |
152 |
|
|
153 |
0 |
String desc = getFirstNotNull(obj, "alleles", "external_name", |
154 |
|
JSON_ID); |
155 |
0 |
SequenceFeature sf = new SequenceFeature(type, desc, start, end, |
156 |
|
source); |
157 |
0 |
sf.setStrand("1".equals(strand) ? "+" : "-"); |
158 |
0 |
if (phase != null) |
159 |
|
{ |
160 |
0 |
sf.setPhase(phase.toString()); |
161 |
|
} |
162 |
0 |
setFeatureAttribute(sf, obj, "id"); |
163 |
0 |
setFeatureAttribute(sf, obj, "Parent"); |
164 |
0 |
setFeatureAttribute(sf, obj, "consequence_type"); |
165 |
0 |
sf.setValue("alleles", alleles); |
166 |
0 |
sf.setValue("clinical_significance", clinSig); |
167 |
|
|
168 |
0 |
seq.addSequenceFeature(sf); |
169 |
|
|
170 |
|
} catch (Throwable t) |
171 |
|
{ |
172 |
|
|
173 |
|
} |
174 |
|
} |
175 |
|
} catch (ParseException | IOException e) |
176 |
|
{ |
177 |
0 |
e.printStackTrace(); |
178 |
|
|
179 |
|
} |
180 |
|
|
181 |
0 |
return seq; |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
@param |
190 |
|
@param |
191 |
|
@return |
192 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
193 |
0 |
@SuppressWarnings("unchecked")... |
194 |
|
protected String getFirstNotNull(Map<String, Object> obj, String... keys) |
195 |
|
{ |
196 |
0 |
for (String key : keys) |
197 |
|
{ |
198 |
0 |
Object val = obj.get(key); |
199 |
0 |
if (val != null) |
200 |
|
{ |
201 |
0 |
String s = val instanceof List<?> |
202 |
|
? JSONUtils.arrayToStringList((List<Object>) val) |
203 |
|
: val.toString(); |
204 |
0 |
if (!s.isEmpty()) |
205 |
|
{ |
206 |
0 |
return s; |
207 |
|
} |
208 |
|
} |
209 |
|
} |
210 |
0 |
return null; |
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
@param |
218 |
|
@param |
219 |
|
@param |
220 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
221 |
0 |
protected void setFeatureAttribute(SequenceFeature sf,... |
222 |
|
Map<String, Object> obj, String key) |
223 |
|
{ |
224 |
0 |
Object object = obj.get(key); |
225 |
0 |
if (object != null) |
226 |
|
{ |
227 |
0 |
sf.setValue(key, object.toString()); |
228 |
|
} |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
@param |
235 |
|
@return |
236 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
237 |
0 |
@Override... |
238 |
|
protected URL getUrl(List<String> ids) throws MalformedURLException |
239 |
|
{ |
240 |
0 |
StringBuffer urlstring = new StringBuffer(128); |
241 |
0 |
urlstring.append(getDomain()).append("/overlap/id/").append(ids.get(0)); |
242 |
|
|
243 |
|
|
244 |
0 |
urlstring.append("?content-type=" + getResponseMimeType()); |
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
0 |
urlstring.append("&").append(OBJECT_TYPE).append("=") |
252 |
|
.append(OBJECT_TYPE_GENE); |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
@see |
257 |
|
|
258 |
|
|
259 |
0 |
for (EnsemblFeatureType feature : featuresWanted) |
260 |
|
{ |
261 |
0 |
urlstring.append("&feature=").append(feature.name()); |
262 |
|
} |
263 |
|
|
264 |
0 |
return new URL(urlstring.toString()); |
265 |
|
} |
266 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
267 |
0 |
@Override... |
268 |
|
protected boolean useGetRequest() |
269 |
|
{ |
270 |
0 |
return true; |
271 |
|
} |
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
277 |
0 |
@Override... |
278 |
|
protected String getRequestMimeType() |
279 |
|
{ |
280 |
0 |
return "application/json"; |
281 |
|
} |
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
286 |
0 |
@Override... |
287 |
|
protected String getResponseMimeType() |
288 |
|
{ |
289 |
0 |
return "application/json"; |
290 |
|
} |
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
@param |
297 |
|
@param |
298 |
|
@return |
299 |
|
@throws |
300 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
301 |
0 |
protected AlignmentI getSequenceRecords(String accId,... |
302 |
|
EnsemblFeatureType[] features) throws IOException |
303 |
|
{ |
304 |
0 |
featuresWanted = features; |
305 |
0 |
return getSequenceRecords(accId); |
306 |
|
} |
307 |
|
} |