Skip to content

Instantly share code, notes, and snippets.

@millerh1
Created January 21, 2022 15:51
Show Gist options
  • Save millerh1/2fbd127d5575cce5d99ffab6b3029f19 to your computer and use it in GitHub Desktop.
Save millerh1/2fbd127d5575cce5d99ffab6b3029f19 to your computer and use it in GitHub Desktop.
Gene set membership matrix generator
library(msigdbr)
library(dplyr)
msigdbr(category = "C8") %>%
dplyr::select(gs_name, gene_symbol) %>%
distinct(gs_name, gene_symbol) %>%
mutate(val = 1) %>%
pivot_wider(
id_cols = gs_name, names_from = gene_symbol,
values_from = val,
values_fill = 0
) %>%
tibble::column_to_rownames("gs_name")
@millerh1
Copy link
Author

This will create a data.frame where rownames are gene sets and columns are gene symbols. Change the arguments in msigdbr() in order to change the species and the gene sets.

@millerh1
Copy link
Author

Values are 0 or 1 depending on membership of each gene in each gene set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment