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'
entryIDs = []


# 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','ReactomeReactionID']}


# 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","Smiles"]

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

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


# results

print(request.text)

# note that you can also retrieve the data for ALL compounds by performing a wildcard search
# eg: query = {"SabioCompoundID":"*", "fields[]":["SabioCompoundID","Name","PubChemID"]}




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

# Example SABIO-RK script 4 - returns reaction details

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

import requests

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

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

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

# make GET request
request = requests.get(QUERY_URL, params = query)
request.raise_for_status()

# results
print(request.text)

# note that you can also retrieve the data for ALL reactions by performing a wildcard search
# eg: query = {"SabioReactionID":"*", "fields[]":["SabioReactionID","KeggReactionID"]}




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

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

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

import requests

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


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

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

# note that you can also retrieve the data for ALL reaction participants by performing a wildcard search
# for this wildcard query, the output field 'SabioReactionID' is added by default
# query = {"SabioReactionID":"*", "fields[]":["SabioCompoundID","Name","Role"]}

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

# results
print(request.text)




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

# Example SABIO-RK script 6 - returns reaction modifier details

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

import requests

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


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

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

# note that you can also retrieve the data for ALL reaction modifiers by performing a wildcard search
# for this wildcard query, the output field 'SabioReactionID' is added by default
# query = {"SabioReactionID":"*", "fields[]":["EntryID","Name","Role"]}

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

# results
print(request.text)




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

# Example SABIO-RK script 7 - returns compound id and compound synonym names

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

import requests

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


# input: SabioCompoundID or compound name (recommended name or synonymous name)
# valid output fields: "fields[]":["SabioCompoundID","Name","NameType"]

# example 1
query = {"SabioCompoundID":"36", "fields[]":["Name","NameType"]}

# example 2
# query = {"CompoundName":"Adenosine triphosphate", "fields[]":["SabioCompoundID","Name","NameType"]}

# example 3 - wildcard search returns all compounds
# query = {"SabioCompoundID":"*", "fields[]":["SabioCompoundID","Name","NameType"]}

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


# results

print(request.text)




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

# Example SABIO-RK script 8 - returns EC number and enzyme synonym names

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

import requests

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


# input: EC number or enzyme name (recommended name or synonymous name)
# valid output fields: "fields[]":["ECNumber","Name","NameType"]

# example 1
query = {"ECNumber":"5.1.99.6", "fields[]":["Name","NameType"]}

# example 2
# query = {"EnzymeName":"isocitrate dehydrogenase (NAD+)", "fields[]":["ECNumber","Name","NameType"]}

# example 3 - wildcard search returns ALL EC numbers, enzyme names and their synomymous names
# query = {"ECNumber":"*", "fields[]":["ECNumber","Name","NameType"]}

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


# results

print(request.text)




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

# Example SABIO-RK script 9 - returns recommended and synonym names of pathways

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

import requests

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


# input: KEGG pathway id or pathway name (recommended name or synonymous name)
# valid output fields: "fields[]":["KeggPathwayID","Name","NameType"]

# example 1
query = {"KeggPathwayID":"00010", "fields[]":["Name","NameType"]}

# example 2
# query = {"PathwayName":"Glycolysis/Gluconeogenesis", "fields[]":["KeggPathwayID","Name","NameType"]}

# example 3 - wildcard search returns ALL pathway data
# query = {"PathwayName":"*", "fields[]":["KeggPathwayID","Name","NameType"]}

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


# results

print(request.text)




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

# Example SABIO-RK script 10 - returns entry data in SBML format

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

import requests

# specify SBML as output format
SBML_URL='http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/sbml'

# input: search fields and search terms eg
query_dict = {"Organism":'"Haemophilus influenzae"',"ECNumber":"2.7.7.1"}
query_string = ' AND '.join(['%s:%s' % (k,v) for k,v in query_dict.items()])
query = {'q':query_string}

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


# results

print(request.text)




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

# Search for data inserted into SABIO-RK between two dates

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

In 'Example SABIO-RK script 1 and 2' the query can be extended by the 'InsertDate' search term eg:

query_dict = {"Organism":'"Homo sapiens"',"InsertDate":"[2021-12-14T00:00:00Z TO 2022-02-14T00:00:00Z]"}


Similarly for the output fields the 'InsertDate' field can be defined:

query = {'format':'tsv', 'fields[]':['EntryID', 'Organism', 'UniprotID','InsertDate']}