@@ -60,10 +60,8 @@ library(pheatmap)
60
60
library(gridExtra)
61
61
library(RColorBrewer)
62
62
library(viridis)
63
-
64
- library(CSCORE)
65
63
library(SAVER)
66
- library(Rmagic)
64
+ # library(Rmagic)
67
65
68
66
invisible(list2env(params, environment()))
69
67
source(project_file)
@@ -218,30 +216,32 @@ We compare three alternative methods of estimating expression levels to log norm
218
216
# Store output so we don't have to re-run imputation each time
219
217
filename <- glue("{path_outs}/imputed.RDS")
220
218
if (!file.exists(filename)) {
221
- # Get raw counts
222
- raw_rna <- LayerData( seurat, assay = "RNA", layer = "counts")
219
+ # Get raw counts (genes x cells matrix)
220
+ raw_rna <- as.matrix(GetAssayData( seurat[[ "RNA"]], slot = "counts") )
223
221
224
222
# SCT
225
223
# Re-run SCT on subset data
226
224
seurat <- SCTransform(seurat, return.only.var.genes = FALSE, min_cells = 1)
227
225
228
226
# Creating new seurat object for genes of interest only
229
- data_raw <- FetchData(seurat, assay = "RNA", layer = "counts", vars = corr_genes)
230
- data_rna <- FetchData(seurat, assay = "RNA", layer = "data", vars = corr_genes)
231
- data_sct <- FetchData(seurat, assay = "SCT", layer = "data", vars = corr_genes)
227
+ # Use GetAssayData to reliably extract counts/data (features x cells)
228
+ data_raw <- as.matrix(GetAssayData(seurat[["RNA"]], slot = "counts")[corr_genes, , drop = FALSE])
229
+ data_rna <- as.matrix(GetAssayData(seurat[["RNA"]], slot = "data")[corr_genes, , drop = FALSE])
230
+ data_sct <- as.matrix(GetAssayData(seurat[["SCT"]], slot = "data")[corr_genes, , drop = FALSE])
232
231
233
232
seurat_imputed <- CreateSeuratObject(
234
- counts = t( data_raw) ,
235
- data = t( data_rna) ,
233
+ counts = data_raw,
234
+ data = data_rna,
236
235
237
236
)
238
- seurat_imputed[["SCT"]] <- CreateAssayObject(data = t( data_sct) )
237
+ seurat_imputed[["SCT"]] <- CreateAssayObject(data = data_sct)
239
238
seurat_imputed[["RAW"]] <- CreateAssayObject(counts = raw_rna)
240
239
241
240
# Delete the original seurat object to save memory
242
241
rm(seurat)
243
242
244
243
data_magic <- magic(t(raw_rna), genes = corr_genes)$result
244
+ # magic returns cells x genes; transpose to features x cells
245
245
seurat_imputed[["MAGIC"]] <- CreateAssayObject(data = t(data_magic))
246
246
247
247
# SAVER
@@ -293,8 +293,7 @@ We have a few different ways to compute correlation scores with their associated
293
293
- ` SCTransform ` counts -> spearman correlation matrix
294
294
- ` MAGIC ` imputed -> spearman correlation matrix
295
295
- ` SAVER ` imputed -> spearman correlation matrix
296
- 2 . ` CS-CORE `
297
- - Raw RNA counts -> co-expression matrix
296
+ 2 . (removed) ` CS-CORE ` (this report no longer runs CS-CORE)
298
297
299
298
``` {r correlations}
300
299
# Store output so we don't have to re-run correlation each time
@@ -321,8 +320,15 @@ if (!file.exists(filename)) {
321
320
gene_2 <- genes_comb[idx, 2]
322
321
323
322
for (assay_ in assays) {
324
- gene_exp <- t(seurat_imputed[[assay_]]$data[c(gene_1, gene_2), ]) %>%
325
- as.data.frame()
323
+ # extract assay data safely (features x cells) and subset to the two genes
324
+ assay_mat <- tryCatch(as.matrix(GetAssayData(seurat_imputed[[assay_]], slot = "data")), error = function(e) NULL)
325
+ if (is.null(assay_mat)) {
326
+ gene_exp <- data.frame()
327
+ } else {
328
+ sub_mat <- assay_mat[c(gene_1, gene_2), , drop = FALSE]
329
+ # transpose to cells x genes for cor.test
330
+ gene_exp <- as.data.frame(t(sub_mat))
331
+ }
326
332
327
333
if (all(gene_exp[[gene_1]] == 0) | all(gene_exp[[gene_2]] == 0)) {
328
334
corr_val <- 0.0
@@ -342,15 +348,7 @@ if (!file.exists(filename)) {
342
348
}
343
349
}
344
350
345
- # Run CS-CORE
346
- DefaultAssay(seurat_imputed) <- "RAW"
347
- CSCORE_result <- CSCORE(seurat_imputed, genes = corr_genes)
348
-
349
- # Store CS-CORE results
350
- tmp <- reshape2::melt(as.matrix(CSCORE_result$est)) %>% rename(CSCORE = value)
351
- df_corr <- left_join(df_corr, tmp)
352
- tmp <- reshape2::melt(as.matrix(CSCORE_result$p_value)) %>% rename(CSCORE = value)
353
- df_p_val <- left_join(df_p_val, tmp)
351
+ # CS-CORE removed: no additional co-expression estimates are appended here
354
352
355
353
# Save output
356
354
write.csv(df_corr, filename)
@@ -367,7 +365,7 @@ Showing the patterns of correlation for each method. The x-axis and y-axis are t
367
365
368
366
``` {r visualize-cors}
369
367
#| fig-width: 7
370
- methods <- c("RNA", "SCT", "MAGIC", "SAVER", "CSCORE" )
368
+ methods <- c("RNA", "SCT", "MAGIC", "SAVER")
371
369
372
370
cor_List <- purrr::map(methods, \(method){
373
371
corr <- df_corr[c("Var1", "Var2", method)]
@@ -381,9 +379,6 @@ cor_List <- purrr::map(methods, \(method){
381
379
382
380
breaks <- seq(-1, 1, by = 0.1)
383
381
show_legend <- F
384
- if (method == "CSCORE") {
385
- show_legend <- T
386
- }
387
382
p <- pheatmap(mtx,
388
383
color = inferno(10),
389
384
show_rownames = FALSE,
@@ -410,7 +405,7 @@ In these scatterplots, the gene-pairs that are colored red have different result
410
405
``` {r cor-compare}
411
406
#| fig-width: 3
412
407
#| fig-height: 8
413
- methods <- c("MAGIC", "SAVER", "CSCORE" )
408
+ methods <- c("MAGIC", "SAVER")
414
409
methods_comb <- data.frame(t(combn(methods, 2)))
415
410
plot_list <- list()
416
411
@@ -460,3 +455,4 @@ List and version of tools used for the QC report generation.
460
455
``` {r}
461
456
sessionInfo()
462
457
```
458
+
0 commit comments