|
| 1 | +# Example usage of msigdf package with improved and parallel code for human and mouse data |
| 2 | + |
| 3 | +library(tidyverse) |
| 4 | +library(msigdf) |
| 5 | + |
| 6 | +# Show first few rows for both human and mouse gene sets |
| 7 | +msigdf.human %>% slice_head(n = 5) |
| 8 | +msigdf.mouse %>% slice_head(n = 5) |
| 9 | + |
| 10 | +# Filter for a specific KEGG pathway in both human and mouse |
| 11 | +msigdf.human %>% |
| 12 | + filter(geneset == "KEGG_NON_HOMOLOGOUS_END_JOINING") |
| 13 | + |
| 14 | +msigdf.mouse %>% |
| 15 | + filter(geneset == "KEGG_NON_HOMOLOGOUS_END_JOINING") |
| 16 | + |
| 17 | +# Get gene symbols as a named list for Hallmark sets (human) and for mouse |
| 18 | +human_hallmark <- msigdf.human %>% |
| 19 | + filter(category_code == "hallmark") %>% |
| 20 | + select(geneset, symbol) %>% |
| 21 | + group_by(geneset) %>% |
| 22 | + summarize(symbols = list(symbol), .groups = "drop") %>% |
| 23 | + deframe() |
| 24 | + |
| 25 | +mouse_hallmark <- msigdf.mouse %>% |
| 26 | + filter(category_code == "hallmark") %>% |
| 27 | + select(geneset, symbol) %>% |
| 28 | + group_by(geneset) %>% |
| 29 | + summarize(symbols = list(symbol), .groups = "drop") %>% |
| 30 | + deframe() |
| 31 | + |
| 32 | +# Show first 3 gene sets and their first 3 symbols |
| 33 | +purrr::map(human_hallmark[1:3], head, 3) |
| 34 | +purrr::map(mouse_hallmark[1:3], head, 3) |
| 35 | + |
| 36 | +# Count gene sets by collection and sub-collection for both species |
| 37 | +msigdf.human %>% |
| 38 | + count(category_code, category_subcode, sort = TRUE) |
| 39 | + |
| 40 | +msigdf.mouse %>% |
| 41 | + count(category_code, category_subcode, sort = TRUE) |
| 42 | + |
| 43 | +# Join with URLs for a specific hallmark set (Notch signaling) in human and mouse |
| 44 | +human_notch_url <- msigdf.human %>% |
| 45 | + filter(geneset == "HALLMARK_NOTCH_SIGNALING") %>% |
| 46 | + distinct(geneset) %>% |
| 47 | + left_join(msigdf.urls, by = "geneset") %>% |
| 48 | + pull(url) |
| 49 | + |
| 50 | +mouse_notch_url <- msigdf.mouse %>% |
| 51 | + filter(geneset == "HALLMARK_NOTCH_SIGNALING") %>% |
| 52 | + distinct(geneset) %>% |
| 53 | + left_join(msigdf.mouse.urls, by = "geneset") %>% |
| 54 | + pull(url) |
| 55 | + |
| 56 | +# Print URLs |
| 57 | +print(human_notch_url) |
| 58 | +print(mouse_notch_url) |
| 59 | + |
| 60 | +# List KEGG pathways sorted by number of genes (human and mouse) |
| 61 | +msigdf.human %>% |
| 62 | + filter(category_code == "c2", str_starts(geneset, "KEGG_")) %>% |
| 63 | + count(geneset, sort = TRUE) |
| 64 | + |
| 65 | +msigdf.mouse %>% |
| 66 | + filter(category_code == "m2", str_starts(geneset, "KEGG_")) %>% |
| 67 | + count(geneset, sort = TRUE) |
0 commit comments