Required packages to be installed:
if (!require("devtools", quietly = TRUE))
install.packages("BiocManager")
devtools::install_github("ctlab/GAMclust")
devtools::install_github("ctlab/gatom")
devtools::install_github("ctlab/mwcsr")
devtools::install_github("ctlab/fgsea")
library(GAMclust)
library(gatom)
library(mwcsr)
library(fgsea)
library(data.table)
library(Seurat)
set.seed(42)
First, please load and initialize all objects required for GAM-clustering analysis:
network.kegg.rds
and its metabolites annotation met.kegg.db.rds;network <- readRDS(url("http://artyomovlab.wustl.edu/publications/supp_materials/GATOM/network.kegg.rds"))
metabolites.annotation <- readRDS(url("http://artyomovlab.wustl.edu/publications/supp_materials/GATOM/met.kegg.db.rds"))
org.Hs.eg.gatom.anno
for human data or org.Mm.eg.gatom.anno
for mouse data;network.annotation <- readRDS(url("http://artyomovlab.wustl.edu/publications/supp_materials/GATOM/org.Hs.eg.gatom.anno.rds"))
met.to.filter <- data.table::fread(system.file("mets2mask.lst", package="GAMclust"))$ID
(4.1.) we recommend to use here either heuristic relax-and-cut solver
rnc_solver from mwcsr
package,
solver <- mwcsr::rnc_solver()
(4.2.) either proprietary CPLEX solver (free for academy);
cplex.dir <- "/opt/ibm/ILOG/CPLEX_Studio1271"
solver <- mwcsr::virgo_solver(cplex_dir = cplex.dir)
work.dir <- "results"
dir.create(work.dir, showWarnings = F, recursive = T)
stats.dir <- paste0(work.dir, "/stats")
dir.create(stats.dir, showWarnings = F, recursive = T)
log_file <- file(paste0(stats.dir, "/log.txt"), open = "wt")
sink(log_file, type = "output", append = TRUE)
sink(log_file, type = "message", append = TRUE)
GAMclust works with bulk, single cell and spatial RNA-seq data.
This vignette shows how to process spatial RNA-seq data.
Let’s load the data and take 10,000 genes for the GAM-clustering analysis.
seurat_object <- readRDS(url("http://artyomovlab.wustl.edu/publications/supp_materials/GAMclust/275_T_seurat.rds"))
seurat_object <- Seurat::SCTransform(seurat_object,
assay = "Spatial",
variable.features.n = 10000,
verbose = FALSE)
E <- as.matrix(Seurat::GetAssayData(object = seurat_object,
assay = "SCT",
slot = "scale.data"))
nrow(E) # ! make sure this value is in range from 6,000 to 12,000
# [1] 10000
E[1:3, 1:3]
# AAACAAGTATCTCCCA-1 AAACACCAATAACTGC-1 AAACAGAGCGACTCCT-1
# NOC2L 1.2429330 0.8244317 3.6945664
# ISG15 2.6233759 -0.7541004 0.5605173
# AGRN -0.6149024 -0.7259493 0.5248512
Genes in your dataset may be named as Symbol, Entrez, Ensembl or
RefSeq IDs. One of these names should be specified as value of
gene.id.type parameter in prepareData().
If you analyse singe cell or spatial RNA-seq data, please set
use.PCA=TRUE in prepareData().
E.prep <- prepareData(E = E,
gene.id.type = "Symbol",
use.PCA = TRUE,
use.PCA.n = 50,
network.annotation = network.annotation)
E.prep[1:3, 1:3]
# PC1 PC2 PC3
# 885 4.977872 -3.7994982 0.8635909
# 4504 -6.323743 -2.5276675 0.5063040
# 9569 -1.237742 -0.6967359 -0.3546444
The prepareNetwork() function defines the structure of
the final metabolic modules.
network.prep <- prepareNetwork(E = E.prep,
network = network,
met.to.filter = met.to.filter,
network.annotation = network.annotation)
# > Global metabolite network contains 4214 edges.
# > Largest connected component of this global network contains 1062 nodes and 3516 edges.
The preClustering() function defines initial patterns
using k-medoids clustering on gene expression matrix. It is strongly
recommended to do initial clustering with no less than 32 clusters
(initial.number.of.clusters = 32).
You can visualize the initial heatmap as shown below.
cur.centers <- preClustering(E.prep = E.prep,
network.prep = network.prep,
initial.number.of.clusters = 32,
network.annotation = network.annotation)
# > 836 metabolic genes from the analysed dataset mapped to this component.
cur.centers[1:3, 1:3]
# PC1 PC2 PC3
# 1 2.2339275 1.394434 -0.9111931
# 2 -0.4371787 1.349472 1.7452293
# 3 1.0833861 1.046135 0.6386994
pheatmap::pheatmap(
GAMclust:::normalize.rows(cur.centers),
cluster_rows=F, cluster_cols=F,
show_rownames=F, show_colnames=T)
Now you have everything prepared for the GAM-clustering analysis.
Initial patterns will be now refined in an iterative process. The
output of gamClustering() function presents a set of
specific subnetworks (also called metabolic modules) that reflect
metabolic variability within a given transcriptional dataset.
Note, that it may take a long time to derive metabolic modules by
gamClustering() function (tens of minutes).
There is a set of parameters which determine the size and number of your final modules. We recommend you to start with the default settings, however you can adjust them based on your own preferences:
If you consider final modules to bee too small or too big and it
complicates interpretation for you, you can either increase or reduce by
10 units the max.module.size parameter.
If among final modules you consider presence of any modules with
too similar patterns, you can reduce by 0.1 units the
cor.threshold parameter.
If among final modules you consider presence of any uninformative
modules, you can reduce by 10 times the p.adj.val.threshold
parameter.
results <- gamClustering(E.prep = E.prep,
network.prep = network.prep,
cur.centers = cur.centers,
start.base = 0.5,
base.dec = 0.05,
max.module.size = 50,
cor.threshold = 0.6,
p.adj.val.threshold = 1e-5,
batch.solver = seq_batch_solver(solver),
work.dir = work.dir,
show.intermediate.clustering = FALSE,
verbose = FALSE,
collect.stats = TRUE)
Each metabolic module is a connected piece of metabolic network whose genes expression is correlated across all dataset.
The following functions will help you to visualize and explore the obtained results.
getGraphs(modules = results$modules,
network.annotation = network.annotation,
metabolites.annotation = metabolites.annotation,
seed.for.layout = 42,
work.dir = work.dir)
# Graphs for module 1 are built
# Graphs for module 2 are built
# Graphs for module 3 are built
# Graphs for module 4 are built
Example of the graph of the fourth module:
The table contains gene list. Each gene has two descriptive values: i) gene’s correlation value with the modules pattern and ii) gene’s score. High score means that this gene’s expression is similar to the module’s pattern and not similar to other modules’ patterns.
m.gene.list <- getGeneTables(modules = results$modules,
nets = results$nets,
patterns = results$patterns.pos,
gene.exprs = E.prep,
network.annotation = network.annotation,
work.dir = work.dir)
# Gene tables for module 1 are produced
# Gene tables for module 2 are produced
# Gene tables for module 3 are produced
# Gene tables for module 4 are produced
Example of the gene table of the fourth module:
head(GAMclust:::read.tsv(paste0(work.dir, "/m.4.genes.tsv")))
for(i in 1:length(m.gene.list)){
plot(fgsea::plotCoregulationProfileSpatial(m.gene.list[[i]],
seurat_object,
title = paste0("module ", i)))
}
Seurat::DefaultAssay(seurat_object) <- "SCT"
i <- 4
Seurat::SpatialFeaturePlot(seurat_object,
features = m.gene.list[[i]],
ncol = 8)