Case 2: EC reaction information in KEGG

This walkthrough uses an Enzyme Commission (EC) number to find KEGG reactions, their compounds, and the associated orthology group.

1. Reactions associated with an EC number

kegg_link takes the target database (reaction) and the EC number as ec:X.X.X.X, and returns every reaction linked to that enzyme:

rxns = KEGGAPI.kegg_link("reaction", "ec:3.2.1.14")
@assert rxns isa KEGGAPI.KeggTupleList
DataFrame(rxns.data, rxns.colnames)
4×2 DataFrame
RowTarget IDSource ID
StringString
1ec:3.2.1.14rn:R01206
2ec:3.2.1.14rn:R02334
3ec:3.2.1.14rn:R06081
4ec:3.2.1.14rn:R06082

2. Reaction information

The second column of rxns.data holds the reaction identifiers, such as rn:R01206. Pass them to kegg_get to retrieve the full entries. The .data field contains one flat-file String per reaction:

info = KEGGAPI.kegg_get(rxns.data[2])
@assert info.url isa Vector{String} && all(item -> item isa String, info.data)
println(join(first(split(info.data[1], "\n"), 6), "\n"))
ENTRY       R01206                      Reaction
NAME        [1,4-(N-acetyl-beta-D-glucosaminyl)]n glycanohydrolase
DEFINITION  Chitin + H2O <=> N-Acetyl-D-glucosamine + Chitin
EQUATION    C00461 + C00001 <=> C00140 + C00461
REMARK      Same as: R06081
RCLASS      RC00467  C00140_C00461

3. Compounds involved in a reaction

cpds = KEGGAPI.kegg_link("compound", "rn:R01206")
@assert cpds isa KEGGAPI.KeggTupleList
DataFrame(cpds.data, cpds.colnames)
4×2 DataFrame
RowTarget IDSource ID
StringString
1rn:R01206cpd:C00001
2rn:R01206cpd:C00140
3rn:R01206cpd:C00461
4rn:R01206cpd:C00461

Retrieve the compound entries the same way as the reactions:

cpd_info = KEGGAPI.kegg_get(cpds.data[2])
@assert cpd_info.url isa Vector{String} && all(item -> item isa String, cpd_info.data)
println(join(first(split(cpd_info.data[1], "\n"), 6), "\n"))
ENTRY       C00001                      Compound
NAME        H2O;
            Water
FORMULA     H2O
EXACT_MASS  18.0106
MOL_WEIGHT  18.02

4. Reaction image

The :image option returns the PNG bytes for a reaction, which you can save to disk:

img = KEGGAPI.kegg_get("rn:R01206", :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

5. Orthology group for a reaction

ko = KEGGAPI.kegg_link("ko", "rn:R01206")
@assert ko isa KEGGAPI.KeggTupleList
DataFrame(ko.data, ko.colnames)
4×2 DataFrame
RowTarget IDSource ID
StringString
1rn:R01206ko:K01183
2rn:R01206ko:K13381
3rn:R01206ko:K20547
4rn:R01206ko:K29107