1 |
|
package jalview.ext.ensembl; |
2 |
|
|
3 |
|
import jalview.datamodel.AlignmentI; |
4 |
|
import jalview.datamodel.DBRefSource; |
5 |
|
|
6 |
|
import java.io.BufferedReader; |
7 |
|
import java.io.IOException; |
8 |
|
import java.net.MalformedURLException; |
9 |
|
import java.net.URL; |
10 |
|
import java.util.HashMap; |
11 |
|
import java.util.Iterator; |
12 |
|
import java.util.List; |
13 |
|
import java.util.Map; |
14 |
|
import java.util.Set; |
15 |
|
|
16 |
|
import org.json.simple.JSONArray; |
17 |
|
import org.json.simple.parser.JSONParser; |
18 |
|
import org.json.simple.parser.ParseException; |
19 |
|
|
|
|
| 0% |
Uncovered Elements: 52 (52) |
Complexity: 19 |
Complexity Density: 0.61 |
|
20 |
|
public class EnsemblInfo extends EnsemblRestClient |
21 |
|
{ |
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
private static Map<String, String> divisions; |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
0 |
@Override... |
41 |
|
public String getDbName() |
42 |
|
{ |
43 |
0 |
return "ENSEMBL"; |
44 |
|
} |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
0 |
@Override... |
47 |
|
public AlignmentI getSequenceRecords(String queries) throws Exception |
48 |
|
{ |
49 |
0 |
return null; |
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
0 |
@Override... |
53 |
|
protected URL getUrl(List<String> ids) throws MalformedURLException |
54 |
|
{ |
55 |
0 |
return null; |
56 |
|
} |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
0 |
@Override... |
59 |
|
protected boolean useGetRequest() |
60 |
|
{ |
61 |
0 |
return true; |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0 |
@Override... |
65 |
|
protected String getRequestMimeType(boolean multipleIds) |
66 |
|
{ |
67 |
0 |
return "application/json"; |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0 |
@Override... |
71 |
|
protected String getResponseMimeType() |
72 |
|
{ |
73 |
0 |
return "application/json"; |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@param |
82 |
|
@return |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
84 |
0 |
public String getDomain(String division)... |
85 |
|
{ |
86 |
0 |
if (divisions == null) |
87 |
|
{ |
88 |
0 |
fetchDivisions(); |
89 |
|
} |
90 |
0 |
return divisions.get(division.toUpperCase()); |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.45 |
|
97 |
0 |
void fetchDivisions()... |
98 |
|
{ |
99 |
0 |
divisions = new HashMap<>(); |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
0 |
divisions.put(DBRefSource.ENSEMBL.toUpperCase(), ensemblDomain); |
105 |
|
|
106 |
0 |
BufferedReader br = null; |
107 |
0 |
try |
108 |
|
{ |
109 |
0 |
URL url = getDivisionsUrl(ensemblGenomesDomain); |
110 |
0 |
if (url != null) |
111 |
|
{ |
112 |
0 |
br = getHttpResponse(url, null); |
113 |
|
} |
114 |
0 |
parseResponse(br, ensemblGenomesDomain); |
115 |
|
} catch (IOException e) |
116 |
|
{ |
117 |
|
|
118 |
|
} finally |
119 |
|
{ |
120 |
0 |
if (br != null) |
121 |
|
{ |
122 |
0 |
try |
123 |
|
{ |
124 |
0 |
br.close(); |
125 |
|
} catch (IOException e) |
126 |
|
{ |
127 |
|
|
128 |
|
} |
129 |
|
} |
130 |
|
} |
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
@param |
137 |
|
@param |
138 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
139 |
0 |
void parseResponse(BufferedReader br, String domain)... |
140 |
|
{ |
141 |
0 |
JSONParser jp = new JSONParser(); |
142 |
|
|
143 |
0 |
try |
144 |
|
{ |
145 |
0 |
JSONArray parsed = (JSONArray) jp.parse(br); |
146 |
|
|
147 |
0 |
Iterator rvals = parsed.iterator(); |
148 |
0 |
while (rvals.hasNext()) |
149 |
|
{ |
150 |
0 |
String division = rvals.next().toString(); |
151 |
0 |
divisions.put(division.toUpperCase(), domain); |
152 |
|
} |
153 |
|
} catch (IOException | ParseException | NumberFormatException e) |
154 |
|
{ |
155 |
|
|
156 |
|
} |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
@param |
162 |
|
|
163 |
|
@return |
164 |
|
@throws |
165 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
0 |
URL getDivisionsUrl(String domain) throws MalformedURLException... |
167 |
|
{ |
168 |
0 |
return new URL(domain |
169 |
|
+ "/info/divisions?content-type=application/json"); |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
@return |
176 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
177 |
0 |
public Set<String> getDivisions() {... |
178 |
0 |
if (divisions == null) |
179 |
|
{ |
180 |
0 |
fetchDivisions(); |
181 |
|
} |
182 |
|
|
183 |
0 |
return divisions.keySet(); |
184 |
|
} |
185 |
|
} |