Skip to content

Instantly share code, notes, and snippets.

@ATpoint
Created November 6, 2024 14:41
Show Gist options
  • Save ATpoint/e05887e4a0f717bc4e7d33f003f780ed to your computer and use it in GitHub Desktop.
Save ATpoint/e05887e4a0f717bc4e7d33f003f780ed to your computer and use it in GitHub Desktop.
Retrieve human-readable KEGG pathway name to Ensembl gene ID mapping table
pkgs <- c("KEGGREST", "org.Mm.eg.db", "tidyverse", "AnnotationDbi")
invisible(lapply(pkgs, function(x) suppressPackageStartupMessages(library(x, character.only = TRUE))))
pathway_id_2_name <-
keggList("pathway", "mmu") %>%
enframe(name = "pathway_id", value = "pathway_name") %>%
mutate(pathway_id = gsub("mmu", "", pathway_id),
pathway_name = gsub(" - .*", "", pathway_name))
pathway_2_entrez <-
keggLink("pathway", "mmu") %>%
enframe(name = "entrez_id", value = "pathway_id") %>%
mutate(pathway_id = gsub("path:mmu", "", pathway_id),
entrez_id = gsub("mmu:", "", entrez_id))
entrez_to_ensembl <-
mapIds(org.Mm.eg.db, pathway_2_entrez$entrez_id, "ENSEMBL", "ENTREZID", multiVals = "list") %>%
enframe(name = "entrez_id", value = "gene_id") %>%
unnest(cols = gene_id) %>%
filter(!is.na(gene_id))
kegg_to_ensembl <-
entrez_to_ensembl %>%
left_join(x = ., y = pathway_2_entrez, by = "entrez_id", relationship = "many-to-many") %>%
left_join(x = ., y = pathway_id_2_name, by = "pathway_id", relationship = "many-to-many") %>%
filter(!is.na(gene_id) & !is.na(pathway_name)) %>%
dplyr::select(pathway_name, gene_id)
head(kegg_to_gene)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment