Code
library(reticulate)
library(Seurat)
library(CellChat)
use_condaenv("/path/to/conda/envs/single_cell/") # path to a conda environment with scanpy installed
sc <- import("scanpy")
dir.create("outputs", showWarnings = F, recursive = T)Here we project the Fibro2/Fibro3 fibroblast signatures, defined from our Visium spatial transcriptomics data, onto an independent, publicly available CosMx dataset from Shiau and colleagues, 2024, Nat Genetics. Cell segmentation was used as described in the original study. Although this CosMx dataset includes both treatment-naive and treated samples, we only included the treatment-naive samples in our analysis.
Data is downloaded from Mendeley Data here, and stored in the data directory.
data <- sc$read_h5ad("data/PDAC-SMI and co-culture dataset/SMI/raw_meta_data_final.h5ad")
metadata <- data$obs
rownames(metadata) <- data$obs_names$to_list()
ct_mtx <- t(data$X)
colnames(ct_mtx) <- data$obs_names$to_list()
rownames(ct_mtx) <- data$var_names$to_list()
seurat <- CreateSeuratObject(counts = ct_mtx, meta.data = metadata)
untreated_samples <- seurat[, seurat$sample_id %in% grep("U", unique(seurat$sample_id), value = T)]
qs::qsave(untreated_samples, "outputs/merged_untreated_samples.qs")
untreated_samples <- qs::qread("outputs/merged_untreated_samples.qs")The dataset includes two gene panels (960-plex and 990-plex probe sets). We restrict our analysis to the shared 960-plex panel so that all samples can be analyzed together.
plex960_samples <- untreated_samples[, colSums(is.na(GetAssayData(untreated_samples, layer = 'counts'))) == 30]
plex960_samples <- plex960_samples[!is.na(rowSums(GetAssayData(plex960_samples, layer = 'counts'))), ]
plex990_samples <- untreated_samples[, colSums(is.na(GetAssayData(untreated_samples, layer = 'counts'))) != 30]
extra_probes <- setdiff(rownames(plex990_samples), rownames(plex960_samples))
untreated_samples <- untreated_samples[rownames(plex960_samples), ]
untreated_samples <- NormalizeData(untreated_samples)
untreated_samples <- ScaleData(untreated_samples)We use the differentially expressed genes (adjusted p < 0.05, log2 fold-change > 0.5) between the Fibro2 and Fibro3 spatial domains, defined in our Visium fibroblast pseudobulk analysis, intersected with the genes available in the CosMx panel, to build Fibro2 and Fibro3 signatures. We then score these signatures per cell using UCell and scale the scores to a 0-1 range.
fibro2_v_fibro3_DEGs <- read.csv("../outputs/Fibroblasts_Analysis/stroma2_v_stroma3_DEGs.csv", row.names = 1)
fibro2_sig <- fibro2_v_fibro3_DEGs %>%
filter(padj < 0.05 & log2FoldChange > 0.5) %>%
rownames() %>%
intersect(rownames(untreated_samples))
fibro3_sig <- fibro2_v_fibro3_DEGs %>%
filter(padj < 0.05 & log2FoldChange < -0.5) %>%
rownames() %>%
intersect(rownames(untreated_samples))
fibro <- subset(untreated_samples, subset = annotation_majortypes == 'CAF')
fibro <- AddModuleScore_UCell(fibro,
features = list(fibro3_sig = fibro3_sig, fibro2_sig = fibro2_sig),
ncores = parallel::detectCores())
fibro@meta.data <- mutate(fibro@meta.data,
fibro2_score_scaled = (fibro2_sig_UCell - min(fibro2_sig_UCell)) / (max(fibro2_sig_UCell) - min(fibro2_sig_UCell)),
fibro3_score_scaled = (fibro3_sig_UCell - min(fibro3_sig_UCell)) / (max(fibro3_sig_UCell) - min(fibro3_sig_UCell)))
qs::qsave(fibro, "outputs/fibro_w_F2F3_scores.qs")