Skip to content

Instantly share code, notes, and snippets.

@ATpoint
Created December 19, 2024 13:00
Show Gist options
  • Select an option

  • Save ATpoint/f7aa167a675a15fca8b7029ab1b32bd6 to your computer and use it in GitHub Desktop.

Select an option

Save ATpoint/f7aa167a675a15fca8b7029ab1b32bd6 to your computer and use it in GitHub Desktop.
Get REACTOME terms and associated genes independent of the REACTOME website via ReactomePA
library(tidyverse)
library(ReactomePA)
library(biomaRt)
r_human <- ReactomePA:::get_Reactome_DATA("human")
# This package maps to Entrez so we need the conversion table to Ensembl IDs
human_entrez2ensembl <- getBM(
attributes = c("entrezgene_id", "ensembl_gene_id"),
mart = mart_human
) %>%
setNames(c("entrez_id", "gene_id")) %>%
mutate(entrez_id = as.character(entrez_id))
# Named list with names being pathway IDs and elements being Entrez genes
reac2entrez <- tibble::enframe(r_human$PATHID2EXTID, name = "reactome_id", value = "entrez_id") %>% unnest("entrez_id")
reac2name <- data.frame(reactome_id = names(r_human$PATHID2NAME), pathway = as.character(r_human$PATHID2NAME))
# Merge with Ensembl ID
human_reactome <-
inner_join(x = human_entrez2ensembl, y = reac2entrez, by = "entrez_id", relationship = "many-to-many") %>%
inner_join(x = ., y = genes_human, by = "gene_id", relationship = "many-to-many") %>%
mutate(gene = paste(gene_id, gene_name, sep = "_")) %>%
inner_join(x = ., y = reac2name, by = "reactome_id") %>%
dplyr::select(pathway, gene) %>%
arrange(pathway) %>%
unique()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment