Skip to main content

Table 8 API examples

From: kegg_pull: a software package for the RESTful access and pulling from the Kyoto Encyclopedia of Gene and Genomes

Action

Examples

Pull Entries with a single request

import kegg_pull.pull as p

single_pull = p.SinglePull(output = 'kegg-entries/')

single_pull.pull(entry_ids = ['cpd:C00001', 'cpd:C00002'])

Pull Entries with multiple requests

import kegg_pull.pull as p

import kegg_pull.entry_ids as ei

single_pull = p.SinglePull(

output = 'kegg-entries.zip', entry_field = 'mol'

)

multi_pull = p.MultiProcessMultiplePull(

single_pull = single_pull, n_workers = 4

)

entry_ids: list = ei.from_file(file_path = 'entry-ids.txt')

multi_pull.pull(entry_ids = entry_ids)

Pull entry IDs

import kegg_pull.entry_ids as ei

ei.from_database(database_name = 'hsa')

REST operation

import kegg_pull.rest as r

kegg_rest = r.KEGGrest()

kegg_response: r.KEGGresponse = kegg_rest.molecular_find(

database_name = 'drug', exact_mass = (200, 220)

)

URL creation

import kegg_pull.kegg_url as ku

conv_url = ku.DatabaseConvKEGGurl(

kegg_database_name = 'hsa',

outside_database_name = 'ncbi-geneid'

)

  1. Example method calls from the API, executable in a python script or python console. The above lines of code are analogous to the corresponding terminal commands in Table 9. While the API requires more lines of code than the CLI, it allows users to use kegg_pull functionality in their own python scripts. There is also no CLI commands for URL creation but those using the API can use this functionality if they just want KEGG REST URLs. Finally, there is no analogous distinction between SinglePull and AbstractMultiplePull in the CLI but rather there is only a pull command