Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SOaAS
dbxref
Commits
fce0ffe2
Commit
fce0ffe2
authored
May 20, 2019
by
Lukas Jelonek
Browse files
Fix bug: dbxref crashes when a pfam entry is returned as html
parent
865554e1
Changes
2
Show whitespace changes
Inline
Side-by-side
dbxref/retrieve/pfam.py
View file @
fce0ffe2
...
...
@@ -2,6 +2,7 @@
import
dbxref.resolver
import
requests
import
xml.etree.ElementTree
as
ET
from
xml.etree.ElementTree
import
ParseError
import
logging
import
json
import
argparse
...
...
@@ -35,11 +36,12 @@ def retrieve(dbxrefs, basic=True, annotation=True):
logger
.
debug
(
'URL: %s'
,
xml_url
)
r
=
requests
.
get
(
xml_url
)
logger
.
debug
(
'Content: %s'
,
r
.
text
)
root
=
ET
.
fromstring
(
r
.
text
)
output
=
{
'id'
:
entry
[
'dbxref'
]}
try
:
root
=
ET
.
fromstring
(
r
.
text
)
tree
=
str
(
ET
.
tostring
(
root
))
if
'<error>'
in
tree
:
output
[
'message'
]
=
tree
[
tree
.
find
(
'<error>'
)
+
7
:
tree
.
rfind
(
'</error>'
)]
...
...
@@ -52,7 +54,7 @@ def retrieve(dbxrefs, basic=True, annotation=True):
except
(
KeyError
,
AttributeError
)
as
e
:
logger
.
warn
(
'Error in retrieving %s'
,
str
(
entry
))
raise
except
RuntimeError
as
e
:
except
(
ParseError
,
RuntimeError
)
as
e
:
output
[
'message'
]
=
'an error occurred'
try
:
html
=
HTML
.
document_fromstring
(
r
.
text
.
replace
(
'
\n
'
,
' '
))
...
...
tests/test_pfam.py
View file @
fce0ffe2
...
...
@@ -8,3 +8,11 @@ class TestPfam(unittest.TestCase):
documents
=
pfam
.
retrieve
([{
'db'
:
'PFAM'
,
'id'
:
'PF00083.23'
}])
# this test failed due to an error due to missing None handling,
# so no assertions here. Once fixed. this should suffice
def
test_renamed_family
(
self
):
'''regression test for missing comment in pfam entry'''
documents
=
pfam
.
retrieve
([{
'db'
:
'PFAM'
,
'id'
:
'Tiny_TM_bacill'
}])
# this test failed due to a redirect when a family was renamed
# unfortunately the redirect was not encoded in http headers, but in
# html markup (<meta http-equiv="Refresh" content="5; URL=/family/PF09680" />)
# so no assertions here. Once fixed. this should suffice
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment