Created
October 23, 2021 03:26
-
-
Save markziemann/dbfb975156e5929ec09767af64315e5c to your computer and use it in GitHub Desktop.
Getting mitopathways into GMT format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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