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 |
|
|
|
|
| 0% |
Uncovered Elements: 38 (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 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
58 |
0 |
public EnsemblXref(String d, String dbSource, String version)... |
59 |
|
{ |
60 |
0 |
super(d); |
61 |
0 |
dbName = dbSource; |
62 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 6 |
Complexity Density: 0.43 |
|
101 |
0 |
@SuppressWarnings("unchecked")... |
102 |
|
public List<DBRefEntry> getCrossReferences(String identifier) |
103 |
|
{ |
104 |
0 |
List<DBRefEntry> result = new ArrayList<>(); |
105 |
0 |
List<String> ids = new ArrayList<>(); |
106 |
0 |
ids.add(identifier); |
107 |
|
|
108 |
0 |
try |
109 |
|
{ |
110 |
0 |
Iterator<Object> rvals = (Iterator<Object>) getJSON( |
111 |
|
getUrl(identifier), ids, -1, MODE_ITERATOR, null); |
112 |
0 |
while (rvals.hasNext()) |
113 |
|
{ |
114 |
0 |
Map<String, Object> val = (Map<String, Object>) rvals.next(); |
115 |
0 |
String db = val.get("dbname").toString(); |
116 |
0 |
String id = val.get("primary_id").toString(); |
117 |
0 |
if (db != null && id != null && !GO_GENE_ONTOLOGY.equals(db)) |
118 |
|
{ |
119 |
0 |
db = DBRefUtils.getCanonicalName(db); |
120 |
0 |
DBRefEntry dbref = new DBRefEntry(db, getXRefVersion(), id); |
121 |
0 |
result.add(dbref); |
122 |
|
} |
123 |
|
} |
124 |
|
} catch (ParseException | IOException e) |
125 |
|
{ |
126 |
|
|
127 |
|
} |
128 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
0 |
public String getXRefVersion()... |
157 |
|
{ |
158 |
0 |
return xrefVersion; |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
@param |
167 |
|
@return |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
169 |
0 |
protected URL getUrl(String identifier)... |
170 |
|
{ |
171 |
0 |
String url = getDomain() + "/xrefs/id/" + identifier + CONTENT_TYPE_JSON |
172 |
|
+ "&all_levels=1"; |
173 |
0 |
try |
174 |
|
{ |
175 |
0 |
return new URL(url); |
176 |
|
} catch (MalformedURLException e) |
177 |
|
{ |
178 |
0 |
return null; |
179 |
|
} |
180 |
|
} |
181 |
|
|
182 |
|
} |