Skip to content

Instantly share code, notes, and snippets.

@markziemann
Created October 23, 2021 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markziemann/dbfb975156e5929ec09767af64315e5c to your computer and use it in GitHub Desktop.
Save markziemann/dbfb975156e5929ec09767af64315e5c to your computer and use it in GitHub Desktop.
Getting mitopathways into GMT format
library(rvest)
library(dplyr)
url="https://www.broadinstitute.org/files/shared/metabolism/mitocarta/human.mitocarta3.0.path_.html"
webpage <- read_html(url)
tbls <- html_nodes(webpage, "table")
tbl <- webpage %>% html_nodes("table") %>% .[1] %>% html_table(fill = TRUE)
tbl <- tbl[[1]]
colnames(tbl) <- c("pathway","description","set")
df <- as.data.frame(tbl)
sets <- strsplit(df$set,",")
sets <- lapply(sets, function(v) { gsub(" ","",v) } )
names(sets) <- paste(df[,1],df[,2])
writeGMT <- function (object, fname ){
if (class(object) != "list") stop("object should be of class 'list'")
if(file.exists(fname)) unlink(fname)
for (iElement in 1:length(object)){
write.table(t(c(make.names(rep(names(object)[iElement],2)),object[[iElement]])),
sep="\t",quote=FALSE,
file=fname,append=TRUE,col.names=FALSE,row.names=FALSE)
}
}
writeGMT(object=sets,fname="mitopathways.gmt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment