Sources: chapters on normalisation in the OSCA book and the ‘Hemberg group material’.
Why normalise?
Systematic differences in sequencing coverage between libraries occur because of low input material, differences in cDNA capture and PCR amplification. Normalisation removes such differences so that differences between cells are not technical but biological, allowing meaningful comparison of expression profiles between cells. Normalisation and batch correction have different aims. Normalisation addresses technical differences only, while batch correction considers both technical and biological differences.
qcPlotDirBit <- "NormPlots"
setName <- "GSM3872434"
Load object
projDir <- "/home/ubuntu/Course_Materials/scRNAseq"
outDirBit <- "AnaWiSce/Attempt1"
setSuf <- ""
if(setName == "hca") {setSuf <- "_5kCellPerSpl"}
# Read object in:
tmpFn <- sprintf("%s/%s/Robjects/%s_sce_nz_postQc%s.Rds", projDir, outDirBit, "caron", setSuf)
print(tmpFn)
## [1] "/home/ubuntu/Course_Materials/scRNAseq/AnaWiSce/Attempt1/Robjects/caron_sce_nz_postQc.Rds"
if(!file.exists(tmpFn))
{
knitr::knit_exit()
}
sce <- readRDS(tmpFn)
sce
## class: SingleCellExperiment
## dim: 16642 20859
## metadata(0):
## assays(1): counts
## rownames(16642): ENSG00000237491 ENSG00000225880 ... ENSG00000275063
## ENSG00000271254
## rowData names(11): ensembl_gene_id external_gene_name ... detected
## gene_sparsity
## colnames: NULL
## colData names(20): Sample Barcode ... outlier cell_sparsity
## reducedDimNames(0):
## altExpNames(0):
Select cells for GSM3872434:
##setSuf <- "_5hCellPerSpl"
##nbCells <- 500
#setSuf <- "_1kCellPerSpl"
#nbCells <- 1000
setSuf <- "_GSM3872434"
##nbCells <- 500
# have new list of cell barcodes for each sample
sce.nz.master <- sce
vec.bc <- colData(sce.nz.master) %>%
data.frame() %>%
filter(Sample.Name == "GSM3872434") %>%
group_by(Sample.Name) %>%
##sample_n(nbCells) %>%
pull(Barcode)
Number of cells in the sample:
table(colData(sce.nz.master)$Barcode %in% vec.bc)
##
## FALSE TRUE
## 19019 1840
Subset cells from the SCE object:
tmpInd <- which(colData(sce.nz.master)$Barcode %in% vec.bc)
sce <- sce.nz.master[,tmpInd]
sce
## class: SingleCellExperiment
## dim: 16642 1840
## metadata(0):
## assays(1): counts
## rownames(16642): ENSG00000237491 ENSG00000225880 ... ENSG00000275063
## ENSG00000271254
## rowData names(11): ensembl_gene_id external_gene_name ... detected
## gene_sparsity
## colnames: NULL
## colData names(20): Sample Barcode ... outlier cell_sparsity
## reducedDimNames(0):
## altExpNames(0):
Check columns data:
head(colData(sce))
## DataFrame with 6 rows and 20 columns
## Sample
## <character>
## 1 /home/ubuntu/Course_Materials/scRNAseq/CaronBourque2020/grch38300/SRR9264343/SRR9264343/outs/filtered_feature_bc_matrix/
## 2 /home/ubuntu/Course_Materials/scRNAseq/CaronBourque2020/grch38300/SRR9264343/SRR9264343/outs/filtered_feature_bc_matrix/
## 3 /home/ubuntu/Course_Materials/scRNAseq/CaronBourque2020/grch38300/SRR9264343/SRR9264343/outs/filtered_feature_bc_matrix/
## 4 /home/ubuntu/Course_Materials/scRNAseq/CaronBourque2020/grch38300/SRR9264343/SRR9264343/outs/filtered_feature_bc_matrix/
## 5 /home/ubuntu/Course_Materials/scRNAseq/CaronBourque2020/grch38300/SRR9264343/SRR9264343/outs/filtered_feature_bc_matrix/
## 6 /home/ubuntu/Course_Materials/scRNAseq/CaronBourque2020/grch38300/SRR9264343/SRR9264343/outs/filtered_feature_bc_matrix/
## Barcode Run Sample.Name source_name sum detected
## <character> <character> <character> <factor> <numeric> <integer>
## 1 GTGCGGTAGACCCACC-1 SRR9264343 GSM3872434 ETV6-RUNX1 7558 2344
## 2 TTCTCAACATCCTTGC-1 SRR9264343 GSM3872434 ETV6-RUNX1 8803 2772
## 3 GTGCATACATTAGGCT-1 SRR9264343 GSM3872434 ETV6-RUNX1 6363 1949
## 4 TCAGCTCCATCACGAT-1 SRR9264343 GSM3872434 ETV6-RUNX1 7774 2475
## 5 AGATTGCAGCTGAAAT-1 SRR9264343 GSM3872434 ETV6-RUNX1 3968 1566
## 6 CCTCAGTAGTTTAGGA-1 SRR9264343 GSM3872434 ETV6-RUNX1 4141 1499
## percent_top_50 percent_top_100 percent_top_200 percent_top_500
## <numeric> <numeric> <numeric> <numeric>
## 1 28.8701 42.1937 54.4192 69.8730
## 2 32.2504 44.7007 54.7995 67.5906
## 3 40.0440 54.4712 64.0421 75.7190
## 4 34.7054 48.7137 59.0044 70.5686
## 5 35.5847 48.2107 59.1482 73.1351
## 6 35.7402 50.4950 61.5069 75.8754
## subsets_Mito_sum subsets_Mito_detected subsets_Mito_percent total
## <numeric> <integer> <numeric> <numeric>
## 1 250 12 3.30775 7558
## 2 455 13 5.16869 8803
## 3 431 12 6.77353 6363
## 4 560 12 7.20350 7774
## 5 311 12 7.83770 3968
## 6 146 11 3.52572 4141
## block setName discard outlier cell_sparsity
## <factor> <character> <logical> <logical> <numeric>
## 1 ETV6-RUNX1 Caron FALSE FALSE 0.868979
## 2 ETV6-RUNX1 Caron FALSE FALSE 0.845035
## 3 ETV6-RUNX1 Caron FALSE FALSE 0.891189
## 4 ETV6-RUNX1 Caron FALSE FALSE 0.861706
## 5 ETV6-RUNX1 Caron FALSE FALSE 0.912392
## 6 ETV6-RUNX1 Caron FALSE FALSE 0.916140
table(colData(sce)$Sample.Name)
##
## GSM3872434
## 1840
We write the R object to GSM3872434_sce_nz_postQc_GSM3872434.Rds.
# Write object to file
tmpFn <- sprintf("%s/%s/Robjects/%s_sce_nz_postQc%s.Rds", projDir, outDirBit, setName, setSuf)
saveRDS(sce, tmpFn)
# Write object to file
tmpFn <- sprintf("%s/%s/Robjects/%s_sce_nz_postQc%s.Rds", projDir, outDirBit, setName, setSuf)
sce <- readRDS(tmpFn)
In scaling normalization, the “normalization factor” is an estimate of the library size relative to the other cells. Steps usually include: computation of a cell-specific ‘scaling’ or ‘size’ factor that represents the relative bias in that cell and division of all counts for the cell by that factor to remove that bias. Assumption: any cell specific bias will affect genes the same way.
Scaling methods typically generate normalised counts-per-million (CPM) or transcripts-per-million (TPM) values that address the effect of sequencing depth. These values however typically have a variance that changes with their mean (heteroscedasticity) while most statistical methods assume a stable variance, which does not vary with the mean (homoscedasticity). A widely used ‘variance stabilising transformation’ is the log transformation (often log2). This works fine for highly expressed genes (as in bulk RNA-seq) but less so for sparse scRNA-seq data.
Convert raw counts to counts-per-million (CPM) for each cell by dividing counts by the library size then multiplying by 1.000.000. Mind that this does not adress compositional bias caused by highly expressed genes that are also differentially expressed between cells. In scater
CPMs are computed with the following code:
calc_cpm <- function (expr_mat, spikes = NULL)
{
norm_factor <- colSums(expr_mat[-spikes, ])
return(t(t(expr_mat)/norm_factor)) * 10^6
}
We will use scater
’s calculateCPM()
For each gene, compute geometric mean across cells. For each cell compute for each gene the ratio of its expression to its geometric mean, and derive the cell’s size factor as the median ratio across genes. Not suitable for sparse scRNA-seq data as the geometric is computed on non-zero values only. This method is also known as ‘Relative Log Expression’ (RLE) in edgeR
and scater
.
Example code:
calc_sf <- function (expr_mat, spikes = NULL)
{
geomeans <- exp(rowMeans(log(expr_mat[-spikes, ])))
SF <- function(cnts) {
median((cnts/geomeans)[(is.finite(geomeans) &
geomeans > 0)])
}
norm_factor <- apply(expr_mat[-spikes, ], 2, SF)
return(t(t(expr_mat)/norm_factor))
}
To compute weighted Trimmed mean of M-values (TMM), a given cell is chosen as a reference to use in computation for other cells. The M-values are gene-wise log2-fold changes between cells. Trimming entails the removal of the top and bottom 30% of values. The size factor is computed as the average for the remaining cells with a weight according to inverse variances. This method assumes that most genes are not differentially expressed, and the 40% of genes left after trimming may include many zero counts.
sizeFactors(sce) <- edgeR::calcNormFactors(counts(sce), method = "TMM")
For each cell, the library size factor is proportional to the library size such that the average size factor across cells is one.
Advantage: normalised counts are on the same scale as the initial counts.
Compute size factors:
lib.sf <- librarySizeFactors(sce)
summary(lib.sf)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0986 0.6708 0.9330 1.0000 1.2337 4.9729
Size factor distribution: wide range, typical of scRNA-seq data.
hist(log10(lib.sf), xlab="Log10[Size factor]", col='grey80')
Assumption: absence of compositional bias; differential expression between two cells is balanced: upregulation in some genes is accompanied by downregulation of other genes. Not observed.
Inaccurate normalisation due to unaccounted-for composition bias affects the size of the log fold change measured between clusters, but less so the clustering itself. It is thus sufficient to identify clusters and top marker genes.
Composition bias occurs when differential expression beteween two samples or here cells is not balanced. For a fixed library size, identical in both cells, upregulation of one gene in a cell will means fewer UMIs can be assigned to other genes, which would then appear down regulated. Even if library sizes are allowed to differ, with that for the cell with upregulation being higher, scaling normalisation will reduce normalised counts. Non-upregulated would therefore also appear downregulated.
For bulk RNA-seq, composition bias is removed by assuming that most genes are not differentially expressed between samples, so that differences in non-DE genes would amount to the bias, and used to compute size factors.
Given the sparsity of scRNA-seq data, the methods are not appropriate.
The method below increases read counts by pooling cells into groups, computing size factors within each of these groups and scaling them so they are comparable across clusters. This process is repeated many times, changing pools each time to collect several size factors for each cell, from which is derived a single value for that cell.
From the article.
Cluster cells then normalise.
set.seed(100) # clusters with PCA from irlba with approximation
clust <- quickCluster(sce) # slow with all cells.
# write to file
tmpFn <- sprintf("%s/%s/Robjects/%s_sce_nz_quickClus%s.Rds", projDir, outDirBit, setName, setSuf)
saveRDS(clust, tmpFn)
# read from file
tmpFn <- sprintf("%s/%s/Robjects/%s_sce_nz_quickClus%s.Rds", projDir, outDirBit, setName, setSuf)
clust <- readRDS(tmpFn)
table(clust)
## clust
## 1 2 3 4 5 6 7
## 423 199 123 241 382 251 221
#deconv.sf <- calculateSumFactors(sce, cluster=clust)
sce <- computeSumFactors(sce, cluster=clust, min.mean=0.1)
deconv.sf <- sizeFactors(sce)
# write to file
tmpFn <- sprintf("%s/%s/Robjects/%s_sce_nz_deconvSf%s.Rds", projDir, outDirBit, setName, setSuf)
saveRDS(deconv.sf, tmpFn)
# read from file
tmpFn <- sprintf("%s/%s/Robjects/%s_sce_nz_deconvSf%s.Rds", projDir, outDirBit, setName, setSuf)
deconv.sf <- readRDS(tmpFn)
summary(deconv.sf)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.02917 0.68042 0.93300 1.00000 1.22547 3.32086
Plot deconvolution size factors against library size factors:
deconvDf <- data.frame(lib.sf, deconv.sf,
"source_name" = sce$source_name,
"sum" = sce$sum,
"mito_content" = sce$subsets_Mito_percent,
"cell_sparsity" = sce$cell_sparsity)
sp <- ggplot(deconvDf, aes(x=lib.sf, y=deconv.sf, col=source_name)) +
geom_point()
# Split by sample type:
#sp + facet_wrap(~source_name)
sp <- ggplot(deconvDf, aes(x=lib.sf, y=deconv.sf, col=cell_sparsity)) +
geom_point()
sp
For each cell, raw counts for genes are divided by the size factor for that cell and log-transformed so downstream analyses focus on genes with strong relative differences. We use scater::logNormCounts()
.
sce <- logNormCounts(sce) # adds logcounts
print(assayNames(sce))
## [1] "counts" "logcounts"
# write to file
tmpFn <- sprintf("%s/%s/Robjects/%s_sce_nz_postDeconv%s.Rds", projDir, outDirBit, setName, setSuf)
saveRDS(sce, tmpFn)
sceDeconv <- sce
With scaling normalisation a correlation remains between the mean and variation of expression (heteroskedasticity). This affects downstream dimensionality reduction as the few main new dimensions are usually correlated with library size. SCTransform addresses the issue by regressing library size out of raw counts and providing residuals to use as normalized and variance-stabilized expression values in downstream analysis. We will use the sctransform vignette.
counts <- counts(sce)
print(class(counts))
## [1] "dgCMatrix"
## attr(,"package")
## [1] "Matrix"
print(dim(counts))
## [1] 16642 1840
colnames(counts) <- colData(sce)$Barcode
We will now calculate some properties and visually inspect the data. Our main interest is in the general trends not in individual outliers. Neither genes nor cells that stand out are important at this step, but we focus on the global trends.
Derive gene and cell attributes from the UMI matrix.
gene_attr <- data.frame(mean = rowMeans(counts),
detection_rate = rowMeans(counts > 0),
var = apply(counts, 1, var))
gene_attr$log_mean <- log10(gene_attr$mean)
gene_attr$log_var <- log10(gene_attr$var)
rownames(gene_attr) <- rownames(counts)
cell_attr <- data.frame(n_umi = colSums(counts),
n_gene = colSums(counts > 0))
rownames(cell_attr) <- colnames(counts)
dim(gene_attr)
## [1] 16642 5
head(gene_attr)
dim(cell_attr)
## [1] 1840 2
head(cell_attr)
Mean-variance relationship
For the genes, we can see that up to a mean UMI count of 0 the variance follows the line through the origin with slop one, i.e. variance and mean are roughly equal as expected under a Poisson model. However, genes with a higher average UMI count show overdispersion compared to Poisson.
ggplot(gene_attr, aes(log_mean, log_var)) +
geom_point(alpha=0.3, shape=16) +
geom_density_2d(size = 0.3) +
geom_abline(intercept = 0, slope = 1, color='red')
## Warning: Removed 1259 rows containing non-finite values (stat_density2d).
Mean-detection-rate relationship
In line with the previous plot, we see a lower than expected detection rate in the medium expression range. However, for the highly expressed genes, the rate is at or very close to 1.0 suggesting that there is no zero-inflation in the counts for those genes and that zero-inflation is a result of overdispersion, rather than an independent systematic bias.
# add the expected detection rate under Poisson model
x = seq(from = -3, to = 2, length.out = 1000)
poisson_model <- data.frame(log_mean = x, detection_rate = 1 - dpois(0, lambda = 10^x))
ggplot(gene_attr, aes(log_mean, detection_rate)) +
geom_point(alpha=0.3, shape=16) +
geom_line(data=poisson_model, color='red') +
theme_gray(base_size = 8)
“Based on the observations above, which are not unique to this particular data set, we propose to model the expression of each gene as a negative binomial random variable with a mean that depends on other variables. Here the other variables can be used to model the differences in sequencing depth between cells and are used as independent variables in a regression model. In order to avoid overfitting, we will first fit model parameters per gene, and then use the relationship between gene mean and parameter values to fit parameters, thereby combining information across genes. Given the fitted model parameters, we transform each observed UMI count into a Pearson residual which can be interpreted as the number of standard deviations an observed count was away from the expected mean. If the model accurately describes the mean-variance relationship and the dependency of mean and latent factors, then the result should have mean zero and a stable variance across the range of expression.” sctransform vignette.
Estimate model parameters and transform data
The vst function estimates model parameters and performs the variance stabilizing transformation. Here we use the log10 of the total UMI counts of a cell as variable for sequencing depth for each cell. After data transformation we plot the model parameters as a function of gene mean (geometric mean).
print(dim(counts))
## [1] 16642 1840
# We use the Future API for parallel processing; set parameters here
future::plan(strategy = 'multicore', workers = 4)
options(future.globals.maxSize = 10 * 1024 ^ 3)
set.seed(44)
vst_out <- sctransform::vst(counts, latent_var = c('log_umi'), return_gene_attr = TRUE, return_cell_attr = TRUE, show_progress = FALSE)
sctransform::plot_model_pars(vst_out)
Model:
print(vst_out$model_str)
## [1] "y ~ log_umi"
Inspect model
We will look at several genes in more detail.
#sctransform::plot_model(vst_out, counts, c('MALAT1', 'RPL10', 'FTL'), plot_residual = TRUE)
rowData(sce) %>% as.data.frame %>% filter(Symbol %in% c('MALAT1', 'RPL10', 'FTL'))
sctransform::plot_model(vst_out, counts, c('ENSG00000251562', 'ENSG00000147403', 'ENSG00000087086'), plot_residual = TRUE)
sctransform::plot_model(vst_out, counts, c('ENSG00000087086'), plot_residual = TRUE, show_nr = TRUE, arrange_vertical = FALSE)
Distribution of residual mean:
ggplot(vst_out$gene_attr, aes(residual_mean)) + geom_histogram(binwidth=0.01)
Distribution of residual variance:
ggplot(vst_out$gene_attr, aes(residual_variance)) + geom_histogram(binwidth=0.1) + geom_vline(xintercept=1, color='red') + xlim(0, 10)
## Warning: Removed 10 rows containing non-finite values (stat_bin).
## Warning: Removed 2 rows containing missing values (geom_bar).
Variance against mean (residuals):
ggplot(vst_out$gene_attr, aes(x=residual_mean, y=residual_variance)) +
geom_point(alpha=0.3, shape=16) +
xlim(0, 2.5) +
ylim(0, 10) +
geom_density_2d()
## Warning: Removed 3839 rows containing non-finite values (stat_density2d).
## Warning: Removed 3839 rows containing missing values (geom_point).
Variance against mean (genes):
ggplot(vst_out$gene_attr, aes(log10(gmean), residual_variance)) + geom_point(alpha=0.3, shape=16) +
geom_density_2d(size = 0.3)
Check genes with large residual variance:
dd <- head(round(vst_out$gene_attr[order(-vst_out$gene_attr$residual_variance), ], 2), 22)
dd %>% tibble::rownames_to_column("ensembl_gene_id") %>%
left_join(as.data.frame(rowData(sce))[,c("ensembl_gene_id", "Symbol")], "ensembl_gene_id")
Write outcome to file:
# write to file
tmpFn <- sprintf("%s/%s/Robjects/%s_sce_nz_vst_out%s.Rds", projDir, outDirBit, setName, setSuf)
saveRDS(vst_out, tmpFn)
Check transformed values:
print(dim(vst_out$y))
## [1] 13390 1840
vst_out$y[1:10,1:5]
## GTGCGGTAGACCCACC-1 TTCTCAACATCCTTGC-1 GTGCATACATTAGGCT-1
## ENSG00000237491 -0.22234869 -0.23782536 -0.20586571
## ENSG00000225880 4.64796328 -0.20855235 -0.18097742
## ENSG00000230368 -0.12223834 -0.13020902 -0.11373061
## ENSG00000230699 -0.06100904 -0.06526812 -0.05649558
## ENSG00000188976 0.90255722 2.13121468 1.09266463
## ENSG00000187961 -0.06700306 -0.07169313 -0.06203256
## ENSG00000188290 -0.09369749 -0.10004284 -0.08694930
## ENSG00000187608 0.78851527 0.63087912 -0.58970381
## ENSG00000188157 -0.07789773 -0.08334277 -0.07212415
## ENSG00000131591 -0.17411548 -0.18602999 -0.16142747
## TCAGCTCCATCACGAT-1 AGATTGCAGCTGAAAT-1
## ENSG00000237491 -0.22512167 -0.16631132
## ENSG00000225880 -0.19759386 -0.14679891
## ENSG00000230368 -0.12366755 -0.09319383
## ENSG00000230699 -0.06177054 -0.04573703
## ENSG00000188976 -0.61285764 -0.45042394
## ENSG00000187961 -0.06784165 -0.05018506
## ENSG00000188290 -0.09483361 -0.07076619
## ENSG00000187608 -0.64563492 -0.47411847
## ENSG00000188157 -0.07887151 -0.05835225
## ENSG00000131591 -0.17625003 -0.13095928
Genes that are expressed in fewer than 5 cells are not used and not returned, so to add vst_out$y as an assay we need to remove the missing genes.
# https://github.com/ChristophH/sctransform/issues/27
sceOrig <- sce
sceOrig
## class: SingleCellExperiment
## dim: 16642 1840
## metadata(0):
## assays(2): counts logcounts
## rownames(16642): ENSG00000237491 ENSG00000225880 ... ENSG00000275063
## ENSG00000271254
## rowData names(11): ensembl_gene_id external_gene_name ... detected
## gene_sparsity
## colnames: NULL
## colData names(21): Sample Barcode ... cell_sparsity sizeFactor
## reducedDimNames(0):
## altExpNames(0):
tmpInd <- which(rownames(sce) %in% rownames(vst_out$y))
cols.meta <- colData(sceOrig)
rows.meta <- rowData(sceOrig)
new.counts <- counts(sceOrig)[tmpInd, ]
sce <- SingleCellExperiment(list(counts=new.counts))
# reset the column data on the new object
colData(sce) <- cols.meta
rowData(sce) <- rows.meta[tmpInd, ]
assayNames(sce)
## [1] "counts"
sce
## class: SingleCellExperiment
## dim: 13390 1840
## metadata(0):
## assays(1): counts
## rownames(13390): ENSG00000237491 ENSG00000225880 ... ENSG00000278817
## ENSG00000271254
## rowData names(11): ensembl_gene_id external_gene_name ... detected
## gene_sparsity
## colnames: NULL
## colData names(21): Sample Barcode ... cell_sparsity sizeFactor
## reducedDimNames(0):
## altExpNames(0):
vstMat <- as(vst_out$y[rownames(sce),], "dgCMatrix")
all(colnames(vstMat) == sce$Barcode)
## [1] TRUE
colnames(vstMat) <- NULL
assay(sce, "sctrans_norm") <- vstMat # as(vst_out$y[rownames(sce),], "dgCMatrix")
#assayNames(sce)
# write to file
tmpFn <- sprintf("%s/%s/Robjects/%s_sce_nz_postSct%s.Rds", projDir, outDirBit, setName, setSuf)
saveRDS(sce, tmpFn)
typeNorm <- "logRaw"
#setSuf <- "_5kCellPerSpl"
options(BiocSingularParam.default=IrlbaParam())
assay(sce, "logcounts_raw") <- log2(counts(sce) + 1)
tmp <- runPCA(
sce[,],
exprs_values = "logcounts_raw"
)
PCA plot for the logRaw counts in the GSM3872434 set.
p <- plotPCA(
tmp,
colour_by = "Sample.Name",
size_by = "sum",
shape_by = "source_name"
) + ggtitle(sprintf("PCA plot: %s", typeNorm))
# write plot to file:
tmpFn <- sprintf("%s/%s/%s/%s_sce_nz_postQc%s_%sPca.png",
projDir, outDirBit, qcPlotDirBit, setName, setSuf, typeNorm)
ggsave(filename=tmpFn, plot=p)
## Saving 7 x 5 in image
knitr::include_graphics(tmpFn, auto_pdf = TRUE)
rm(tmpFn)
typeNorm <- "logCpm"
assay(sce, "logCpm") <- log2(calculateCPM(sce, size_factors = NULL) + 1)
logCpmPca <- runPCA(
sce[,],
exprs_values = "logCpm"
)
PCA plot for the logCpm counts in the GSM3872434 set.
p <- plotPCA(
logCpmPca,
colour_by = "Sample.Name",
size_by = "sum",
shape_by = "source_name"
) + ggtitle(sprintf("PCA plot: %s", typeNorm))
# write plot to file:
tmpFn <- sprintf("%s/%s/%s/%s_sce_nz_postQc%s_%sPca.png",
projDir, outDirBit, qcPlotDirBit, setName, setSuf, typeNorm)
ggsave(filename=tmpFn, plot=p)
## Saving 7 x 5 in image
knitr::include_graphics(tmpFn, auto_pdf = TRUE)
rm(tmpFn)
Normalised counts are stored in the ‘logcounts’ assay
typeNorm <- "scran"
# assay(sce, "logcounts")
scranPca <- runPCA(
sceDeconv[,],
exprs_values = "logcounts"
)
PCA plot for the ‘scran’ counts in the GSM3872434 set.
p <- plotPCA(
scranPca,
colour_by = "Sample.Name",
size_by = "sum",
shape_by = "source_name"
) + ggtitle(sprintf("PCA plot: %s", typeNorm))
# write plot to file:
tmpFn <- sprintf("%s/%s/%s/%s_sce_nz_postQc%s_%sPca.png",
projDir, outDirBit, qcPlotDirBit, setName, setSuf, typeNorm)
ggsave(filename=tmpFn, plot=p)
## Saving 7 x 5 in image
knitr::include_graphics(tmpFn, auto_pdf = TRUE)
rm(tmpFn)
TSNE plot for the ‘scran’ counts in the GSM3872434 set.
typeNorm <- "scran"
reducedDim(sceDeconv, "TSNE_scran") <- reducedDim(
runTSNE(sceDeconv, exprs_values = "logcounts"),
"TSNE"
)
p <- plotReducedDim(
sceDeconv,
dimred = "TSNE_scran",
colour_by = "Sample.Name",
size_by = "sum",
shape_by = "source_name"
) + ggtitle(sprintf("TSNE plot: %s", typeNorm))
# write plot to file:
tmpFn <- sprintf("%s/%s/%s/%s_sce_nz_postQc%s_%sTsne.png",
projDir, outDirBit, qcPlotDirBit, setName, setSuf, typeNorm)
ggsave(filename=tmpFn, plot=p)
## Saving 7 x 5 in image
knitr::include_graphics(tmpFn, auto_pdf = TRUE)
rm(tmpFn)
typeNorm <- "sctrans"
reducedDim(sce, "PCA_sctrans_norm") <- reducedDim(
runPCA(sce, exprs_values = "sctrans_norm"),
"PCA"
)
PCA plot for the ‘sctrans’ counts in the GSM3872434 set.
p <- plotReducedDim(
sce,
dimred = "PCA_sctrans_norm",
colour_by = "Sample.Name",
size_by = "sum",
shape_by = "source_name"
) + ggtitle(sprintf("PCA plot: %s", typeNorm))
# write plot to file:
tmpFn <- sprintf("%s/%s/%s/%s_sce_nz_postQc%s_%sPca.png",
projDir, outDirBit, qcPlotDirBit, setName, setSuf, typeNorm)
ggsave(filename=tmpFn, plot=p)
## Saving 7 x 5 in image
knitr::include_graphics(tmpFn, auto_pdf = TRUE)
rm(tmpFn)
TSNE plot for the sctrans counts in the GSM3872434 set.
typeNorm <- "sctrans"
reducedDim(sce, "TSNE_sctrans_norm") <- reducedDim(
runTSNE(sce, exprs_values = "sctrans_norm"),
"TSNE"
)
p <- plotReducedDim(
sce,
dimred = "TSNE_sctrans_norm",
colour_by = "Sample.Name",
size_by = "sum",
shape_by = "source_name"
) + ggtitle(sprintf("TSNE plot: %s", typeNorm))
# write plot to file:
tmpFn <- sprintf("%s/%s/%s/%s_sce_nz_postQc%s_%sTsne.png",
projDir, outDirBit, qcPlotDirBit, setName, setSuf, typeNorm)
ggsave(filename=tmpFn, plot=p)
## Saving 7 x 5 in image
knitr::include_graphics(tmpFn, auto_pdf = TRUE)
rm(tmpFn)
Cell-wise RLE for the sctrans counts in the GSM3872434 set.
p <- plotRLE(
sce,
exprs_values = "sctrans_norm",
colour_by = "Sample.Name"
) + ggtitle(sprintf("RLE plot: %s", typeNorm))
# write plot to file:
tmpFn <- sprintf("%s/%s/%s/%s_sce_nz_postQc%s_%sRle.png",
projDir, outDirBit, qcPlotDirBit, setName, setSuf, typeNorm)
ggsave(filename=tmpFn, plot=p)
## Saving 7 x 5 in image
knitr::include_graphics(tmpFn, auto_pdf = TRUE)
rm(tmpFn)
sessionInfo()
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.4 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C
## [4] LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C
## [7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C
## [10] LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C
##
## attached base packages:
## [1] parallel stats4 stats graphics grDevices utils datasets
## [8] methods base
##
## other attached packages:
## [1] BiocSingular_1.4.0 dplyr_1.0.0
## [3] scran_1.16.0 scater_1.16.2
## [5] ggplot2_3.3.2 SingleCellExperiment_1.10.1
## [7] SummarizedExperiment_1.18.2 DelayedArray_0.14.1
## [9] matrixStats_0.56.0 Biobase_2.48.0
## [11] GenomicRanges_1.40.0 GenomeInfoDb_1.24.2
## [13] IRanges_2.22.2 S4Vectors_0.26.1
## [15] BiocGenerics_0.34.0
##
## loaded via a namespace (and not attached):
## [1] viridis_0.5.1 edgeR_3.30.3
## [3] jsonlite_1.7.0 viridisLite_0.3.0
## [5] DelayedMatrixStats_1.10.1 statmod_1.4.34
## [7] dqrng_0.2.1 GenomeInfoDbData_1.2.3
## [9] vipor_0.4.5 yaml_2.2.1
## [11] globals_0.12.5 pillar_1.4.6
## [13] lattice_0.20-41 glue_1.4.1
## [15] limma_3.44.3 digest_0.6.25
## [17] XVector_0.28.0 colorspace_1.4-1
## [19] cowplot_1.0.0 plyr_1.8.6
## [21] htmltools_0.5.0 Matrix_1.2-18
## [23] pkgconfig_2.0.3 listenv_0.8.0
## [25] zlibbioc_1.34.0 purrr_0.3.4
## [27] scales_1.1.1 Rtsne_0.15
## [29] BiocParallel_1.22.0 tibble_3.0.3
## [31] generics_0.0.2 farver_2.0.3
## [33] ellipsis_0.3.1 withr_2.2.0
## [35] magrittr_1.5 crayon_1.3.4
## [37] evaluate_0.14 future_1.18.0
## [39] MASS_7.3-51.6 beeswarm_0.2.3
## [41] tools_4.0.2 lifecycle_0.2.0
## [43] stringr_1.4.0 munsell_0.5.0
## [45] locfit_1.5-9.4 irlba_2.3.3
## [47] isoband_0.2.2 compiler_4.0.2
## [49] rsvd_1.0.3 rlang_0.4.7
## [51] grid_4.0.2 RCurl_1.98-1.2
## [53] BiocNeighbors_1.6.0 igraph_1.2.5
## [55] bitops_1.0-6 labeling_0.3
## [57] rmarkdown_2.3 gtable_0.3.0
## [59] codetools_0.2-16 reshape2_1.4.4
## [61] R6_2.4.1 gridExtra_2.3
## [63] knitr_1.29 future.apply_1.6.0
## [65] stringi_1.4.6 ggbeeswarm_0.6.0
## [67] Rcpp_1.0.5 png_0.1-7
## [69] sctransform_0.2.1 vctrs_0.3.2
## [71] tidyselect_1.1.0 xfun_0.15