Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SOaAS
psot.repository
Commits
a0fdafcd
Commit
a0fdafcd
authored
Jan 24, 2018
by
Lukas Jelonek
Browse files
Replace single document handling with dictionary documents handling for dbxref resolver
parent
3b7d874f
Changes
3
Hide whitespace changes
Inline
Side-by-side
psot/dbxref.py
View file @
a0fdafcd
def
dbxrefs_from
(
document
):
def
dbxrefs_from_documents
(
documents
):
refs
=
set
()
for
key
in
documents
:
refs
.
update
(
dbxrefs_from_document
(
documents
[
key
]))
return
refs
def
dbxrefs_from_document
(
document
):
'''finds all dbxrefs in the document and returns a list of ids'''
refs
=
[]
for
c
in
document
[
'computations'
]:
...
...
@@ -7,7 +13,11 @@ def dbxrefs_from(document):
refs
.
append
(
r
[
'target'
][
'dbxref'
])
return
set
(
refs
)
def
combine
(
document
,
informations
):
def
combine_with_documents
(
documents
,
informations
):
for
k
in
documents
:
combine_with_document
(
documents
[
k
],
informations
)
def
combine_with_document
(
document
,
informations
):
'''adds an information tag for each result that references a dbxref'''
for
c
in
document
[
'computations'
]:
for
r
in
c
[
'results'
]:
...
...
psot/scripts/resolve_dbxrefs.py
View file @
a0fdafcd
...
...
@@ -15,11 +15,11 @@ args = parser.parse_args()
with
open
(
args
.
input
,
'r'
)
as
json_file
:
j
=
json
.
load
(
json_file
)
# extract all dbxrefs
dbxrefs
=
dbxref
.
dbxrefs_from
(
j
)
dbxrefs
=
dbxref
.
dbxrefs_from
_documents
(
j
)
# retrieve information for dbxrefs
entries
=
retrieve
(
convert_to_dbxrefs
(
sorted
(
dbxrefs
)))
# add information field to results
dbxref
.
combine
(
j
,
entries
)
dbxref
.
combine
_with_documents
(
j
,
entries
)
# write updated json
with
open
(
args
.
output
,
'w'
)
as
o
:
json
.
dump
(
j
,
o
)
...
...
tests/test_resolve_dbxrefs.py
View file @
a0fdafcd
...
...
@@ -25,7 +25,7 @@ class TestDbXrefs(unittest.TestCase):
'text'
:
'some text'
}
]
dbxref
.
combine
(
test_data
,
test_information
)
dbxref
.
combine
_with_document
(
test_data
,
test_information
)
self
.
assertTrue
(
'text'
in
test_data
[
'computations'
][
0
][
'results'
][
0
][
'informations'
])
self
.
assertEqual
(
test_data
[
'computations'
][
0
][
'results'
][
0
][
'informations'
][
'text'
],
'some text'
)
...
...
@@ -36,7 +36,7 @@ class TestDbXrefs(unittest.TestCase):
with
open
(
test_file
,
'r'
)
as
f
:
data
=
json
.
load
(
f
)
# extract dbxrefs
dbxrefs
=
dbxref
.
dbxrefs_from
(
data
)
dbxrefs
=
dbxref
.
dbxrefs_from
_document
(
data
)
# test if all expected dbxrefs were found
self
.
assertEqual
(
dbxrefs
,
set
([
"PFAM:PF01048.19"
,
...
...
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