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 |
|
import jalview.util.JSONUtils; |
27 |
|
|
28 |
|
import java.io.BufferedReader; |
29 |
|
import java.io.IOException; |
30 |
|
import java.net.MalformedURLException; |
31 |
|
import java.net.URL; |
32 |
|
import java.util.ArrayList; |
33 |
|
import java.util.Iterator; |
34 |
|
import java.util.List; |
35 |
|
import java.util.Map; |
36 |
|
|
37 |
|
import org.json.simple.parser.ParseException; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
@author |
44 |
|
@see |
45 |
|
|
|
|
| 76.3% |
Uncovered Elements: 9 (38) |
Complexity: 14 |
Complexity Density: 0.54 |
|
46 |
|
class EnsemblXref extends EnsemblRestClient |
47 |
|
{ |
48 |
|
|
49 |
|
private static final String GO_GENE_ONTOLOGY = "GO"; |
50 |
|
|
51 |
|
private String dbName = "ENSEMBL (xref)"; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@param |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
58 |
1 |
public EnsemblXref(String d, String dbSource, String version)... |
59 |
|
{ |
60 |
1 |
super(d); |
61 |
1 |
dbName = dbSource; |
62 |
1 |
xrefVersion = dbSource + ":" + version; |
63 |
|
|
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0 |
@Override... |
67 |
|
public String getDbName() |
68 |
|
{ |
69 |
0 |
return dbName; |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
0 |
@Override... |
73 |
|
public AlignmentI getSequenceRecords(String queries) throws Exception |
74 |
|
{ |
75 |
0 |
return null; |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
0 |
@Override... |
79 |
|
protected URL getUrl(List<String> ids) throws MalformedURLException |
80 |
|
{ |
81 |
0 |
return getUrl(ids.get(0)); |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
0 |
@Override... |
85 |
|
protected boolean useGetRequest() |
86 |
|
{ |
87 |
0 |
return true; |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
@param |
98 |
|
|
99 |
|
@return |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 6 |
Complexity Density: 0.43 |
|
101 |
1 |
@SuppressWarnings("unchecked")... |
102 |
|
public List<DBRefEntry> getCrossReferences(String identifier) |
103 |
|
{ |
104 |
1 |
List<DBRefEntry> result = new ArrayList<>(); |
105 |
1 |
List<String> ids = new ArrayList<>(); |
106 |
1 |
ids.add(identifier); |
107 |
|
|
108 |
1 |
try |
109 |
|
{ |
110 |
1 |
Iterator<Object> rvals = (Iterator<Object>) getJSON( |
111 |
|
getUrl(identifier), ids, -1, MODE_ITERATOR, null); |
112 |
4 |
while (rvals.hasNext()) |
113 |
|
{ |
114 |
3 |
Map<String, Object> val = (Map<String, Object>) rvals.next(); |
115 |
3 |
String db = val.get("dbname").toString(); |
116 |
3 |
String id = val.get("primary_id").toString(); |
117 |
3 |
if (db != null && id != null && !GO_GENE_ONTOLOGY.equals(db)) |
118 |
|
{ |
119 |
2 |
db = DBRefUtils.getCanonicalName(db); |
120 |
2 |
DBRefEntry dbref = new DBRefEntry(db, getXRefVersion(), id); |
121 |
2 |
result.add(dbref); |
122 |
|
} |
123 |
|
} |
124 |
|
} catch (ParseException | IOException e) |
125 |
|
{ |
126 |
|
|
127 |
|
} |
128 |
1 |
return result; |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
private String xrefVersion = "ENSEMBL:0"; |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
@return |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
2 |
public String getXRefVersion()... |
157 |
|
{ |
158 |
2 |
return xrefVersion; |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
@param |
167 |
|
@return |
168 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
169 |
1 |
protected URL getUrl(String identifier)... |
170 |
|
{ |
171 |
1 |
String url = getDomain() + "/xrefs/id/" + identifier + CONTENT_TYPE_JSON |
172 |
|
+ "&all_levels=1"; |
173 |
1 |
try |
174 |
|
{ |
175 |
1 |
return new URL(url); |
176 |
|
} catch (MalformedURLException e) |
177 |
|
{ |
178 |
0 |
return null; |
179 |
|
} |
180 |
|
} |
181 |
|
|
182 |
|
} |