Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions bin/seurat_preprocess_init.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
title: "scRNA Sample Processing"
output:
html_document:
toc: yes
editor_options:
chunk_output_type: console
params:
species: "hg38"
sampleid: "WB_Lysis_1"
h5: "./tests/test_dir/cellranger_counts/sample1/outs/filtered_feature_bc_matrix.h5"
qc_filtering: "miQC"
nCount_RNA_max: 500000
nCount_RNA_min: 1000
nFeature_RNA_max: 5000
nFeature_RNA_min: 200
percent_mt_max: 10
percent_mt_min: 0
doublet_finder: "DoubletFinder"
npcs: 30
---

```{r, prep_args, message=FALSE}
# set up params
species <- params$species
sample_id <- params$sampleid
h5 <- params$h5

qc_filtering <- params$qc_filtering # manual, miqc, mads
nCount_RNA_max <- as.numeric(params$nCount_RNA_max)
nCount_RNA_min <- as.numeric(params$nCount_RNA_min)
nFeature_RNA_max <- as.numeric(params$nFeature_RNA_max)
nFeature_RNA_min <- as.numeric(params$nFeature_RNA_min)
percent_mt_max <- as.numeric(params$percent_mt_max)
percent_mt_min <- as.numeric(params$percent_mt_min)
doublet_finder <- params$doublet_finder
npcs_val <- as.numeric(params$npcs)
```

```{r, handle_pkg, message=FALSE}
if (!("SCOT" %in% installed.packages())){
devtools::install_github("CCBR/SCOT", ref = "main" )
}
library("SCOT")
```

```{r, pre-processing, message = FALSE, echo=FALSE, include =FALSE}
# read in data
rnaCounts <- Seurat::Read10X_h5(h5)

#REMOVED CONDITION FOR TESTING, WHICH IS NOW IN NEXTFLOW ARGUMENTS
so_pre <- Seurat::CreateSeuratObject(counts = rnaCounts)

so_pre <- SCOT::calc_prelim_stats(so = so_pre, sampleID = sample_id)

#Violin plots to be moved to secondary visualization

```

```{r QC}
#Use SCOT function for filtering conditions
so_pre
so_filt <- subset(so_pre, subset = nFeature_RNA > 200)

so_filt <- SCOT::filter_cells(so_filt, method = qc_filtering)

so_pre$keep <- "low_genes"
so_pre$keep[colnames(so_filt)] <- so_filt$keep

so_filt <- subset(so_filt, subset = keep == "keep")
```

```{r normalization_and_clustering}
#Calculate s.genes and g2m.genes
#Normalize RNA
#Scale RNA
#Cell cycle scoring
#SCTransform
#PCA, UMAP, and initial clustering
so_filt <- SCOT::preprocess_sample(
so_in = so_filt, species = species, npcs_in = npcs_val
)
```

```{r cell_type_annotation}
so_filt <- SCOT::run_singleR_db(so_in = so_filt, species = species)
```

```{r doublet_finding}
if (doublet_finder %in% c("DoubletFinder", "scDblFinder","consensus","union")){
so_filt <- SCOT::filter_doublets(
so_in = so_filt, doublet_finder_method = doublet_finder
)
}

so_pre$keep[setdiff(colnames(so_pre)[which(so_pre$keep=="keep")], colnames(so_filt))] <- "doublet_removed"
```

```{r process_unfiltered}
so_pre <- SCOT::preprocess_sample(
so_in = so_pre, species = species, npcs_in = npcs_val
)
```

```{r save_objects}
fpath_process <- paste0(sample_id, "_seurat_preprocess.rds")
saveRDS(so_filt, fpath_process)
fpath_prefilt <- paste0(sample_id, "_seurat_prefilter.rds")
saveRDS(so_pre, fpath_prefilt)
```

```{r print_session}
sessionInfo()
```
104 changes: 104 additions & 0 deletions bin/seurat_preprocess_report.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: "scRNA Sample Report"
output:
html_document:
toc: yes
editor_options:
chunk_output_type: console
params:
species: "hg38"
sampleid: "WB_Lysis_1"
h5: "./tests/test_dir/cellranger_counts/sample1/outs/filtered_feature_bc_matrix.h5"
preprocess_rds: "./tests/test_dir/process_sample/WB_Lysis_1_seurat_preprocess.rds"
prefilter_rds: "./tests/test_dir/process_sample/WB_Lysis_1_seurat_prefilter.rds"
qc_filtering: "miQC"
nCount_RNA_max: 500000
nCount_RNA_min: 1000
nFeature_RNA_max: 5000
nFeature_RNA_min: 200
percent_mt_max: 10
percent_mt_min: 0
doublet_finder: "DoubletFinder"
npcs: 30
---


