1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ws.dbsources; |
22 |
|
|
23 |
|
import java.io.InputStream; |
24 |
|
import java.net.URL; |
25 |
|
import java.net.URLConnection; |
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.List; |
28 |
|
import java.util.Locale; |
29 |
|
import java.util.Vector; |
30 |
|
|
31 |
|
import javax.xml.bind.JAXBContext; |
32 |
|
import javax.xml.bind.JAXBElement; |
33 |
|
import javax.xml.bind.JAXBException; |
34 |
|
import javax.xml.stream.FactoryConfigurationError; |
35 |
|
import javax.xml.stream.XMLInputFactory; |
36 |
|
import javax.xml.stream.XMLStreamException; |
37 |
|
import javax.xml.stream.XMLStreamReader; |
38 |
|
|
39 |
|
import com.stevesoft.pat.Regex; |
40 |
|
|
41 |
|
import jalview.bin.Cache; |
42 |
|
import jalview.datamodel.Alignment; |
43 |
|
import jalview.datamodel.AlignmentI; |
44 |
|
import jalview.datamodel.DBRefEntry; |
45 |
|
import jalview.datamodel.DBRefSource; |
46 |
|
import jalview.datamodel.PDBEntry; |
47 |
|
import jalview.datamodel.Sequence; |
48 |
|
import jalview.datamodel.SequenceFeature; |
49 |
|
import jalview.datamodel.SequenceI; |
50 |
|
import jalview.schemes.ResidueProperties; |
51 |
|
import jalview.util.HttpUtils; |
52 |
|
import jalview.util.StringUtils; |
53 |
|
import jalview.ws.seqfetcher.DbSourceProxyImpl; |
54 |
|
import jalview.xml.binding.uniprot.DbReferenceType; |
55 |
|
import jalview.xml.binding.uniprot.Entry; |
56 |
|
import jalview.xml.binding.uniprot.FeatureType; |
57 |
|
import jalview.xml.binding.uniprot.LocationType; |
58 |
|
import jalview.xml.binding.uniprot.PositionType; |
59 |
|
import jalview.xml.binding.uniprot.PropertyType; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
@author |
67 |
|
|
68 |
|
|
|
|
| 0% |
Uncovered Elements: 204 (204) |
Complexity: 53 |
Complexity Density: 0.39 |
|
69 |
|
public class TDBeacons extends DbSourceProxyImpl |
70 |
|
{ |
71 |
|
private static final String DEFAULT_UNIPROT_DOMAIN = "https://www.uniprot.org"; |
72 |
|
|
73 |
|
private static final String BAR_DELIMITER = "|"; |
74 |
|
|
75 |
|
private static final String DEFAULT_THREEDBEACONS_DOMAIN = "https://wwwdev.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons-hub-api/uniprot/summary/"; |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
0 |
public TDBeacons()... |
81 |
|
{ |
82 |
0 |
super(); |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
0 |
private String getDomain()... |
86 |
|
{ |
87 |
0 |
return Cache.getDefault("UNIPROT_DOMAIN", DEFAULT_UNIPROT_DOMAIN); |
88 |
|
|
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
@see |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
0 |
@Override... |
97 |
|
public String getAccessionSeparator() |
98 |
|
{ |
99 |
0 |
return null; |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
@see |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
0 |
@Override... |
108 |
|
public Regex getAccessionValidator() |
109 |
|
{ |
110 |
0 |
return new Regex("([A-Z]+[0-9]+[A-Z0-9]+|[A-Z0-9]+_[A-Z0-9]+)"); |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
@see |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
0 |
@Override... |
119 |
|
public String getDbSource() |
120 |
|
{ |
121 |
0 |
return "3d-beacons"; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@see |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
129 |
0 |
@Override... |
130 |
|
public String getDbVersion() |
131 |
|
{ |
132 |
0 |
return "0"; |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
@see |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 3 |
Complexity Density: 0.17 |
|
140 |
0 |
@Override... |
141 |
|
public AlignmentI getSequenceRecords(String queries) throws Exception |
142 |
|
{ |
143 |
0 |
startQuery(); |
144 |
0 |
try |
145 |
|
{ |
146 |
0 |
queries = queries.toUpperCase(Locale.ROOT).replaceAll( |
147 |
|
"(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", ""); |
148 |
0 |
AlignmentI al = null; |
149 |
|
|
150 |
0 |
String downloadstring = getDomain() + "/uniprot/" + queries + ".xml"; |
151 |
|
|
152 |
|
|
153 |
0 |
URL url = new URL(downloadstring); |
154 |
0 |
URLConnection urlconn = HttpUtils.openConnection(url); |
155 |
0 |
InputStream istr = urlconn.getInputStream(); |
156 |
0 |
List<Entry> entries = getUniprotEntries(istr); |
157 |
0 |
if (entries != null) |
158 |
|
{ |
159 |
0 |
List<SequenceI> seqs = new ArrayList<>(); |
160 |
0 |
for (Entry entry : entries) |
161 |
|
{ |
162 |
0 |
seqs.add(uniprotEntryToSequence(entry)); |
163 |
|
} |
164 |
0 |
al = new Alignment(seqs.toArray(new SequenceI[seqs.size()])); |
165 |
|
} |
166 |
|
|
167 |
0 |
stopQuery(); |
168 |
0 |
return al; |
169 |
|
} catch (Exception e) |
170 |
|
{ |
171 |
0 |
throw (e); |
172 |
|
} finally |
173 |
|
{ |
174 |
0 |
stopQuery(); |
175 |
|
} |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
@param |
182 |
|
@return |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 61 (61) |
Complexity: 11 |
Complexity Density: 0.24 |
|
184 |
0 |
SequenceI uniprotEntryToSequence(Entry entry)... |
185 |
|
{ |
186 |
0 |
String id = getUniprotEntryId(entry); |
187 |
|
|
188 |
|
|
189 |
|
|
190 |
0 |
String seqString = entry.getSequence().getValue().replaceAll("\\s*", |
191 |
|
""); |
192 |
|
|
193 |
0 |
SequenceI sequence = new Sequence(id, seqString); |
194 |
0 |
sequence.setDescription(getUniprotEntryDescription(entry)); |
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
0 |
final String dbVersion = getDbVersion(); |
200 |
0 |
List<DBRefEntry> dbRefs = new ArrayList<>(); |
201 |
0 |
for (String accessionId : entry.getAccession()) |
202 |
|
{ |
203 |
0 |
DBRefEntry dbRef = new DBRefEntry(DBRefSource.UNIPROT, dbVersion, |
204 |
|
accessionId); |
205 |
0 |
dbRefs.add(dbRef); |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
0 |
Vector<PDBEntry> pdbRefs = new Vector<>(); |
215 |
0 |
for (DbReferenceType dbref : entry.getDbReference()) |
216 |
|
{ |
217 |
0 |
String type = dbref.getType(); |
218 |
0 |
DBRefEntry dbr = new DBRefEntry(type, |
219 |
|
DBRefSource.UNIPROT + ":" + dbVersion, dbref.getId()); |
220 |
0 |
dbRefs.add(dbr); |
221 |
0 |
if ("PDB".equals(type)) |
222 |
|
{ |
223 |
0 |
pdbRefs.add(new PDBEntry(dbr)); |
224 |
|
} |
225 |
0 |
if ("EMBL".equals(type)) |
226 |
|
{ |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
0 |
String cdsId = getProperty(dbref.getProperty(), |
235 |
|
"protein sequence ID"); |
236 |
0 |
if (cdsId != null && cdsId.trim().length() > 0) |
237 |
|
{ |
238 |
|
|
239 |
0 |
String[] vrs = cdsId.split("\\."); |
240 |
0 |
String version = vrs.length > 1 ? vrs[1] |
241 |
|
: DBRefSource.UNIPROT + ":" + dbVersion; |
242 |
0 |
dbr = new DBRefEntry(DBRefSource.EMBLCDS, version, vrs[0]); |
243 |
0 |
dbRefs.add(dbr); |
244 |
|
} |
245 |
|
} |
246 |
0 |
if ("Ensembl".equals(type)) |
247 |
|
{ |
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
0 |
String cdsId = getProperty(dbref.getProperty(), |
257 |
|
"protein sequence ID"); |
258 |
0 |
if (cdsId != null && cdsId.trim().length() > 0) |
259 |
|
{ |
260 |
0 |
dbr = new DBRefEntry(DBRefSource.ENSEMBL, |
261 |
|
DBRefSource.UNIPROT + ":" + dbVersion, cdsId.trim()); |
262 |
0 |
dbRefs.add(dbr); |
263 |
|
} |
264 |
|
} |
265 |
|
} |
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
0 |
sequence.setPDBId(pdbRefs); |
271 |
0 |
if (entry.getFeature() != null) |
272 |
|
{ |
273 |
0 |
for (FeatureType uf : entry.getFeature()) |
274 |
|
{ |
275 |
0 |
LocationType location = uf.getLocation(); |
276 |
0 |
int start = 0; |
277 |
0 |
int end = 0; |
278 |
0 |
if (location.getPosition() != null) |
279 |
|
{ |
280 |
0 |
start = location.getPosition().getPosition().intValue(); |
281 |
0 |
end = start; |
282 |
|
} |
283 |
|
else |
284 |
|
{ |
285 |
0 |
start = location.getBegin().getPosition().intValue(); |
286 |
0 |
end = location.getEnd().getPosition().intValue(); |
287 |
|
} |
288 |
0 |
SequenceFeature sf = new SequenceFeature(uf.getType(), |
289 |
|
getDescription(uf), start, end, "Uniprot"); |
290 |
0 |
sf.setStatus(uf.getStatus()); |
291 |
0 |
sequence.addSequenceFeature(sf); |
292 |
|
} |
293 |
|
} |
294 |
0 |
for (DBRefEntry dbr : dbRefs) |
295 |
|
{ |
296 |
0 |
sequence.addDBRef(dbr); |
297 |
|
} |
298 |
0 |
return sequence; |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
@param |
305 |
|
@return |
306 |
|
|
|
|
| 0% |
Uncovered Elements: 56 (56) |
Complexity: 15 |
Complexity Density: 0.44 |
|
307 |
0 |
static String getDescription(FeatureType feature)... |
308 |
|
{ |
309 |
0 |
String orig = feature.getOriginal(); |
310 |
0 |
List<String> variants = feature.getVariation(); |
311 |
0 |
StringBuilder sb = new StringBuilder(); |
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
0 |
boolean asHtml = false; |
319 |
0 |
if (orig != null && !orig.isEmpty() && variants != null |
320 |
|
&& !variants.isEmpty()) |
321 |
|
{ |
322 |
0 |
int p = 0; |
323 |
0 |
for (String var : variants) |
324 |
|
{ |
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
0 |
sb.append("p."); |
331 |
0 |
if (orig.length() < 4) |
332 |
|
{ |
333 |
0 |
for (int c = 0, clen = orig.length(); c < clen; c++) |
334 |
|
{ |
335 |
0 |
char origchar = orig.charAt(c); |
336 |
0 |
String orig3 = ResidueProperties.aa2Triplet.get("" + origchar); |
337 |
0 |
sb.append(orig3 == null ? origchar |
338 |
|
: StringUtils.toSentenceCase(orig3)); |
339 |
|
} |
340 |
|
} |
341 |
|
else |
342 |
|
{ |
343 |
0 |
sb.append(orig); |
344 |
|
} |
345 |
|
|
346 |
0 |
LocationType location = feature.getLocation(); |
347 |
0 |
PositionType start = location.getPosition() == null |
348 |
|
? location.getBegin() |
349 |
|
: location.getPosition(); |
350 |
0 |
sb.append(Integer.toString(start.getPosition().intValue())); |
351 |
|
|
352 |
0 |
if (var.length() < 4) |
353 |
|
{ |
354 |
0 |
for (int c = 0, clen = var.length(); c < clen; c++) |
355 |
|
{ |
356 |
0 |
char varchar = var.charAt(c); |
357 |
0 |
String var3 = ResidueProperties.aa2Triplet.get("" + varchar); |
358 |
|
|
359 |
0 |
sb.append(var3 != null ? StringUtils.toSentenceCase(var3) |
360 |
|
: "" + varchar); |
361 |
|
} |
362 |
|
} |
363 |
|
else |
364 |
|
{ |
365 |
0 |
sb.append(var); |
366 |
|
} |
367 |
0 |
if (++p != variants.size()) |
368 |
|
{ |
369 |
0 |
sb.append("<br/> "); |
370 |
0 |
asHtml = true; |
371 |
|
} |
372 |
|
else |
373 |
|
{ |
374 |
0 |
sb.append(" "); |
375 |
|
} |
376 |
|
} |
377 |
|
} |
378 |
0 |
String description = feature.getDescription(); |
379 |
0 |
if (description != null) |
380 |
|
{ |
381 |
0 |
sb.append(description); |
382 |
|
} |
383 |
0 |
if (asHtml) |
384 |
|
{ |
385 |
0 |
sb.insert(0, "<html>"); |
386 |
0 |
sb.append("</html>"); |
387 |
|
} |
388 |
|
|
389 |
0 |
return sb.toString(); |
390 |
|
} |
391 |
|
|
392 |
|
|
393 |
|
|
394 |
|
|
395 |
|
|
396 |
|
@param |
397 |
|
@param |
398 |
|
@return |
399 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
400 |
0 |
static String getProperty(List<PropertyType> properties, String key)... |
401 |
|
{ |
402 |
0 |
String value = null; |
403 |
0 |
if (properties != null) |
404 |
|
{ |
405 |
0 |
for (PropertyType prop : properties) |
406 |
|
{ |
407 |
0 |
if (key.equals(prop.getType())) |
408 |
|
{ |
409 |
0 |
value = prop.getValue(); |
410 |
0 |
break; |
411 |
|
} |
412 |
|
} |
413 |
|
} |
414 |
0 |
return value; |
415 |
|
} |
416 |
|
|
417 |
|
|
418 |
|
|
419 |
|
|
420 |
|
@param |
421 |
|
@return |
422 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
423 |
0 |
static String getUniprotEntryDescription(Entry entry)... |
424 |
|
{ |
425 |
0 |
String desc = ""; |
426 |
0 |
if (entry.getProtein() != null |
427 |
|
&& entry.getProtein().getRecommendedName() != null) |
428 |
|
{ |
429 |
|
|
430 |
0 |
desc = entry.getProtein().getRecommendedName().getFullName() |
431 |
|
.getValue(); |
432 |
|
} |
433 |
0 |
return desc; |
434 |
|
} |
435 |
|
|
436 |
|
|
437 |
|
|
438 |
|
|
439 |
|
|
440 |
|
@param |
441 |
|
@return |
442 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
443 |
0 |
static String getUniprotEntryId(Entry entry)... |
444 |
|
{ |
445 |
0 |
StringBuilder name = new StringBuilder(32); |
446 |
0 |
for (String n : entry.getName()) |
447 |
|
{ |
448 |
0 |
if (name.length() > 0) |
449 |
|
{ |
450 |
0 |
name.append(BAR_DELIMITER); |
451 |
|
} |
452 |
0 |
name.append(n); |
453 |
|
} |
454 |
0 |
return name.toString(); |
455 |
|
} |
456 |
|
|
457 |
|
|
458 |
|
|
459 |
|
|
460 |
|
@see |
461 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
462 |
0 |
@Override... |
463 |
|
public boolean isValidReference(String accession) |
464 |
|
{ |
465 |
|
|
466 |
0 |
return (accession == null || accession.length() < 2) ? false |
467 |
|
: getAccessionValidator().search(accession); |
468 |
|
} |
469 |
|
|
470 |
|
|
471 |
|
|
472 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
473 |
0 |
@Override... |
474 |
|
public String getTestQuery() |
475 |
|
{ |
476 |
0 |
return "P00340"; |
477 |
|
} |
478 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
479 |
0 |
@Override... |
480 |
|
public String getDbName() |
481 |
|
{ |
482 |
0 |
return "Uniprot"; |
483 |
|
} |
484 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
485 |
0 |
@Override... |
486 |
|
public int getTier() |
487 |
|
{ |
488 |
0 |
return 0; |
489 |
|
} |
490 |
|
|
491 |
|
|
492 |
|
|
493 |
|
|
494 |
|
|
495 |
|
|
496 |
|
@param |
497 |
|
@return |
498 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.36 |
|
499 |
0 |
public List<Entry> getUniprotEntries(InputStream is)... |
500 |
|
{ |
501 |
0 |
List<Entry> entries = null; |
502 |
0 |
try |
503 |
|
{ |
504 |
0 |
JAXBContext jc = JAXBContext |
505 |
|
.newInstance("jalview.xml.binding.uniprot"); |
506 |
0 |
XMLStreamReader streamReader = XMLInputFactory.newInstance() |
507 |
|
.createXMLStreamReader(is); |
508 |
0 |
javax.xml.bind.Unmarshaller um = jc.createUnmarshaller(); |
509 |
0 |
JAXBElement<jalview.xml.binding.uniprot.Uniprot> uniprotElement = um |
510 |
|
.unmarshal(streamReader, |
511 |
|
jalview.xml.binding.uniprot.Uniprot.class); |
512 |
0 |
jalview.xml.binding.uniprot.Uniprot uniprot = uniprotElement |
513 |
|
.getValue(); |
514 |
|
|
515 |
0 |
if (uniprot != null && !uniprot.getEntry().isEmpty()) |
516 |
|
{ |
517 |
0 |
entries = uniprot.getEntry(); |
518 |
|
} |
519 |
|
} catch (JAXBException | XMLStreamException |
520 |
|
| FactoryConfigurationError e) |
521 |
|
{ |
522 |
0 |
e.printStackTrace(); |
523 |
|
} |
524 |
0 |
return entries; |
525 |
|
} |
526 |
|
} |