Skip to content

Commit

Permalink
Merge pull request #189 from zhanghao-njmu/develop
Browse files Browse the repository at this point in the history
Update the CellQC function
  • Loading branch information
zhanghao-njmu authored Oct 25, 2023
2 parents 4637e0c + 6a0d2fc commit 39ff0aa
Show file tree
Hide file tree
Showing 23 changed files with 208 additions and 146 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ importFrom(ggplot2,ggplot_gtable)
importFrom(ggplot2,ggsave)
importFrom(ggplot2,ggtitle)
importFrom(ggplot2,guide_colorbar)
importFrom(ggplot2,guide_colourbar)
importFrom(ggplot2,guide_legend)
importFrom(ggplot2,guide_none)
importFrom(ggplot2,guides)
Expand Down
25 changes: 7 additions & 18 deletions R/SCP-cellqc.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ isOutlier <- function(x, nmads = 2.5, constant = 1.4826, type = c("both", "lower

#' Run cell-level quality control for single cell RNA-seq data.
#'
#' In CellQC, doublet-calling will be run first and then reject abnormal cell data based on median absolute deviation (MAD) outliers.
#' After doublet-calling and outlier filtering, CellQC will perform general QC (gene count, UMI count, etc.)
#' and reject cell data for non-species of interest based on the proportion and number of UMIs for the species.
#' This function handles multiple quality control methods for single-cell RNA-seq data.
#'
#' @inheritParams RunDoubletCalling
#' @param batch Name of the batch variable to split the Seurat object. Default is NULL.
Expand All @@ -284,15 +282,6 @@ isOutlier <- function(x, nmads = 2.5, constant = 1.4826, type = c("both", "lower
#'
#' @return Returns Seurat object with the QC results stored in the meta.data slot.
#'
#' @note
#' General quality control usually uses metrics such as gene count, UMI count, etc.
#' In addition, ribo content and mito content can be used as QC indicators:
#' mito content can be used as an indication of apoptosis,
#' with a general threshold of 20% and less than 10% mito content in high quality cells;
#' ribo content is cell type dependent, with some cell types having even more than 50% ribo content;
#' however, ribo content in single cell data can also indicate whether the empty droplets,
#' and the ribo content in empty droplets is usually high and the mito content is low instead.
#'
#' @examples
#' data("pancreas_sub")
#' pancreas_sub <- RunCellQC(pancreas_sub)
Expand All @@ -307,7 +296,7 @@ isOutlier <- function(x, nmads = 2.5, constant = 1.4826, type = c("both", "lower
#' table(pancreas_sub$CellQC)
#'
#' data("ifnb_sub")
#' ifnb_sub <- RunCellQC(ifnb_sub, batch = "stim", UMI_threshold = 1000, gene_threshold = 550)
#' ifnb_sub <- RunCellQC(ifnb_sub, split.by = "stim", UMI_threshold = 1000, gene_threshold = 550)
#' CellStatPlot(
#' srt = ifnb_sub,
#' stat.by = c(
Expand All @@ -322,7 +311,7 @@ isOutlier <- function(x, nmads = 2.5, constant = 1.4826, type = c("both", "lower
#' @importFrom Matrix colSums t
#' @export
#'
RunCellQC <- function(srt, assay = "RNA", batch = NULL,
RunCellQC <- function(srt, assay = "RNA", split.by = NULL,
qc_metrics = c("doublets", "outlier", "umi", "gene", "mito", "ribo", "ribo_mito_ratio", "species"),
return_filtered = FALSE,
db_method = "scDblFinder", db_rate = NULL, db_coefficient = 0.01,
Expand Down Expand Up @@ -364,16 +353,16 @@ RunCellQC <- function(srt, assay = "RNA", batch = NULL,
srt@meta.data[[paste0("nFeature_", assay)]] <- colSums(srt[[assay]]@counts > 0)
}
srt_raw <- srt
if (!is.null(batch)) {
srtList <- SplitObject(srt, split.by = batch)
if (!is.null(split.by)) {
srtList <- SplitObject(srt, split.by = split.by)
} else {
srtList <- list(srt)
}

for (i in seq_along(srtList)) {
srt <- srtList[[i]]
if (!is.null(batch)) {
cat("===", srt@meta.data[[batch]][1], "===\n")
if (!is.null(split.by)) {
cat("===", srt@meta.data[[split.by]][1], "===\n")
}
ntotal <- ncol(srt)

Expand Down
231 changes: 145 additions & 86 deletions R/SCP-plot.R

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ plist <- list()
for (method in integration_methods) {
panc8_sub <- Integration_SCP(
srtMerge = panc8_sub, batch = "tech",
srtMerge = panc8_sub, batch = "tech", linear_reduction_dims_use = 1:50,
integration_method = method, nonlinear_reduction = "umap"
)
plist[[method]] <- CellDimPlot(panc8_sub,
title = method, group.by = c("celltype"), reduction = paste0(method, "UMAP2D"), theme_use = "theme_blank",
show_stat = F, xlab = "UMAP_1", ylab = "UMAP_2", legend.position = "none"
xlab = "UMAP_1", ylab = "UMAP_2", legend.position = "none"
)
}
p <- plot_grid(plotlist = plist, ncol = 3)
Expand All @@ -335,7 +335,11 @@ panel_fix(grob, height = 2)
### Cell projection between single-cell datasets

```{r RunKNNMap}
panc8_rename <- RenameFeatures(srt = panc8_sub, newnames = make.unique(capitalize(rownames(panc8_sub), force_tolower = TRUE)), assays = "RNA")
panc8_rename <- RenameFeatures(
srt = panc8_sub,
newnames = make.unique(capitalize(rownames(panc8_sub[["RNA"]]), force_tolower = TRUE)),
assays = "RNA"
)
srt_query <- RunKNNMap(srt_query = pancreas_sub, srt_ref = panc8_rename, ref_umap = "SeuratUMAP2D")
ProjectionPlot(
srt_query = srt_query, srt_ref = panc8_rename,
Expand Down Expand Up @@ -447,7 +451,7 @@ EnrichmentPlot(

> To ensure that labels are visible, you can adjust the size of the viewer panel on Rstudio IDE.
```{r Enrichment_enrichmap, fig.height=9.5,fig.width=15}
```{r Enrichment_enrichmap, fig.height=9.5, fig.width=15}
EnrichmentPlot(
srt = pancreas_sub, group_by = "CellType", group_use = "Ductal",
plot_type = "enrichmap"
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@ UMAP embeddings based on different integration methods in SCP:
### Cell projection between single-cell datasets

``` r
panc8_rename <- RenameFeatures(srt = panc8_sub, newnames = make.unique(capitalize(rownames(panc8_sub), force_tolower = TRUE)), assays = "RNA")
panc8_rename <- RenameFeatures(
srt = panc8_sub,
newnames = make.unique(capitalize(rownames(panc8_sub[["RNA"]]), force_tolower = TRUE)),
assays = "RNA"
)
srt_query <- RunKNNMap(srt_query = pancreas_sub, srt_ref = panc8_rename, ref_umap = "SeuratUMAP2D")
ProjectionPlot(
srt_query = srt_query, srt_ref = panc8_rename,
Expand Down
Binary file modified README/README-EDA-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-EDA-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-EDA-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-EDA-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-Enrichment_comparison-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-GSEA_comparison-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-Integration_SCP-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-RunDEtest-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-RunEnrichment-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-RunEnrichment-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-RunSCVELO-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-RunSCVELO-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-RunSlingshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README/README-Standard_SCP-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions man/CellDimPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 30 additions & 13 deletions man/FeatureDimPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/FeatureDimPlot3D.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 5 additions & 16 deletions man/RunCellQC.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 39ff0aa

Please sign in to comment.