Skip to content
Snippets Groups Projects
Commit 6f375a5b authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add namespace prefixes to parse uniprot XML (fixes #4)

parent 740d325d
No related branches found
No related tags found
No related merge requests found
...@@ -37,15 +37,16 @@ def get_epo_info(patent_number): ...@@ -37,15 +37,16 @@ def get_epo_info(patent_number):
def get_uniprot_info(uniprot_id): def get_uniprot_info(uniprot_id):
uniprot_client = UniProt() uniprot_client = UniProt()
ns = {'u':'http://uniprot.org/uniprot'}
resp = uniprot_client.retrieve(uniprot_id) 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 recommended_name = resp.root.findall('u:entry/u:protein/u:recommendedName/u:fullName', ns)[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'] organism = resp.root.findall('u:entry/u:organism/u:dbReference[@type="NCBI Taxonomy"]', ns)[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 gene = resp.root.findall('u:entry/u:gene/u:name[@type="primary"]', ns)[0].text
entry_name = resp.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}name')[0].text entry_name = resp.root.findall('u:entry/u:name', ns)[0].text
go_els = resp.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}dbReference[@type="GO"]') go_els = resp.root.findall('u:entry/u:dbReference[@type="GO"]', ns)
molecular_functions = [] molecular_functions = []
for go_el in go_els: 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:': if term_property_value[0:2]=='F:':
molecular_functions.append('GO_'+go_el.attrib['id'][3:]) molecular_functions.append('GO_'+go_el.attrib['id'][3:])
return {'recommended_name': recommended_name, return {'recommended_name': recommended_name,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment