Case 1: From a UniProt ID to KEGG information

This walkthrough starts with a UniProt identifier and retrieves its KEGG gene, sequences, orthology group, reactions, and pathways.

1. Convert an outside identifier to a KEGG identifier

kegg_conv maps identifiers between KEGG and outside databases. Some common gene / protein identifier prefixes are:

DatabaseIdentifier prefix
UniProtuniprot:
NCBI Genencbi-geneid:
NCBI Proteinncbi-proteinid:
KEGG genesgenes

Only identifiers with a hit in KEGG are returned:

conv = KEGGAPI.kegg_conv("genes", "uniprot:A0A072UR65")
@assert conv isa KEGGAPI.KeggTupleList
DataFrame(conv.data, conv.colnames)
1×2 DataFrame
RowTarget IDSource ID
StringString
1up:A0A072UR65mtr:25493984

Several identifiers from the same database can be converted in one call by passing a vector. KEGGAPI splits inputs longer than 10 entries into request batches:

entries = ["uniprot:A0A072UR65", "uniprot:P12345"]
conv = KEGGAPI.kegg_conv("genes", entries)
@assert conv isa KEGGAPI.KeggTupleList
conv.url
1-element Vector{String}:
 "https://rest.kegg.jp/conv/genes/uniprot:A0A072UR65+uniprot:P12345"

To convert from KEGG to an outside database, reverse the target and source:

conv = KEGGAPI.kegg_conv("ncbi-proteinid", "mtr:25493984")
@assert conv isa KEGGAPI.KeggTupleList
DataFrame(conv.data, conv.colnames)
1×2 DataFrame
RowTarget IDSource ID
StringString
1mtr:25493984ncbi-proteinid:XP_013458146

2. Retrieve the gene entry

Use kegg_get to fetch the full flat-file entry for a KEGG gene. A single entry is returned as a String in the .data field:

gene = KEGGAPI.kegg_get("mtr:25493984")
@assert gene.url isa String && gene.data isa String
println(join(first(split(gene.data, "\n"), 8), "\n"))
ENTRY       25493984          CDS       T01716
NAME        (RefSeq) class V chitinase CHIT5b
ORTHOLOGY   K01183  chitinase [EC:3.2.1.14]
ORGANISM    mtr  Medicago truncatula (barrel medic)
PATHWAY     mtr00520  Amino sugar and nucleotide sugar metabolism
            mtr01100  Metabolic pathways
BRITE       KEGG Orthology (KO) [BR:mtr00001]
             09100 Metabolism

3. Download sequences

kegg_get can return amino-acid (:aaseq) or nucleotide (:ntseq) FASTA sequences. For vector input, .data holds one FASTA record per requested entry:

seqs = KEGGAPI.kegg_get(["mtr:25493984", "shz:shn_30305"], :aaseq)
@assert length(seqs.data) == 2 && all(startswith(">"), seqs.data)
first(split(first(seqs.data), '\n'))
">mtr:25493984 K01183 chitinase [EC:3.2.1.14] | (RefSeq) class V chitinase CHIT5b (A)"

Write the records with write("aaseq.fasta", join(seqs.data, '\n')) or pass them to a FASTA package.

4. Orthology, reactions and pathways

kegg_link finds cross-references between databases. The orthology (KO) group for the gene:

ko = KEGGAPI.kegg_link("ko", "mtr:25493984")
@assert ko isa KEGGAPI.KeggTupleList
DataFrame(ko.data, ko.colnames)
1×2 DataFrame
RowTarget IDSource ID
StringString
1mtr:25493984ko:K01183

Reactions associated with that ortholog:

rxns = KEGGAPI.kegg_link("reaction", "K01183")
@assert rxns isa KEGGAPI.KeggTupleList
DataFrame(rxns.data, rxns.colnames)
2×2 DataFrame
RowTarget IDSource ID
StringString
1ko:K01183rn:R01206
2ko:K01183rn:R02334

Pathways the gene participates in:

paths = KEGGAPI.kegg_link("pathway", "mtr:25493984")
@assert paths isa KEGGAPI.KeggTupleList
DataFrame(paths.data, paths.colnames)
2×2 DataFrame
RowTarget IDSource ID
StringString
1mtr:25493984path:mtr00520
2mtr:25493984path:mtr01100

5. All genes in an orthology group

The same kegg_link call, targeting genes, expands an orthology group into every member gene across organisms:

ko_genes = KEGGAPI.kegg_link("genes", "K01183")
@assert ko_genes isa KEGGAPI.KeggTupleList
first(DataFrame(ko_genes.data, ko_genes.colnames), 5)
5×2 DataFrame
RowTarget IDSource ID
StringString
1ko:K01183hsa:1118
2ko:K01183hsa:27159
3ko:K01183ptr:457114
4ko:K01183ptr:457641
5ko:K01183pps:100977638

The second column of ko_genes.data contains gene identifiers. Pass it to kegg_get with :aaseq or :ntseq to prepare input for a multiple sequence alignment.

6. Download a pathway map

The :image option returns the PNG bytes of a pathway map, which you can write to disk and open with your favourite image viewer or Images.jl:

img = KEGGAPI.kegg_get("map00520", :image)
@assert img.data isa Vector{UInt8} && !isempty(img.data)
path = tempname()
bytes_written = open(path, "w") do io
    write(io, img.data)
end
rm(path)
bytes_written == length(img.data)
true