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.DBRefEntry; |
25 |
|
import jalview.util.DBRefUtils; |
26 |
|
|
27 |
|
import java.io.BufferedReader; |
28 |
|
import java.io.IOException; |
29 |
|
import java.net.MalformedURLException; |
30 |
|
import java.net.URL; |
31 |
|
import java.util.ArrayList; |
32 |
|
import java.util.Iterator; |
33 |
|
import java.util.List; |
34 |
|
|
35 |
|
import org.json.simple.JSONArray; |
36 |
|
import org.json.simple.JSONObject; |
37 |
|
import org.json.simple.parser.JSONParser; |
38 |
|
import org.json.simple.parser.ParseException; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@author |
45 |
|
@see |
46 |
|
|
|
|
| 74.6% |
Uncovered Elements: 16 (63) |
Complexity: 22 |
Complexity Density: 0.52 |
|
47 |
|
class EnsemblXref extends EnsemblRestClient |
48 |
|
{ |
49 |
|
|
50 |
|
private static final String GO_GENE_ONTOLOGY = "GO"; |
51 |
|
|
52 |
|
private String dbName = "ENSEMBL (xref)"; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@param |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
59 |
1 |
public EnsemblXref(String d, String dbSource, String version)... |
60 |
|
{ |
61 |
1 |
super(d); |
62 |
1 |
dbName = dbSource; |
63 |
1 |
xrefVersion = dbSource + ":" + version; |
64 |
|
|
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0 |
@Override... |
68 |
|
public String getDbName() |
69 |
|
{ |
70 |
0 |
return dbName; |
71 |
|
} |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
0 |
@Override... |
74 |
|
public AlignmentI getSequenceRecords(String queries) throws Exception |
75 |
|
{ |
76 |
0 |
return null; |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0 |
@Override... |
80 |
|
protected URL getUrl(List<String> ids) throws MalformedURLException |
81 |
|
{ |
82 |
0 |
return getUrl(ids.get(0)); |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
0 |
@Override... |
86 |
|
protected boolean useGetRequest() |
87 |
|
{ |
88 |
0 |
return true; |
89 |
|
} |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0 |
@Override... |
92 |
|
protected String getRequestMimeType(boolean multipleIds) |
93 |
|
{ |
94 |
0 |
return "application/json"; |
95 |
|
} |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
0 |
@Override... |
98 |
|
protected String getResponseMimeType() |
99 |
|
{ |
100 |
0 |
return "application/json"; |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
@param |
111 |
|
|
112 |
|
@return |
113 |
|
|
|
|
| 85% |
Uncovered Elements: 3 (20) |
Complexity: 6 |
Complexity Density: 0.43 |
|
114 |
1 |
public List<DBRefEntry> getCrossReferences(String identifier)... |
115 |
|
{ |
116 |
1 |
List<DBRefEntry> result = new ArrayList<DBRefEntry>(); |
117 |
1 |
List<String> ids = new ArrayList<String>(); |
118 |
1 |
ids.add(identifier); |
119 |
|
|
120 |
1 |
BufferedReader br = null; |
121 |
1 |
try |
122 |
|
{ |
123 |
1 |
URL url = getUrl(identifier); |
124 |
1 |
if (url != null) |
125 |
|
{ |
126 |
1 |
br = getHttpResponse(url, ids); |
127 |
1 |
if (br != null) |
128 |
|
{ |
129 |
1 |
result = parseResponse(br); |
130 |
|
} |
131 |
|
} |
132 |
|
} catch (IOException e) |
133 |
|
{ |
134 |
|
|
135 |
|
} finally |
136 |
|
{ |
137 |
1 |
if (br != null) |
138 |
|
{ |
139 |
1 |
try |
140 |
|
{ |
141 |
1 |
br.close(); |
142 |
|
} catch (IOException e) |
143 |
|
{ |
144 |
|
|
145 |
|
} |
146 |
|
} |
147 |
|
} |
148 |
|
|
149 |
1 |
return result; |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
@param |
159 |
|
@return |
160 |
|
@throws |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 6 |
Complexity Density: 0.43 |
|
162 |
1 |
protected List<DBRefEntry> parseResponse(BufferedReader br)... |
163 |
|
throws IOException |
164 |
|
{ |
165 |
1 |
JSONParser jp = new JSONParser(); |
166 |
1 |
List<DBRefEntry> result = new ArrayList<DBRefEntry>(); |
167 |
1 |
try |
168 |
|
{ |
169 |
1 |
JSONArray responses = (JSONArray) jp.parse(br); |
170 |
1 |
Iterator rvals = responses.iterator(); |
171 |
4 |
while (rvals.hasNext()) |
172 |
|
{ |
173 |
3 |
JSONObject val = (JSONObject) rvals.next(); |
174 |
3 |
String db = val.get("dbname").toString(); |
175 |
3 |
String id = val.get("primary_id").toString(); |
176 |
3 |
if (db != null && id != null |
177 |
|
&& !GO_GENE_ONTOLOGY.equals(db)) |
178 |
|
{ |
179 |
2 |
db = DBRefUtils.getCanonicalName(db); |
180 |
2 |
DBRefEntry dbref = new DBRefEntry(db, getXRefVersion(), id); |
181 |
2 |
result.add(dbref); |
182 |
|
} |
183 |
|
} |
184 |
|
} catch (ParseException e) |
185 |
|
{ |
186 |
|
|
187 |
|
} |
188 |
1 |
return result; |
189 |
|
} |
190 |
|
|
191 |
|
private String xrefVersion = "ENSEMBL:0"; |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
@return |
197 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
198 |
2 |
public String getXRefVersion()... |
199 |
|
{ |
200 |
2 |
return xrefVersion; |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
@param |
209 |
|
@return |
210 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
211 |
1 |
protected URL getUrl(String identifier)... |
212 |
|
{ |
213 |
1 |
String url = getDomain() + "/xrefs/id/" + identifier |
214 |
|
+ CONTENT_TYPE_JSON + "&all_levels=1"; |
215 |
1 |
try |
216 |
|
{ |
217 |
1 |
return new URL(url); |
218 |
|
} catch (MalformedURLException e) |
219 |
|
{ |
220 |
0 |
return null; |
221 |
|
} |
222 |
|
} |
223 |
|
|
224 |
|
} |