Semblance / scripts /build_descriptions.R
yueyvettehao's picture
Upload full app (app.py + core/agents/mcp_server/ui/assets/examples/...)
fb2ae51 verified
Raw
History Blame Contribute Delete
1.63 kB
# Offline: MSigDB Hallmark gene-set descriptions -> assets/pathway_descriptions.json
#
# This is the documented R/msigdbr regeneration path (the author already has the R stack).
# The committed assets/pathway_descriptions.json is produced equivalently by the offline-friendly
# Python path (scripts/_hallmark_descriptions.py + scripts/build_embeddings.py) so the build needs
# no R. Use this script to regenerate or extend to other collections (C2:CP:REACTOME, C5:GO:BP).
#
# Usage: Rscript scripts/build_descriptions.R
# Deps: install.packages(c("msigdbr", "jsonlite", "dplyr"))
#
# MSigDB is free under CC-BY 4.0 — attribute the Broad Institute.
suppressPackageStartupMessages({
library(msigdbr)
library(dplyr)
library(jsonlite)
})
collections <- list(
list(category = "H", subcategory = NULL) # Hallmark (50 sets)
# , list(category = "C2", subcategory = "CP:REACTOME") # add as needed
# , list(category = "C5", subcategory = "GO:BP")
)
desc <- list()
for (col in collections) {
sets <- msigdbr(species = "Homo sapiens",
category = col$category,
subcategory = col$subcategory)
# gs_name -> gs_description, one row per gene set
one <- sets %>%
distinct(gs_name, gs_description) %>%
filter(!is.na(gs_description) & gs_description != "")
for (i in seq_len(nrow(one))) {
desc[[ one$gs_name[i] ]] <- one$gs_description[i]
}
}
dir.create("assets", showWarnings = FALSE)
write_json(desc, "assets/pathway_descriptions.json", auto_unbox = TRUE, pretty = TRUE)
cat(sprintf("wrote assets/pathway_descriptions.json (%d gene sets)\n", length(desc)))