Commit f4475346 authored by lmueller's avatar lmueller
Browse files

modefied retriever.py to use retrieve function external

parent 3826d12b
......@@ -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)
......
- name: Enzyme
prefixes: [EC, Enzyme]
prefixes: ["EC"]
resources:
html: ["https://enzyme.expasy.org/EC/%i"]
text: ["https://enzyme.expasy.org/EC/%i.txt"]
......
......@@ -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):
......
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