API reference
KEGG operations
KEGGAPI.kegg_info — Function
kegg_info(database::String) -> StringGet information about a specific database from the KEGG API.
Allowed database values are:
kegg | pathway | brite | module | ko | genes | <org> |
ag | vg | vp | genome | vtax | vgenome | ligand |
compound | glycan | reaction| rclass | rmodule | enzyme | network |
ntmap | variant | disease | drug | dgroupArguments
database::String: The KEGG database for which to retrieve information.
Returns
String: Database release information and statistics from KEGG.
Example
julia> info = kegg_info("kegg");
julia> occursin("KEGG", info)
trueExtended help
kegg_info returns database release information and statistics. For databases other than kegg, genes, and ligand, the response also lists databases that can be passed to kegg_link.
Reference
- https://www.kegg.jp/kegg/rest/keggapi.html#info
KEGGAPI.kegg_list — Function
kegg_list(query::String, query_type::String = "") -> Union{KeggTupleList, KeggGenesList}Get a list of entry identifiers and associated names.
Arguments
query::String: The KEGG database to list.query_type::String: An optional organism code, BRITE prefix, organism group, or taxonomy rank identifier used to narrow the list.
Allowed database values are:
pathway | brite | module | ko | <org> | ag | vg |
vp | genome | vtax | vgenome | compound | glycan | reaction|
rclass | rmodule | enzyme | network | ntmap | variant| disease |
drug | dgroupReturns
KeggTupleList: A two-column response, a response with an unrecognized width, or an empty response, together with its request URL and column names.KeggGenesList: The four columns in an organism-specific gene response, together with its request URL and column names.
Examples
julia> result = kegg_list("pathway", "hsa");
julia> result isa KEGGAPI.KeggTupleList && !isempty(result.data)
trueExtended help
kegg_list returns entries from the requested database. It accepts the database names above except the composite databases genes and kegg. Use genome to list organisms and their three- or four-letter codes.
The optional query_type becomes the second URL segment. For pathway queries, pass an organism code to list organism-specific pathways. For BRITE queries, pass "br", "jp", "ko", or an organism code. For genome queries, pass an organism group name or taxonomy <rank_id> such as a phylum, class, order, family, genus, or species identifier.
References
- https://www.kegg.jp/kegg/rest/keggapi.html#list
kegg_list(dbentries::Vector{String}; request_delay::Real = 0.4, timeout = nothing) -> KeggTupleListGet a list of entry identifiers and associated names.
Arguments
dbentries::Vector{String}: The list of entries to list.request_delay::Real: Seconds to wait between batched requests. Defaults to 0.4. No delay occurs when the input fits in one request.timeout::Real: Deprecated alias forrequest_delay. If both keywords are supplied, their values must be equal.
Throws
ArgumentError: If a delay is negative or non-finite, or ifrequest_delayandtimeoutconflict.
Returns
KeggTupleList: The requested entries, request URLs, and column names.
Examples
julia> result = kegg_list(["hsa:10458", "hsa:10459"]);
julia> result isa KEGGAPI.KeggTupleList && result.url isa Vector{String} && length(result.data) == 2
trueExtended help
The input is limited to 10 entries per request. Larger inputs are split into batches, with request_delay seconds between requests and no wait after the final request. The default of 0.4 seconds keeps batched calls below KEGG's limit of three requests per second.
KEGGAPI.kegg_find — Function
kegg_find(database::String, query::String, option::String = "") -> KeggTupleListFind entries with a matching query keyword or other query data.
Allowed database values are:
kegg | pathway | brite | module | ko | genes | <org> |
ag | vg | vp | genome | vtax | vgenome| compound|
glycan | reaction| rclass | rmodule| enzyme | network| ntmap |
variant | disease | drug | dgroupAllowed option values (only for the compound and drug databases):
formula | exact_mass | mol_weight | nopArguments
database::String: The KEGG database to search.query::String: The query keyword or data. Spaces are converted to+.option::String: For thecompound/drugdatabases, restrict the search to a chemical field.nopdisables keyword pre-processing.
Returns
KeggTupleList: The matching identifiers and descriptions, with the request URL and column names.
Examples
julia> result = kegg_find("compound", "glucose");
julia> result isa KEGGAPI.KeggTupleList && result.colnames == ["ID", "Details"] && !isempty(result.data)
trueExtended help
kegg_find searches a KEGG database for entries that match query. For compound and drug, use option to search by formula, exact_mass, or mol_weight. Specify a range with a hyphen, as in "300-310". The nop option disables keyword preprocessing. The function accepts recognized KEGG databases and organism codes. It warns about other database names before passing them to the API.
Reference
- https://www.kegg.jp/kegg/rest/keggapi.html#find
KEGGAPI.kegg_get — Function
kegg_get(dbentries::Vector{String}, option::Union{Symbol, Nothing} = nothing; request_delay::Real = 0.4, timeout = nothing) -> NamedTuple
kegg_get(dbentry::String, option::Union{Symbol, Nothing} = nothing; request_delay::Real = 0.4, timeout = nothing) -> NamedTupleRetrieve given database entries.
Allowed dbentries (database entries):
pathway | brite | module | ko | <org> | ag | vg |
vp | genome | vtax | vgenome | compound | glycan | reaction|
rclass | rmodule | enzyme | network | ntmap | variant | disease |
drug | dgroup | disease_ja| drug_ja | dgroup_ja| compound_jaAllowed option for retrieval of selected fields:
:aaseq | :ntseq | :mol | :kcf | :image | :image2x | :conf | :kgml | :json | nothingArguments
dbentries::Vector{String}: A vector of KEGG database entries to retrieve.option::Union{Symbol, Nothing}: An optional symbol specifying the format of the retrieved data. Ifnothing, the default format is used.request_delay::Real: Seconds to wait between batched requests. Defaults to 0.4. No delay occurs when the input fits in one request.timeout::Real: Deprecated alias forrequest_delay. If both keywords are supplied, their values must be equal.
Throws
ArgumentError: If a delay is negative or non-finite, or ifrequest_delayandtimeoutconflict.
Returns
- For vector input, a named tuple
(url = urls, data = data).urlsis aVector{String}containing one URL per request batch.datais a vector with one processed result per retrieved entry. - For scalar input, a named tuple
(url = url, data = data).urlis the single request URL.datais aStringfor text and sequence formats and aVector{UInt8}for:imageand:image2x.
Examples
julia> result = kegg_get(["hsa:10458", "hsa:10459"], :aaseq);
julia> (result.url isa Vector{String}, length(result.data), all(item -> item isa String, result.data))
(true, 2, true)
julia> result = kegg_get("hsa:10458");
julia> (result.url isa String, result.data isa String)
(true, true)Extended help
kegg_get retrieves entries as KEGG flat files or in the format selected by option. Flat files are supported for every KEGG database except brite. Each request accepts at most 10 entries, so the function splits longer inputs into batches. It waits request_delay seconds between batches but not after the final request. The default of 0.4 seconds keeps batched calls below KEGG's limit of three requests per second.
Use option to retrieve gene sequences, chemical structures, compound, glycan, or drug images, pathway images, or KGML files. The :image2x option retrieves a reference pathway map at double size.
The input is limited to one compound/glycan/drug entry with the :image option, and to one pathway entry with the :image, :image2x or :kgml option.
Reference
- https://www.kegg.jp/kegg/rest/keggapi.html#get
KEGGAPI.kegg_conv — Function
kegg_conv(target_db::String, source_db::String) -> KeggTupleListConvert KEGG identifiers to/from outside identifiers.
Arguments
target_db::String: Target databasesource_db::String: Source database
Returns
KeggTupleList: The requested identifier mappings, with the request URL and column names.
Examples
julia> result = kegg_conv("genes", "ncbi-geneid:948364");
julia> result isa KEGGAPI.KeggTupleList && !isempty(result.data)
trueExtended help
Convert outside accession numbers to KEGG identifiers or KEGG identifiers to outside accession numbers. Pass database names for database-to-database mapping, or pass one or more entries to convert selected identifiers. The genes database is valid only when converting selected entries.
References
kegg_conv(target_db::String, dbentries::Vector{String}; request_delay::Real = 0.4, timeout = nothing) -> KeggTupleListConvert KEGG identifiers to/from outside identifiers.
For gene identifiers:
<dbentries> = database entries of the following <database>
<database> = <org> | genes | ncbi-geneid | ncbi-proteinid | uniprot
<org> = KEGG organism code or T numberFor chemical substance identifiers:
<dbentries> = database entries of the following <database>
<database> = compound | glycan | drug | pubchem | chebiArguments
target_db::String: Target databasedbentries::Vector{String}: Entries to convert.request_delay::Real: Seconds to wait between batched requests. Defaults to 0.4. No delay occurs when the input fits in one request.timeout::Real: Deprecated alias forrequest_delay. If both keywords are supplied, their values must be equal.
Returns
KeggTupleList: The requested identifier mappings, request URLs, and column names.
Throws
ArgumentError: If a delay is negative or non-finite, or ifrequest_delayandtimeoutconflict.
Examples
julia> result = kegg_conv("ncbi-proteinid", ["hsa:10458", "ece:Z5100"]);
julia> result isa KEGGAPI.KeggTupleList && result.url isa Vector{String} && !isempty(result.data)
trueKEGGAPI.kegg_link — Function
kegg_link(target_db::String, source_db::String, option::String = "") -> Union{KeggTupleList, String}Find related entries by using database cross-references.
The available KEGG databases are:
pathway | brite | module | ko | <org> | ag | vg |
vp | genome | vtax | vgenome | compound| glycan | reaction|
rclass | rmodule | enzyme | network | ntmap | variant | disease |
drug | dgroup | <outside_db>and the available external databases are:
pubmed | taxonomy | atc | jtc | ndc | ykArguments
target_db::String: Target databasesource_db::String: Source databaseoption::String: Optional refinement of the query. Forgenome/taxonomylinks a taxonomic rank may be given (species | genus | family | order | class | phylum). For thedrug/atc/jtcdatabases an RDF output format may be requested (turtle | n-triple), in which case the raw response text is returned instead of aKeggTupleList.
Returns
KeggTupleList: The linked identifiers, request URL, and column names for tabular responses.String: The raw RDF response whenoptionis"turtle"or"n-triple".
Examples
julia> links = kegg_link("pathway", "hsa:10458");
julia> links isa KEGGAPI.KeggTupleList && !isempty(links.data)
true
julia> rdf = kegg_link("atc", "D00564", "turtle");
julia> rdf isa String && !isempty(rdf)
trueExtended help
kegg_link retrieves cross-references within KEGG and between KEGG and outside databases. Pass database names to retrieve all links between two databases, or pass entry identifiers to retrieve links for selected entries.
kegg_link(target_db::String, dbentries::Vector{String}, option::String = ""; request_delay::Real = 0.4, timeout = nothing) -> Union{KeggTupleList, String}Find related entries by using database cross-references.
The available KEGG databases are:
pathway | brite | module | ko | <org> | ag | vg |
vp | genome | vtax | vgenome | compound| glycan | reaction|
rclass | rmodule | enzyme | network | ntmap | variant | disease |
drug | dgroup | <outside_db>and the available external databases are:
pubmed | taxonomy | atc | jtc | ndc | ykArguments
target_db::String, target databasedbentries::Vector{String}, entries from the source databaseoption::String, optional refinement of the query. A taxonomic rank (species | genus | family | order | class | phylum) forgenome/taxonomylinks, or an RDF output format (turtle | n-triple) for thedrug/atc/jtcdatabases (in which case the raw response text is returned).request_delay::Real, seconds to wait between batched requests. Defaults to 0.4. No delay occurs when the input fits in one request.timeout::Real, deprecated alias forrequest_delay. If both keywords are supplied, their values must be equal.
Returns
KeggTupleList: The linked identifiers, request URLs, and column names for tabular responses.String: The concatenated raw RDF responses whenoptionis"turtle"or"n-triple".
Throws
ArgumentError: If a delay is negative or non-finite, or ifrequest_delayandtimeoutconflict.
Examples
julia> links = kegg_link("pathway", ["hsa:10458", "hsa:10459"]);
julia> links isa KEGGAPI.KeggTupleList && links.url isa Vector{String} && !isempty(links.data)
trueThe vector form sends at most 10 entries per request. It waits request_delay seconds between requests, but does not wait after the final request.
KEGGAPI.kegg_ddi — Function
kegg_ddi(dbentry::String) -> KeggTupleList
kegg_ddi(dbentries::Vector{String}) -> KeggTupleListFind adverse drug-drug interactions (DDI).
The available databases are:
drug | ndc | yjArguments
dbentry::String/dbentries::Vector{String}: KEGG DRUG (dr:/Dnumbers), NDC or YJ code entries to query for interactions.
Returns
KeggTupleList: The interactions, request URL or URLs, and column names. The columns are["Entry 1", "Entry 2", "Interaction Type", "Mechanism"], where the interaction type isCI(contraindication) orP(precaution).
Throws
ArgumentError: Ifdbentriesis empty
Examples
julia> result = kegg_ddi(["D00564", "D00100"]);
julia> result isa KEGGAPI.KeggTupleList && result.colnames == ["Entry 1", "Entry 2", "Interaction Type", "Mechanism"]
trueExtended help
The KEGG DDI database records known adverse drug-drug interactions. A query with multiple entries also returns pairwise interactions among those entries. Vector inputs must contain between one and ten entries. Empty vectors and vectors with more than ten entries throw an ArgumentError before a request is sent. Queries above the KEGG limit cannot be split into independent requests because doing so would omit interactions between entries in different requests.
Reference
- https://www.kegg.jp/kegg/rest/keggapi.html#ddi
KEGGAPI.@kegg_str — Macro
@kegg_str -> NamedTupleRetrieve a KEGG flat-file entry with string-macro syntax in the REPL.
See kegg_get for accepted database entries.
Returns
NamedTuple: The same(url = url, data = data)result as scalarkegg_get.
Example
julia> entry = kegg"hsa:10458";
julia> (entry.url isa String, entry.data isa String)
(true, true)Low-level requests
KEGGAPI.request is not exported. Use the qualified name when calling a valid KEGG endpoint that does not have a dedicated wrapper.
KEGGAPI.request — Function
request(url::String [, T::Type = String]) -> TSend a GET request to a KEGG API URL. This low-level function is an escape hatch for valid KEGG endpoints that do not have a dedicated KEGGAPI.jl wrapper.
The default T is String. Pass Vector{UInt8} to return the response body as raw bytes, for example when requesting an image. Other response types must be constructible from a Vector{UInt8}.
HTTP.jl exceptions pass through unchanged. Connection failures, including DNS and TLS failures, throw HTTP.Exceptions.ConnectError. Failures while sending a request or reading its response throw HTTP.Exceptions.RequestError, timeouts throw HTTP.Exceptions.TimeoutError, and unsuccessful HTTP responses throw HTTP.Exceptions.StatusError. The HTTP exceptions retain the underlying error or response in their fields.
Examples
request is not exported, so call it with the KEGGAPI module prefix.
julia> text = KEGGAPI.request("https://rest.kegg.jp/info/kegg");
julia> occursin("KEGG", text)
true
julia> image = KEGGAPI.request("https://rest.kegg.jp/get/hsa00010/image", Vector{UInt8});
julia> image[1:8] == UInt8[0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]
trueArguments
url::String: A KEGG API URL.T::Type: The response body type. Defaults toString.
Returns
T: The response body converted to the requested type.
Throws
HTTP.Exceptions.ConnectError: If HTTP.jl cannot establish a connection.HTTP.Exceptions.RequestError: If HTTP.jl cannot send the request or read the response.HTTP.Exceptions.TimeoutError: If the request exceeds HTTP.jl's read timeout.HTTP.Exceptions.StatusError: If the server returns an unsuccessful status.