Commit 51f84a07 authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Fix bug: uniprot handler has problems with position tag

parent f05f4c7f
...@@ -58,8 +58,10 @@ def retrieve(dbxrefs, basic=True, sequence=True, organism=True, annotation=True, ...@@ -58,8 +58,10 @@ def retrieve(dbxrefs, basic=True, sequence=True, organism=True, annotation=True,
output.update(read_annotation(child)) output.update(read_annotation(child))
if features: if features:
output['features'] = read_features(child) output['features'] = read_features(child)
except KeyError:
logger.warn('Error in retrieving %s', str(entry))
raise
except RuntimeError as e: except RuntimeError as e:
print(e.message)
output['message'] = 'an error occurred' output['message'] = 'an error occurred'
try: try:
html = HTML.document_fromstring(r.text.replace('\n', ' ')) html = HTML.document_fromstring(r.text.replace('\n', ' '))
...@@ -166,8 +168,17 @@ def read_features(entry): ...@@ -166,8 +168,17 @@ def read_features(entry):
if f.find('uniprot:location', ns).find('uniprot:position', ns) is not None: if f.find('uniprot:location', ns).find('uniprot:position', ns) is not None:
feature['position'] = f.find('uniprot:location', ns).find('uniprot:position', ns).attrib['position'] feature['position'] = f.find('uniprot:location', ns).find('uniprot:position', ns).attrib['position']
else: else:
feature['begin'] = f.find('uniprot:location', ns).find('uniprot:begin', ns).attrib['position'] begin = f.find('uniprot:location', ns).find('uniprot:begin', ns)
feature['end'] = f.find('uniprot:location', ns).find('uniprot:end', ns).attrib['position'] if 'position' in begin.attrib:
feature['begin'] = begin.attrib['position']
else:
feature['begin'] = begin.attrib['status']
end = f.find('uniprot:location', ns).find('uniprot:end', ns)
if 'position' in end.attrib:
feature['end'] = end.attrib['position']
else:
feature['end'] = end.attrib['status']
features.append (feature) features.append (feature)
return features return features
......
import unittest
from dbxref.retrieve import uniprot
class TestPfam(unittest.TestCase):
def test_no_position(self):
'''regression test for missing position parameter in uniprot entry'''
documents = uniprot.retrieve([{'db': 'UniProtKB/Swiss-Prot', 'id': 'P0CM58'}])
# this test failed due to an error due to missing None handling,
# so no assertions here. Once fixed. this should suffice
Markdown is supported
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