Case 3: Identifying a compound in KEGG

This walkthrough looks up a compound by name, retrieves its entry, and finds the reactions it participates in.

1. Find a compound by name

kegg_find searches a database by keyword. To look for a compound, pass the compound database and the compound name:

hits = KEGGAPI.kegg_find("compound", "chitin")
@assert hits isa KEGGAPI.KeggTupleList
DataFrame(hits.data, hits.colnames)
1×2 DataFrame
RowIDDetails
StringString
1C00461Chitin; beta-1,4-Poly-N-acetyl-D-glucosamine; [1,4-(N-Acetyl-beta-D-glucosaminyl)]n; [1,4-(N-Acetyl-beta-D-glucosaminyl)]n+1

2. Retrieve the compound entry

The first column of hits.data holds compound identifiers such as cpd:C00461. Fetch the full entry with kegg_get:

cpd = KEGGAPI.kegg_get("cpd:C00461")
@assert cpd.url isa String && cpd.data isa String
println(join(first(split(cpd.data, "\n"), 8), "\n"))
ENTRY       C00461                      Compound
NAME        Chitin;
            beta-1,4-Poly-N-acetyl-D-glucosamine;
            [1,4-(N-Acetyl-beta-D-glucosaminyl)]n;
            [1,4-(N-Acetyl-beta-D-glucosaminyl)]n+1
FORMULA     (C8H13NO5)n
REMARK      Same as: G10483
REACTION    R01206 R02333 R02334 R02335 R11660

3. Compound image

The :image option returns the PNG bytes of the compound structure, which you can save to disk:

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

4. Reactions linked to the compound

kegg_link returns the reactions that include the compound:

rxns = KEGGAPI.kegg_link("reaction", "cpd:C00461")
@assert rxns isa KEGGAPI.KeggTupleList
DataFrame(rxns.data, rxns.colnames)
9×2 DataFrame
RowTarget IDSource ID
StringString
1cpd:C00461rn:R01206
2cpd:C00461rn:R01206
3cpd:C00461rn:R02333
4cpd:C00461rn:R02334
5cpd:C00461rn:R02334
6cpd:C00461rn:R02335
7cpd:C00461rn:R02335
8cpd:C00461rn:R11660
9cpd:C00461rn:R11660

5. Reaction information

Pass the reaction identifiers in the second column of rxns.data to kegg_get to retrieve their entries:

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