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
dbxref
Commits
f4475346
Commit
f4475346
authored
Dec 04, 2017
by
lmueller
Browse files
modefied retriever.py to use retrieve function external
parent
3826d12b
Changes
3
Hide whitespace changes
Inline
Side-by-side
dbxref/retriever.py
View file @
f4475346
...
...
@@ -8,7 +8,7 @@ import json
providers
=
load_providers
()
def
retrieve
(
strings
):
def
retrieve
(
strings
,
location
=
''
):
dbxrefs
=
list
(
map
(
convert_string_to_dbxref
,
strings
))
sorted
(
dbxrefs
,
key
=
lambda
x
:
x
[
'db'
])
results
=
[]
...
...
@@ -17,22 +17,23 @@ def retrieve(strings):
provider
=
providers
[
key
]
logger
.
debug
(
'{0} is supported'
.
format
(
key
))
if
provider
[
'retriever'
][
'type'
]
==
'external'
:
retrieved
=
load_with_external_provider
(
provider
,
list
(
dbxrefs
))
retrieved
=
load_with_external_provider
(
provider
,
list
(
dbxrefs
)
,
location
)
results
.
extend
(
retrieved
)
else
:
raise
Exception
(
'Unknown retriever type'
,
provider
[
'retriever'
][
'type'
])
else
:
logger
.
debug
(
'{0} is not supported'
.
format
(
key
))
results
.
extend
(
map
(
lambda
x
:
{
'dbxref'
:
toString
(
x
),
'status'
:
'not supported'
},
dbxrefs
))
if
not
location
==
''
:
return
(
results
)
else
:
print
(
json
.
dumps
(
results
,
indent
=
4
))
print
(
json
.
dumps
(
results
,
indent
=
4
))
def
load_with_external_provider
(
provider
,
dbxrefs
):
def
load_with_external_provider
(
provider
,
dbxrefs
,
location
):
logger
.
debug
(
'Loading {0} via external provider'
.
format
(
dbxrefs
))
script
=
provider
[
'retriever'
][
'location'
]
call
=
'{} {}'
.
format
(
script
,
' '
.
join
(
list
(
map
(
toString
,
dbxrefs
))))
call
=
location
+
'{} {}'
.
format
(
script
,
' '
.
join
(
list
(
map
(
toString
,
dbxrefs
))))
logger
.
debug
(
"Running '{}'"
.
format
(
call
))
import
subprocess
result
=
subprocess
.
check_output
(
call
,
shell
=
True
)
...
...
providers.yaml
View file @
f4475346
-
name
:
Enzyme
prefixes
:
[
EC
,
Enzyme
]
prefixes
:
[
"
EC
"
]
resources
:
html
:
[
"
https://enzyme.expasy.org/EC/%i"
]
text
:
[
"
https://enzyme.expasy.org/EC/%i.txt"
]
...
...
scripts/retrieve_gene_ontology.py
View file @
f4475346
...
...
@@ -36,16 +36,20 @@ def main():
print
(
json
.
dumps
(
documents
))
def
read_basic
(
d
):
out
=
{
'definition'
:
d
[
'results'
][
0
][
'definition'
][
'text'
]}
out
=
{
'definition'
:
d
[
'results'
][
0
][
'definition'
][
'text'
]
,
'synonyms'
:
[]
}
out
[
'name'
]
=
d
[
'results'
][
0
][
'name'
]
out
[
'synonyms'
]
=
d
[
'results'
][
0
][
'synonyms'
]
if
'synonyms'
in
d
[
'results'
][
0
]:
out
[
'synonyms'
]
=
d
[
'results'
][
0
][
'synonyms'
]
return
(
out
)
def
read_relations
(
d
):
out
=
{
'relations'
:
{
'children'
:
d
[
'results'
][
0
][
'children'
]}}
for
child
in
out
[
'relations'
][
'children'
]:
child
[
'type'
]
=
child
.
pop
(
'relation'
)
out
[
'relations'
][
'parents'
]
=
parse_history
(
d
[
'results'
][
0
][
'history'
])
out
=
{
'relations'
:
{
'children'
:
[],
'parents'
:
[]}}
if
'children'
in
d
[
'results'
][
0
]:
out
[
'relations'
][
'children'
]
=
d
[
'results'
][
0
][
'children'
]
for
child
in
out
[
'relations'
][
'children'
]:
child
[
'type'
]
=
child
.
pop
(
'relation'
)
if
'history'
in
d
[
'results'
][
0
]:
out
[
'relations'
][
'parents'
]
=
parse_history
(
d
[
'results'
][
0
][
'history'
])
return
(
out
)
def
parse_history
(
h
):
...
...
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