```{r, prep_args, message=FALSE}
# set up params
species <- params$species
sample_id <- params$sampleid
h5 <- params$h5
processed <- params$preprocess_rds
prefilter <- params$prefilter_rds
qc_filtering <- params$qc_filtering # manual, miqc, mads
nCount_RNA_max <- as.numeric(params$nCount_RNA_max)
nCount_RNA_min <- as.numeric(params$nCount_RNA_min)
nFeature_RNA_max <- as.numeric(params$nFeature_RNA_max)
nFeature_RNA_min <- as.numeric(params$nFeature_RNA_min)
percent_mt_max <- as.numeric(params$percent_mt_max)
percent_mt_min <- as.numeric(params$percent_mt_min)
doublet_finder <- params$doublet_finder
npcs_val <- as.numeric(params$npcs)
```

```{r, handle_pkg, message=FALSE}
if (!("SCOT" %in% installed.packages())){
devtools::install_github("CCBR/SCOT", ref = "main" )
}
library("SCOT")
if (!requireNamespace("Seurat", quietly = TRUE)) {
install.packages("Seurat")
}

```

```{r load_objects, echo=FALSE, message=FALSE, warning=FALSE}
so_prefilter <- Seurat::readRDS(prefilter)
so_processed <- Seurat::readRDS(processed)

n_prefilter <- ncol(so_prefilter)
n_processed <- ncol(so_processed)
```

## Filtering Summary
```{r summary_table}
#UPDATE TO INDICATE
summary_table <- data.frame(
Stage = c("Prefilter", "Processed"),
Cells = c(n_prefilter, n_processed)
)

knitr::kable(summary_table, caption = "Cell counts before and after filtering")
```

## UMAP of Filtered Cells

## Violin plots for QC metrics

```{r violin_plots, echo=FALSE, message=FALSE, warning=FALSE}
qc_features <- c("nFeature_RNA", "nCount_RNA", "percent.mt")

p_prefilter <- Seurat::VlnPlot(
so_prefilter,
features = qc_features,
ncol = 3,
pt.size = 0.1,
log = 10
) + ggplot2::ggtitle("QC metrics before filtering")

p_processed <- Seurat::VlnPlot(
so_processed,
features = qc_features,
ncol = 3,
pt.size = 0.1,
log = 10
) + ggplot2::ggtitle("QC metrics after filtering")

p_prefilter
p_processed
```


```{r print_session}
sessionInfo()
```
4 changes: 2 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
}
],
"codeRepository": "https://github.com/CCBR/SINCLAIR",
"datePublished": "2026-05-12",
"datePublished": "2026-05-13",
"identifier": "https://doi.org/10.5281/zenodo.15283503",
"license": "https://spdx.org/licenses/MIT",
"name": "SINCLAIR: SINgle CelL AnalysIs Resource",
"url": "https://ccbr.github.io/SINCLAIR",
"version": "v0.3.7"
"version": "v0.4.0"
}
2 changes: 1 addition & 1 deletion conf/test_pbmc.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ params {
nFeature_RNA_min = 200
percent_mt_max = 30
percent_mt_min = 0
run_doublet_finder = "Y"
doublet_finder = "DoubletFinder"

// GEX
seurat_resolution = "0.1,0.2,0.3,0.5,0.6,0.8,1"
Expand Down
2 changes: 1 addition & 1 deletion docs/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Define where the pipeline should find input data and save output data.
| `nFeature_RNA_min` | | `integer` | 200 | | |
| `percent_mt_max` | | `integer` | 10 | | |
| `percent_mt_min` | | `integer` | 0 | | |
| `run_doublet_finder` | (accepted: `Y`\|`N`) | `string` | Y | | |
| `doublet_finder` | (accepted: `scDblFinder`\|`union`\|`consensus`) | `string` | DoubletFinder | | |
| `seurat_resolution` | | `string` | 0.1,0.2,0.3,0.5,0.6,0.8,1 | | |
| `npcs` | | `integer` | 50 | | |
| `resolution_list` | | `string` | 0.1,0.2,0.3,0.5,0.6,0.8,1 | | |
Expand Down
32 changes: 17 additions & 15 deletions modules/local/seurat_preprocess.nf
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ process SEURAT_PREPROCESS {
val(nFeature_RNA_min)
val(percent_mt_max)
val(percent_mt_min)
val(run_doublet_finder)
val(doublet_finder)
val(npcs)
path(rmd)
path(scRNA_functions)

output:
tuple val(id), path ("*.rds") , emit:rds
tuple val(id), path ("*.html") , emit:logs
tuple val(id), path ("*.seurat_preprocess.rds"), emit:rds
tuple val(id), path ("*_seurat_prefilter.rds"), emit:prefilter
tuple val(id), path ("*seurat_preprocess.html"), emit:logs
// tuple val(id), path ("*seurat_preprocess_report.html"), emit:report

script:
def args = task.ext.args ?: ''
Expand All @@ -33,23 +34,24 @@ process SEURAT_PREPROCESS {
sampleid="$id",
h5="$h5",
qc_filtering="$qc_filtering",
nCount_RNA_max=$nCount_RNA_max,
nCount_RNA_min=$nCount_RNA_min,
nFeature_RNA_max=$nFeature_RNA_max,
nFeature_RNA_min=$nFeature_RNA_min,
percent_mt_max=$percent_mt_max,
percent_mt_min=$percent_mt_min,
run_doublet_finder="$run_doublet_finder",
npcs=$npcs,
scRNA_functions="$scRNA_functions",

nCount_RNA_max="$nCount_RNA_max",
nCount_RNA_min="$nCount_RNA_min",
nFeature_RNA_max="$nFeature_RNA_max",
nFeature_RNA_min="$nFeature_RNA_min",
percent_mt_max="$percent_mt_max",
percent_mt_min="$percent_mt_min",
doublet_finder="$doublet_finder",
npcs="$npcs",
celldex_cache="$celldex_path"
),
output_file = "${id}_seurat_preprocess.html"
)
output_file = "${id}_seurat_preprocess.html")'

"""

stub:
"""
touch ${id}_seurat_prefilter.rds
touch ${id}_seurat_preprocess.rds
touch ${id}_seurat_preprocess.html
"""
Expand Down
7 changes: 4 additions & 3 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ params {
vars_to_regress = null // other options include "percent.mt,nFeature_RNA,S.Score,G2M.Score,nCount_RNA"

// seurat_preprocess.nf
qc_filtering = "miqc" //other options include "manual" (uses subsequent thresholds), "mads" (3 median absolute deviations)
qc_filtering = "miQC" //other options include "manual" (uses subsequent thresholds), "mads" (3 median absolute deviations)
nCount_RNA_max = 500000
nCount_RNA_min = 1000
nFeature_RNA_max = 5000
nFeature_RNA_min = 200
percent_mt_max = 10
percent_mt_min = 0
run_doublet_finder = "Y"
doublet_finder = "DoubletFinder" //other options are "scDblFinder", "union", and "consensus"

// GEX
seurat_resolution = "0.1,0.2,0.3,0.5,0.6,0.8,1"
Expand All @@ -42,7 +42,8 @@ params {

// Scripts
script_functions = "${projectDir}/bin/scRNA_functions.R"
script_preprocess = "${projectDir}/bin/seurat_preprocess.Rmd"
script_preprocess = "${projectDir}/bin/seurat_preprocess_init.Rmd"
script_preprocess_report = "${projectDir}/bin/seurat_preprocess_report.Rmd"
script_merge = "${projectDir}/bin/seurat_merge.Rmd"
script_bc_harmony = "${projectDir}/bin/batch_correction_harmony.Rmd"
script_bc_rpca = "${projectDir}/bin/batch_correction_rpca.Rmd"
Expand Down
6 changes: 3 additions & 3 deletions nextflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
"type": "integer",
"default": 0
},
"run_doublet_finder": {
"doublet_finder": {
"type": "string",
"default": "Y",
"enum": ["Y", "N"]
"default": "DoubletFinder",
"enum": ["scDblFinder", "union", "consensus"]
},
"seurat_resolution": {
"type": "string",
Expand Down
Loading
Loading