Skip to content

Instantly share code, notes, and snippets.

@mlist
Created August 22, 2017 08:49
Show Gist options
  • Save mlist/06915e72e5a0e03e2a2350509681f931 to your computer and use it in GitHub Desktop.
Save mlist/06915e72e5a0e03e2a2350509681f931 to your computer and use it in GitHub Desktop.
function for reading gmt files as data frames with 1st column gene set id, 2nd column gene id.
library(foreach)
library(stringr)
library(biomaRt)
read_gmt <- function(gmt_file){
conn <- file(gmt_file,open="r")
all_lines <-readLines(conn)
result <- foreach(line = str_split(all_lines, "\t"), .combine = bind_rows) %do% {
data_frame(id = line[1], gene_id = line[-c(1,2)])
}
close(conn)
return(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment