Skip to content

Commit

Permalink
Adding option to increase clusters included in damaged cell detection
Browse files Browse the repository at this point in the history
  • Loading branch information
AlicenJoyHenning committed Sep 1, 2024
1 parent 70ab037 commit 5e3b828
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 deletions.
11 changes: 9 additions & 2 deletions R/limiric.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#' @param filtered_path Directory of filtered alignment output
#' @param seurat_input 'Seurat' object to be used as input over raw files. Default NULL
#' @param min_cells In how many cells should a gene be expressed to be kept
#' @param resolution Numeric between 0 and 1.6 describing cluster division. Default 1
#' @param soupx Perform ambient RNA correction, if TRUE raw_path must be given. Default is FALSE
#' @param raw_path Directory of unfiltered alignment output
#' @param droplet_qc Verify output with droplet_qc, if TRUE velocyto_path must be given. Default is FALSE
Expand All @@ -20,6 +19,8 @@
#' @param filter_output Should output contain no damaged cells. Default is TRUE
#' @param output_path Directory where 'limiric' output should be generated
#' @param organism "Hsap" if human sample or "Mmus" if mouse sample
#' @param resolution Numeric between 0 and 1.6 describing cluster division. Default 1
#' @param cluster_ranks Numeric describing the number of top ranking clusters to be included as damaged cells. Default 1.
#' @param sample_list Input multiple samples in list. Default is FALSE
#'
#' @return (list) Output storing the final 'Seurat' object
Expand Down Expand Up @@ -66,7 +67,6 @@ limiric <- function(
filtered_path = NULL,
seurat_input = NULL,
min_cells = NULL,
resolution = NULL,
soupx = NULL,
raw_path = NULL,
droplet_qc = NULL,
Expand All @@ -76,6 +76,8 @@ limiric <- function(
filter_output = NULL,
output_path = NULL,
organism = NULL,
resolution = NULL,
cluster_ranks = NULL,
sample_list = NULL

){
Expand All @@ -90,6 +92,7 @@ limiric <- function(
if (is.null(seurat_input)) {seurat_input = NULL}
if (is.null(min_cells)) {min_cells = 0}
if (is.null(resolution)) {resolution = 1}
if (is.null(cluster_ranks)) {cluster_ranks = 1}
if (is.null(soupx)) {soupx = FALSE}
if (is.null(droplet_qc)) {droplet_qc = FALSE}
if (is.null(filter_rbc)) {filter_rbc = TRUE}
Expand All @@ -105,6 +108,7 @@ limiric <- function(
seurat_input = seurat_input,
min_cells = min_cells,
resolution = resolution,
cluster_ranks = cluster_ranks,
soupx = soupx,
raw_path = raw_path,
droplet_qc = droplet_qc,
Expand Down Expand Up @@ -163,6 +167,7 @@ limiric <- function(
seurat_input <- sample$seurat_input
min_cells <- sample$min_cells
resolution <- sample$resolution
cluster_ranks <- sample$cluster_ranks
soupx <- sample$soupx
raw_path <- sample$raw_path
droplet_qc <- sample$droplet_qc
Expand All @@ -177,6 +182,7 @@ limiric <- function(
if (is.null(seurat_input)) {seurat_input = NULL}
if (is.null(min_cells)) {min_cells = 0}
if (is.null(resolution)) {resolution = 1}
if (is.null(cluster_ranks)) {cluster_ranks = 1}
if (is.null(soupx)) {soupx = FALSE}
if (is.null(droplet_qc)) {droplet_qc = FALSE}
if (is.null(filter_rbc)) {filter_rbc = TRUE}
Expand All @@ -196,6 +202,7 @@ limiric <- function(
seurat_input = seurat_input,
min_cells = min_cells,
resolution = resolution,
cluster_ranks = cluster_ranks,
soupx = soupx,
raw_path = raw_path,
droplet_qc = droplet_qc,
Expand Down
14 changes: 8 additions & 6 deletions R/limiric_calculation.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#' @param organism A string representing the organism ("Hsap", "Mmus").
#' @param Seurat A 'Seurat' object containing the single-cell RNA-seq data.
#' @param resolution Numeric between 0 and 1.6 describing cluster division. Default is 1.
#' @param cluster_ranks Numeric describing the number of top ranking clusters to be included as damaged cells. Default 1.
#' @param annotations A data frame containing gene annotations.
#' @param initial_cells An integer representing the initial number of cells.
#' @param project_name A string representing the name of the project, used for plot titles.
Expand Down Expand Up @@ -54,6 +55,7 @@ utils::globalVariables(c("mt_plot", "complexity_plot", "rb_plot",
limiric_calculation <- function(organism,
Seurat,
resolution,
cluster_ranks,
annotations,
initial_cells,
project_name,
Expand Down Expand Up @@ -168,12 +170,12 @@ limiric_calculation <- function(organism,
combined_rank = rank_mt + rank_rb
) %>%
arrange(combined_rank) %>%
slice(1) %>%
slice(1:cluster_ranks) %>%
pull(seurat_clusters) %>%
as.character()

# Label all cells belonging to this cluster as "damaged"
limiric$seurat_clusters <- ifelse(limiric$seurat_clusters == best_cluster, 'damaged', limiric$seurat_clusters)
limiric$seurat_clusters <- ifelse(limiric$seurat_clusters %in% best_cluster, 'damaged', limiric$seurat_clusters)

# Add Cell QC meta data to object
limiric$MtRb <- ifelse(limiric$seurat_clusters == "damaged", "damaged", "cell")
Expand All @@ -189,30 +191,30 @@ limiric_calculation <- function(organism,

# Visualise clusters coloured by QC metrics ------------------------------------

mt_plot <- FeaturePlot(limiric, features = c("mt.percent"), cols = c("#E1E1E1", "#5372B4"), pt.size = 1) +
mt_plot <- FeaturePlot(limiric, features = c("mt.percent"), cols = c("#E1E1E1", "#6765ED"), pt.size = 1) +
NoAxes() + labs(caption = "Mitochondrial gene expression") +
theme(
plot.title = element_blank(),
panel.border = element_rect(colour = "black", fill=NA, linewidth =1),
plot.caption = element_text(hjust = 0.5, size = 16))

rb_plot <- FeaturePlot(limiric, features = c("rb.percent"), cols = c("#E1E1E1", "#5372B4"), pt.size = 1) +
rb_plot <- FeaturePlot(limiric, features = c("rb.percent"), cols = c("#E1E1E1", "#6765ED"), pt.size = 1) +
NoAxes() + labs(caption = "Ribosomal gene expression") +
theme(
plot.title = element_blank(),
panel.border = element_rect(colour = "black", fill=NA, linewidth =1),
plot.caption = element_text(hjust = 0.5, size = 16))

cluster_plot <- DimPlot(
limiric, pt.size = 1, group.by = "MtRb", cols = c("cell" = "grey", "damaged" = "#5372B4")) +
limiric, pt.size = 1, group.by = "MtRb", cols = c("cell" = "grey", "damaged" = "#6765ED")) +
labs(caption = expression("Damaged cells identified by " * italic("limiric"))) + NoAxes() +
theme(
plot.title = element_blank(),
plot.caption = element_text(hjust = 0.5, size = 16),
panel.border = element_rect(colour = "black", fill=NA, linewidth =1)
)

complexity_plot <- FeaturePlot(limiric, features = c("complexity"), cols = c("#E1E1E1", "#5372B4"), pt.size = 1) +
complexity_plot <- FeaturePlot(limiric, features = c("complexity"), cols = c("#E1E1E1", "#6765ED"), pt.size = 1) +
NoAxes() + labs(caption = "Complexity score") +
theme(
plot.title = element_blank(),
Expand Down
7 changes: 5 additions & 2 deletions R/limiric_core.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#' @param filtered_path Directory of filtered alignment output
#' @param seurat_input Seurat object to be used as input over raw files. Default NULL
#' @param min_cells In how many cells should a gene be expressed to be kept
#' @param resolution Numeric between 0 and 1.6 describing cluster division. Default 1
#' @param soupx Perform ambient RNA correction, if TRUE raw_path must be given. Default is FALSE
#' @param raw_path Directory of unfiltered alignment output
#' @param droplet_qc Verify output with droplet_qc, if TRUE velocyto_path must be given. Default is FALSE
Expand All @@ -17,6 +16,8 @@
#' @param isolate_cd45 Discard non-immune cells. Default is FALSE
#' @param filter_output Should output contain no damaged cells. Default is TRUE
#' @param output_path Directory where limiric output cen be generated
#' @param resolution Numeric between 0 and 1.6 describing cluster division. Default 1
#' @param cluster_ranks Numeric describing the number of top ranking clusters to be included as damaged cells. Default 1.
#' @param organism "Hsap" if human sample or "Mmus" if mouse sample
#'
#' @return (list) Output list storing the final Seurat object
Expand Down Expand Up @@ -63,7 +64,6 @@ limiric_core <- function(
filtered_path,
seurat_input = NULL,
min_cells = 0,
resolution = 1,
soupx = FALSE,
raw_path = NULL,
droplet_qc = FALSE,
Expand All @@ -72,6 +72,8 @@ limiric_core <- function(
isolate_cd45 = FALSE,
filter_output = TRUE,
output_path = "./",
resolution = 1,
cluster_ranks = 1,
organism = "Hsap"
){
# Receive & prepare input ------------------------------------
Expand Down Expand Up @@ -339,6 +341,7 @@ limiric_core <- function(
limiric_output <- limiric_calculation(organism = organism,
Seurat = Seurat,
resolution = resolution,
cluster_ranks = cluster_ranks,
annotations = annotations,
initial_cells = initial_cells,
project_name = project_name,
Expand Down
6 changes: 4 additions & 2 deletions man/limiric.Rd

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

2 changes: 2 additions & 0 deletions man/limiric_calculation.Rd

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

6 changes: 4 additions & 2 deletions man/limiric_core.Rd

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

0 comments on commit 5e3b828

Please sign in to comment.