Skip to content
Snippets Groups Projects
Commit 5f840e3f authored by Vermaat's avatar Vermaat
Browse files

Entrez dbSNP api suddenly returns other XML structure

git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/trunk@478 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
parent 2a2ccf76
No related branches found
No related tags found
No related merge requests found
...@@ -278,11 +278,17 @@ class Retriever(object) : ...@@ -278,11 +278,17 @@ class Retriever(object) :
response_text = response.read() response_text = response.read()
if response_text == '\n':
# This is apparently what dbSNP returns for non-existing dbSNP id
self._output.addMessage(__file__, 4, 'EENTREZ',
'ID rs%s could not be found in dbSNP.' \
% id)
return []
try: try:
# Parse the output. # Parse the output.
doc = minidom.parseString(response_text) doc = minidom.parseString(response_text)
exchange_set = doc.getElementsByTagName('ExchangeSet') rs = doc.getElementsByTagName('Rs')[0]
rs = exchange_set[0].getElementsByTagName('Rs')
except expat.ExpatError as e: except expat.ExpatError as e:
# Could not parse XML. # Could not parse XML.
self._output.addMessage(__file__, 4, 'EENTREZ', 'Unknown dbSNP ' \ self._output.addMessage(__file__, 4, 'EENTREZ', 'Unknown dbSNP ' \
...@@ -300,29 +306,8 @@ class Retriever(object) : ...@@ -300,29 +306,8 @@ class Retriever(object) :
'Result from dbSNP: %s' % response_text) 'Result from dbSNP: %s' % response_text)
return [] return []
if len(rs) < 1:
# No Rs result element.
text = []
for node in exchange_set[0].childNodes:
if node.nodeType == node.TEXT_NODE:
text.append(node.data)
message = ''.join(text)
if message.find('cannot get document summary') != -1:
# Entrez does not have this rs ID.
self._output.addMessage(__file__, 4, 'EENTREZ',
'ID rs%s could not be found in dbSNP.' \
% id)
else:
# Something else was wrong (print {message} to see more).
self._output.addMessage(__file__, 4, 'EENTREZ',
'Unkown dbSNP error. Got no result ' \
'from dbSNP.')
self._output.addMessage(__file__, -1, 'INFO',
'Message from dbSNP: %s' % message)
return []
snps = [] snps = []
for i in rs[0].getElementsByTagName('hgvs'): for i in rs.getElementsByTagName('hgvs'):
snps.append(i.lastChild.data.encode('utf8')) snps.append(i.lastChild.data.encode('utf8'))
return snps return snps
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment