From 6f375a5b48fe7743f3a5f2e50e1ed7cd0bb2ac3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20=20MENAGER?= <herve.menager@pasteur.fr> Date: Tue, 28 Mar 2017 09:00:11 +0200 Subject: [PATCH] add namespace prefixes to parse uniprot XML (fixes #4) --- ippisite/ippidb/ws.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ippisite/ippidb/ws.py b/ippisite/ippidb/ws.py index f52d2e76..768d0afb 100644 --- a/ippisite/ippidb/ws.py +++ b/ippisite/ippidb/ws.py @@ -37,15 +37,16 @@ def get_epo_info(patent_number): def get_uniprot_info(uniprot_id): uniprot_client = UniProt() + ns = {'u':'http://uniprot.org/uniprot'} resp = uniprot_client.retrieve(uniprot_id) - recommended_name = resp.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}protein/{http://uniprot.org/uniprot}recommendedName/{http://uniprot.org/uniprot}fullName')[0].text - organism = resp.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}organism/{http://uniprot.org/uniprot}dbReference[@type="NCBI Taxonomy"]')[0].attrib['id'] - gene = resp.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}gene/{http://uniprot.org/uniprot}name[@type="primary"]')[0].text - entry_name = resp.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}name')[0].text - go_els = resp.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}dbReference[@type="GO"]') + recommended_name = resp.root.findall('u:entry/u:protein/u:recommendedName/u:fullName', ns)[0].text + organism = resp.root.findall('u:entry/u:organism/u:dbReference[@type="NCBI Taxonomy"]', ns)[0].attrib['id'] + gene = resp.root.findall('u:entry/u:gene/u:name[@type="primary"]', ns)[0].text + entry_name = resp.root.findall('u:entry/u:name', ns)[0].text + go_els = resp.root.findall('u:entry/u:dbReference[@type="GO"]', ns) molecular_functions = [] for go_el in go_els: - term_property_value = go_el.findall('{http://uniprot.org/uniprot}property[@type="term"]')[0].attrib['value'] + term_property_value = go_el.findall('u:property[@type="term"]', ns)[0].attrib['value'] if term_property_value[0:2]=='F:': molecular_functions.append('GO_'+go_el.attrib['id'][3:]) return {'recommended_name': recommended_name, -- GitLab