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.BufferedReader; |
24 |
|
import java.io.IOException; |
25 |
|
import java.net.MalformedURLException; |
26 |
|
import java.net.URL; |
27 |
|
import java.util.ArrayList; |
28 |
|
import java.util.Iterator; |
29 |
|
import java.util.List; |
30 |
|
|
31 |
|
import org.json.simple.JSONArray; |
32 |
|
import org.json.simple.JSONObject; |
33 |
|
import org.json.simple.parser.JSONParser; |
34 |
|
import org.json.simple.parser.ParseException; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@see |
40 |
|
@author |
41 |
|
|
42 |
|
|
|
|
| 0% |
Uncovered Elements: 57 (57) |
Complexity: 16 |
Complexity Density: 0.39 |
|
43 |
|
public class EnsemblSymbol extends EnsemblXref |
44 |
|
{ |
45 |
|
private static final String GENE = "gene"; |
46 |
|
private static final String TYPE = "type"; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@param |
51 |
|
@param |
52 |
|
@param |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
0 |
public EnsemblSymbol(String domain, String dbName, String dbVersion)... |
55 |
|
{ |
56 |
0 |
super(domain, dbName, dbVersion); |
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@param |
64 |
|
@return |
65 |
|
@throws |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.38 |
|
67 |
0 |
protected String parseSymbolResponse(BufferedReader br) throws IOException... |
68 |
|
{ |
69 |
0 |
JSONParser jp = new JSONParser(); |
70 |
0 |
String result = null; |
71 |
0 |
try |
72 |
|
{ |
73 |
0 |
JSONArray responses = (JSONArray) jp.parse(br); |
74 |
0 |
Iterator rvals = responses.iterator(); |
75 |
0 |
while (rvals.hasNext()) |
76 |
|
{ |
77 |
0 |
JSONObject val = (JSONObject) rvals.next(); |
78 |
0 |
String id = val.get(JSON_ID).toString(); |
79 |
0 |
String type = val.get(TYPE).toString(); |
80 |
0 |
if (id != null && GENE.equals(type)) |
81 |
|
{ |
82 |
0 |
result = id; |
83 |
0 |
break; |
84 |
|
} |
85 |
|
} |
86 |
|
} catch (ParseException e) |
87 |
|
{ |
88 |
|
|
89 |
|
} |
90 |
0 |
return result; |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
@param |
97 |
|
|
98 |
|
@param |
99 |
|
|
100 |
|
@param |
101 |
|
|
102 |
|
|
103 |
|
@return |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
105 |
0 |
protected URL getUrl(String id, Species species, String... type)... |
106 |
|
{ |
107 |
0 |
StringBuilder sb = new StringBuilder(); |
108 |
0 |
sb.append(getDomain()).append("/xrefs/symbol/") |
109 |
|
.append(species.toString()).append("/").append(id) |
110 |
|
.append(CONTENT_TYPE_JSON); |
111 |
0 |
for (String t : type) |
112 |
|
{ |
113 |
0 |
sb.append("&object_type=").append(t); |
114 |
|
} |
115 |
0 |
try |
116 |
|
{ |
117 |
0 |
String url = sb.toString(); |
118 |
0 |
return new URL(url); |
119 |
|
} catch (MalformedURLException e) |
120 |
|
{ |
121 |
0 |
return null; |
122 |
|
} |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
@param |
130 |
|
@return |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 8 |
Complexity Density: 0.42 |
|
132 |
0 |
public List<String> getGeneIds(String identifier)... |
133 |
|
{ |
134 |
0 |
List<String> result = new ArrayList<String>(); |
135 |
0 |
List<String> ids = new ArrayList<String>(); |
136 |
0 |
ids.add(identifier); |
137 |
|
|
138 |
0 |
String[] queries = identifier.split(getAccessionSeparator()); |
139 |
0 |
BufferedReader br = null; |
140 |
0 |
try |
141 |
|
{ |
142 |
0 |
for (String query : queries) |
143 |
|
{ |
144 |
0 |
for (Species taxon : Species.getModelOrganisms()) |
145 |
|
{ |
146 |
0 |
URL url = getUrl(query, taxon, GENE); |
147 |
0 |
if (url != null) |
148 |
|
{ |
149 |
0 |
br = getHttpResponse(url, ids); |
150 |
0 |
if (br != null) |
151 |
|
{ |
152 |
0 |
String geneId = parseSymbolResponse(br); |
153 |
0 |
if (geneId != null && !result.contains(geneId)) |
154 |
|
{ |
155 |
0 |
result.add(geneId); |
156 |
|
} |
157 |
|
} |
158 |
|
} |
159 |
|
} |
160 |
|
} |
161 |
|
} catch (IOException e) |
162 |
|
{ |
163 |
|
|
164 |
|
} finally |
165 |
|
{ |
166 |
0 |
if (br != null) |
167 |
|
{ |
168 |
0 |
try |
169 |
|
{ |
170 |
0 |
br.close(); |
171 |
|
} catch (IOException e) |
172 |
|
{ |
173 |
|
|
174 |
|
} |
175 |
|
} |
176 |
|
} |
177 |
0 |
return result; |
178 |
|
} |
179 |
|
|
180 |
|
} |