Webservice access using a Python script

The following Python example scripts retrieve SABIO-RK data in table format (thanks to Robert Stanley).


# ------------------------------------------------------------------------------

# Example SABIO-RK script 1

# ------------------------------------------------------------------------------

import requests

ENTRYID_QUERY_URL = 'http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/entryIDs'
PARAM_QUERY_URL = 'http://sabiork.h-its.org/entry/exportToExcelCustomizable'


# ask SABIO-RK for all EntryIDs matching a query

query_dict = {"Organism":'"Homo sapiens"',"ECNumber":"1.1.1.1"}
query_string = ' AND '.join(['%s:%s' % (k,v) for k,v in query_dict.items()])
query = {'format':'txt', 'q':query_string}


# make GET request

request = requests.get(ENTRYID_QUERY_URL, params = query)
request.raise_for_status() # raise if 404 error


# each entry is reported on a new line

entryIDs = [int(x) for x in request.text.strip().split('\n')]
print('%d matching entries found.' % len(entryIDs))


# encode next request, for parameter data given entry IDs

data_field = {'entryIDs[]': entryIDs}
query = {'format':'tsv', 'fields[]':['EntryID', 'Organism', 'UniprotID','ECNumber', 'Parameter']}


# make POST request

request = requests.post(PARAM_QUERY_URL, params=query, data=data_field)
request.raise_for_status()


# results

print(request.text)




# ------------------------------------------------------------------------------

# Example SABIO-RK script 2
# This single-step method is especially recommended for large result sets (> 10000)

# ------------------------------------------------------------------------------

import requests

QUERY_URL = 'http://sabiork.h-its.org/sabioRestWebServices/kineticlawsExportTsv'


# specify search fields and search terms

query_dict = {"Organism":'"lactococcus lactis subsp. lactis bv. diacetylactis"', "Product":'"Tyrosine"'}
query_string = ' AND '.join(['%s:%s' % (k,v) for k,v in query_dict.items()])


# specify output fields and send request

query = {'fields[]':['EntryID', 'Organism', 'UniprotID','ECNumber', 'Parameter'], 'q':query_string}

request = requests.post(QUERY_URL, params = query)
request.raise_for_status()


# results

print(request.text)




# ------------------------------------------------------------------------------

# Example SABIO-RK script 3 - returns compound details

# ------------------------------------------------------------------------------

import requests

QUERY_URL = 'http://sabiork.h-its.org/sabioRestWebServices/searchCompoundDetails'


# input: SabioCompoundID
# valid output fields: "fields[]":["Name","ChebiID","PubChemID","InChI","SabioCompoundID","KeggCompoundID"]

# example
params = {"SabioCompoundID":"36", "fields[]":["Name","ChebiID","PubChemID"]}

request = requests.post(QUERY_URL, params = query)
request.raise_for_status()


# results

print(request.text)




# ------------------------------------------------------------------------------

# Example SABIO-RK script 4 - returns reaction details

# ------------------------------------------------------------------------------

#QUERY_URL = 'http://sabiork.h-its.org/sabioRestWebServices/searchReactionDetails'


# input: SabioReactionID
# valid output fields: "fields[]":["KeggReactionID","SabioReactionID","Enzymename","ECNumber","UniProtKB_AC","ReactionEquation"]

# example
params = {"SabioReactionID":"128", "fields[]":["KeggReactionID","ReactionEquation"]}




# ------------------------------------------------------------------------------

# Example SABIO-RK script 5 - returns reaction participant details

# ------------------------------------------------------------------------------

QUERY_URL = 'http://sabiork.h-its.org/testSabio/sabioRestWebServices/searchReactionParticipants'


# input: SabioReactionID
# valid output fields: "fields[]":["Name","Role","SabioCompoundID","ChebiID","PubChemID","KeggCompoundID","InChI"]

# example
params = {"SabioReactionID":"128", "fields[]":["Name","Role"]}