vignettes/visium_cytassist_human_glioblastoma.Rmd
visium_cytassist_human_glioblastoma.Rmd
The Human glioblastoma (FFPE) dataset was obtained from 10x Genomics. The tissue was sectioned as described in Visium CytAssist Spatial Gene Expression for FFPE – Tissue Preparation Guide Demonstrated Protocol (CG000518). 5 µm tissue sections were placed on Superfrost glass slides, then IF stained following deparaffinization, then hard coverslipped. Sections were imaged, decoverslipped, followed by Demonstrated Protocol (CG000494).
More information about this dataset can be found here.
dir.create("data")
download.file(url = "https://cf.10xgenomics.com/samples/spatial-exp/2.1.0/CytAssist_FFPE_Protein_Expression_Human_Glioblastoma/CytAssist_FFPE_Protein_Expression_Human_Glioblastoma_raw_feature_bc_matrix.tar.gz",
destfile = "data/CytAssist_FFPE_Protein_Expression_Human_Glioblastoma_raw_feature_bc_matrix.tar.gz")
download.file(url = "https://cf.10xgenomics.com/samples/spatial-exp/2.1.0/CytAssist_FFPE_Protein_Expression_Human_Glioblastoma/CytAssist_FFPE_Protein_Expression_Human_Glioblastoma_spatial.tar.gz",
destfile = "data/CytAssist_FFPE_Protein_Expression_Human_Glioblastoma_spatial.tar.gz")
untar("data/CytAssist_FFPE_Protein_Expression_Human_Glioblastoma_raw_feature_bc_matrix.tar.gz",
exdir = "data")
untar("data/CytAssist_FFPE_Protein_Expression_Human_Glioblastoma_spatial.tar.gz",
exdir = "data")
# Ensure Giotto Suite is installed
if(!"Giotto" %in% installed.packages()) {
pak::pkg_install("drieslab/Giotto")
}
# Ensure the Python environment for Giotto has been installed
genv_exists <- Giotto::checkGiottoEnvironment()
if(!genv_exists){
# The following command need only be run once to install the Giotto environment
Giotto::installGiottoEnvironment()
}
library(Giotto)
# 1. set results directory
results_folder <- "/path/to/results/"
# 2. set giotto python path
# set python path to your preferred python version path
# set python path to NULL if you want to automatically install (only the 1st time) and use the giotto miniconda environment
python_path <- NULL
# 3. create giotto instructions
instructions <- createGiottoInstructions(save_dir = results_folder,
save_plot = TRUE,
show_plot = FALSE,
return_plot = FALSE,
python_path = python_path)
The minimum requirements are
createGiottoVisiumObject() will automatically detect both rna and protein modalities within the expression matrix creating a multi-omics Giotto object.
# Provide path to visium folder
data_path <- "/path/to/data/"
# Create Giotto object
visium <- createGiottoVisiumObject(visium_dir = data_path,
expr_data = "raw",
png_name = "tissue_lowres_image.png",
gene_column_index = 2,
instructions = instructions)
How to work with Giotto instructions that are part of your Giotto object:
# show instructions associated with the giotto object
showGiottoInstructions(visium)
# Subset on spots that were covered by tissue
metadata <- pDataDT(visium)
in_tissue_barcodes <- metadata[in_tissue == 1]$cell_ID
visium <- subsetGiotto(visium,
cell_ids = in_tissue_barcodes)
## Visualize aligned tissue
spatPlot2D(gobject = visium,
point_alpha = 0.7)
# Filtering, normalization, and statistics
## RNA feature
visium <- filterGiotto(gobject = visium,
expression_threshold = 1,
feat_det_in_min_cells = 50,
min_det_feats_per_cell = 1000,
expression_values = "raw",
verbose = TRUE)
visium <- normalizeGiotto(gobject = visium,
scalefactor = 6000,
verbose = TRUE)
visium <- addStatistics(gobject = visium)
### Visualize number of features after processing
spatPlot2D(gobject = visium,
point_alpha = 0.7,
cell_color = "nr_feats",
color_as_factor = FALSE)
## Protein feature
visium <- filterGiotto(gobject = visium,
spat_unit = "cell",
feat_type = "protein",
expression_threshold = 1,
feat_det_in_min_cells = 50,
min_det_feats_per_cell = 1,
expression_values = "raw",
verbose = TRUE)
visium <- normalizeGiotto(gobject = visium,
spat_unit = "cell",
feat_type = "protein",
scalefactor = 6000,
verbose = TRUE)
visium <- addStatistics(gobject = visium,
spat_unit = "cell",
feat_type = "protein")
### Visualize number of features after processing
spatPlot2D(gobject = visium,
spat_unit = "cell",
feat_type = "protein",
point_alpha = 0.7,
cell_color = "nr_feats",
color_as_factor = FALSE)
# Identify highly variable features (HVF)
visium <- calculateHVF(gobject = visium)
### Visualize RNA PCA
plotPCA(gobject = visium)
## Protein
visium <- runPCA(gobject = visium,
spat_unit = "cell",
feat_type = "protein")
screePlot(visium,
spat_unit = "cell",
feat_type = "protein",
ncp = 30)
### Visualize Protein PCA
plotPCA(gobject = visium,
spat_unit = "cell",
feat_type = "protein")
# cluster and run UMAP
# sNN network (default)
## RNA feature
visium <- createNearestNetwork(gobject = visium,
dimensions_to_use = 1:10,
k = 30)
## Protein feature
visium <- createNearestNetwork(gobject = visium,
spat_unit = "cell",
feat_type = "protein",
dimensions_to_use = 1:10,
k = 30)
# Leiden clustering
## RNA feature
visium <- doLeidenCluster(gobject = visium,
resolution = 1,
n_iterations = 1000)
## Protein feature
visium <- doLeidenCluster(gobject = visium,
spat_unit = "cell",
feat_type = "protein",
resolution = 1,
n_iterations = 1000)
# UMAP
## RNA feature
visium <- runUMAP(visium,
dimensions_to_use = 1:10)
plotUMAP(gobject = visium,
cell_color = "leiden_clus",
show_NN_network = TRUE,
point_size = 2)
## Protein feature
visium <- runUMAP(visium,
spat_unit = "cell",
feat_type = "protein",
dimensions_to_use = 1:10)
plotUMAP(gobject = visium,
spat_unit = "cell",
feat_type = "protein",
cell_color = "leiden_clus",
show_NN_network = TRUE,
point_size = 2)
# Visualize spatial plot
## RNA feature
spatPlot2D(gobject = visium,
show_image = TRUE,
cell_color = "leiden_clus",
point_size = 2)
## Protein feature
spatPlot2D(gobject = visium,
spat_unit = "cell",
feat_type = "protein",
show_image = TRUE,
cell_color = "leiden_clus",
point_size = 2)
The Weighted Nearest Neighbors allows to integrate two or more modalities acquired from the same sample. WNN will re-calculate the clustering to provide an integrated umap and leiden clustering. For running WNN, the Giotto object must contain the results of running PCA calculation for each modality.
# Calculate kNN
## RNA modality
visium <- createNearestNetwork(gobject = visium,
type = "kNN",
dimensions_to_use = 1:10,
k = 20)
## Protein modality
visium <- createNearestNetwork(gobject = visium,
spat_unit = "cell",
feat_type = "protein",
type = "kNN",
dimensions_to_use = 1:10,
k = 20)
# Run WNN
visium <- runWNN(visium,
spat_unit = "cell",
feat_types = c("rna", "protein"),
reduction_methods = c("pca", "pca"),
reduction_names = c("pca", "protein.pca"),
k = 20,
verbose = TRUE)
# Run Integrated umap
visium <- runIntegratedUMAP(visium,
feat_types = c("rna", "protein"),
force = FALSE)
# Calculate integrated clusters
visium <- doLeidenCluster(gobject = visium,
spat_unit = "cell",
feat_type = "rna",
nn_network_to_use = "kNN",
network_name = "integrated_kNN",
name = "integrated_leiden_clus",
resolution = 0.5)
# Visualize integrated umap
plotUMAP(gobject = visium,
spat_unit = "cell",
feat_type = "rna",
cell_color = "integrated_leiden_clus",
dim_reduction_name = "integrated.umap",
point_size = 1.5,
title = "Integrated UMAP using Integrated Leiden clusters",
axis_title = 12,
axis_text = 10 )
# Visualize spatial plot with integrated clusters
spatPlot2D(visium,
spat_unit = "cell",
feat_type = "rna",
cell_color = "integrated_leiden_clus",
point_size = 2,
show_image = FALSE,
title = "Integrated Leiden clustering")
4.4.1 (2024-06-14)
R version : x86_64-apple-darwin20
Platform: macOS 15.0
Running under
: default
Matrix products: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
BLAS: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
LAPACK
:
locale1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
[
: America/New_York
time zone: internal
tzcode source
:
attached base packages1] stats graphics grDevices utils datasets methods base
[
:
other attached packages1] Giotto_4.1.3 GiottoClass_0.4.0
[
namespace (and not attached):
loaded via a [1] colorRamp2_0.1.0 deldir_2.0-4 rlang_1.1.4
4] magrittr_2.0.3 RcppAnnoy_0.0.22 GiottoUtils_0.1.12
[7] matrixStats_1.4.1 compiler_4.4.1 png_0.1-8
[10] systemfonts_1.1.0 vctrs_0.6.5 pkgconfig_2.0.3
[13] SpatialExperiment_1.14.0 crayon_1.5.3 fastmap_1.2.0
[16] backports_1.5.0 magick_2.8.5 XVector_0.44.0
[19] labeling_0.4.3 utf8_1.2.4 rmarkdown_2.28
[22] UCSC.utils_1.0.0 ragg_1.3.3 purrr_1.0.2
[25] xfun_0.47 beachmat_2.20.0 zlibbioc_1.50.0
[28] GenomeInfoDb_1.40.1 jsonlite_1.8.9 DelayedArray_0.30.1
[31] BiocParallel_1.38.0 terra_1.7-78 irlba_2.3.5.1
[34] parallel_4.4.1 R6_2.5.1 RColorBrewer_1.1-3
[37] reticulate_1.39.0 parallelly_1.38.0 GenomicRanges_1.56.1
[40] scattermore_1.2 Rcpp_1.0.13 SummarizedExperiment_1.34.0
[43] knitr_1.48 future.apply_1.11.2 R.utils_2.12.3
[46] IRanges_2.38.1 Matrix_1.7-0 igraph_2.0.3
[49] tidyselect_1.2.1 rstudioapi_0.16.0 abind_1.4-8
[52] yaml_2.3.10 codetools_0.2-20 listenv_0.9.1
[55] lattice_0.22-6 tibble_3.2.1 Biobase_2.64.0
[58] withr_3.0.1 evaluate_1.0.0 future_1.34.0
[61] pillar_1.9.0 MatrixGenerics_1.16.0 checkmate_2.3.2
[64] stats4_4.4.1 plotly_4.10.4 generics_0.1.3
[67] dbscan_1.2-0 sp_2.1-4 S4Vectors_0.42.1
[70] ggplot2_3.5.1 munsell_0.5.1 scales_1.3.0
[73] gtools_3.9.5 globals_0.16.3 glue_1.7.0
[76] lazyeval_0.2.2 tools_4.4.1 GiottoVisuals_0.2.5
[79] data.table_1.16.0 ScaledMatrix_1.12.0 cowplot_1.1.3
[82] grid_4.4.1 tidyr_1.3.1 colorspace_2.1-1
[85] SingleCellExperiment_1.26.0 GenomeInfoDbData_1.2.12 BiocSingular_1.20.0
[88] rsvd_1.0.5 cli_3.6.3 textshaping_0.4.0
[91] fansi_1.0.6 S4Arrays_1.4.1 viridisLite_0.4.2
[94] dplyr_1.1.4 uwot_0.2.2 gtable_0.3.5
[97] R.methodsS3_1.8.2 digest_0.6.37 BiocGenerics_0.50.0
[100] SparseArray_1.4.8 ggrepel_0.9.6 rjson_0.2.23
[103] htmlwidgets_1.6.4 farver_2.1.2 htmltools_0.5.8.1
[106] R.oo_1.26.0 lifecycle_1.0.4 httr_1.4.7 [