Case 1: From a UniProt ID to KEGG information
This walkthrough starts from a protein identifier in an outside database (UniProt / Swiss-Prot) and pulls together the corresponding KEGG gene, its 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:
| Database | Identifier prefix |
|---|---|
| UniProt | uniprot: |
| NCBI Gene | ncbi-geneid: |
| NCBI Protein | ncbi-proteinid: |
| KEGG genes | genes |
Only identifiers with a hit in KEGG are returned:
conv = KEGGAPI.kegg_conv("genes", "uniprot:A0A072UR65")
DataFrame(conv.data, conv.colnames)| Row | Target ID | Source ID |
|---|---|---|
| String | String | |
| 1 | up:A0A072UR65 | mtr:25493984 |
Several identifiers from the same database can be converted in one call by passing a vector (for example a column read from a CSV file with CSV.jl). The input is automatically split into chunks of 10 to respect the KEGG rate limit:
using CSV
df = DataFrame(CSV.File("subset_data.csv"))
entries = string.("uniprot:", df.Entry)
conv = KEGGAPI.kegg_conv("genes", entries)
DataFrame(conv.data, conv.colnames)The reverse direction (KEGG → outside database) works the same way:
conv = KEGGAPI.kegg_conv("ncbi-proteinid", "mtr:25493984")
DataFrame(conv.data, conv.colnames)| Row | Target ID | Source ID |
|---|---|---|
| String | String | |
| 1 | mtr:25493984 | ncbi-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")
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 Metabolism3. Download sequences
kegg_get can return amino-acid (:aaseq) or nucleotide (:ntseq) FASTA sequences. .data holds one FASTA record per requested entry, which you can write to a file (e.g. with FastaIO.jl):
using FastaIO
seqs = KEGGAPI.kegg_get(["mtr:25493984", "shz:shn_30305"], :aaseq)
FastaWriter("aaseq.fasta") do fw
for record in seqs.data
write(fw, record)
end
end4. 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")
DataFrame(ko.data, ko.colnames)| Row | Target ID | Source ID |
|---|---|---|
| String | String | |
| 1 | mtr:25493984 | ko:K01183 |
Reactions associated with that ortholog:
rxns = KEGGAPI.kegg_link("reaction", "K01183")
DataFrame(rxns.data, rxns.colnames)| Row | Target ID | Source ID |
|---|---|---|
| String | String | |
| 1 | ko:K01183 | rn:R01206 |
| 2 | ko:K01183 | rn:R02334 |
Pathways the gene participates in:
paths = KEGGAPI.kegg_link("pathway", "mtr:25493984")
DataFrame(paths.data, paths.colnames)| Row | Target ID | Source ID |
|---|---|---|
| String | String | |
| 1 | mtr:25493984 | path:mtr00520 |
| 2 | mtr:25493984 | path: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")
first(DataFrame(ko_genes.data, ko_genes.colnames), 5)| Row | Target ID | Source ID |
|---|---|---|
| String | String | |
| 1 | ko:K01183 | hsa:1118 |
| 2 | ko:K01183 | hsa:27159 |
| 3 | ko:K01183 | ptr:457114 |
| 4 | ko:K01183 | ptr:457641 |
| 5 | ko:K01183 | pps:100977638 |
The second column of ko_genes.data is a vector of gene identifiers that can be fed straight back into kegg_get(...; :aaseq) or :ntseq to build, for example, a multiple-sequence-alignment input.
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)
open("map00520.png", "w") do io
write(io, img.data)
end