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