diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ae737c6..a5b22f70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,13 @@ Initial release of nf-core/scdownstream, created with the [nf-core](https://nf-c ### `Added` - Added `singleR` module for automated cell type annotation. +- Added `scDblFinder` module for doublet detection. +- Added optional `doublet_rate` column in input samplesheet to provide per-sample expected doublet rate for `scDblFinder`. ### `Fixed` +- Updated `scDblFinder` to use internal `dbr` estimation when `doublet_rate` is not provided, and to use provided `doublet_rate` when available. + ### `Dependencies` ### `Deprecated` diff --git a/CITATIONS.md b/CITATIONS.md index bee9e80f..10ad4fc5 100644 --- a/CITATIONS.md +++ b/CITATIONS.md @@ -47,6 +47,10 @@ > Cannoodt R, Zappia L, Morgan M, Deconinck L (2025). anndataR: AnnData interoperability in R. R package version 0.99.0 +- [scDblFinder](https://pubmed.ncbi.nlm.nih.gov/35118618/) + + > Germain P, Lun A, Garcia Meixide C, Macnair W, Robinson M. Doublet identification in single-cell sequencing data using scDblFinder. F1000Res. 2022;11:979. doi: 10.12688/f1000research.73600.2. + ## Software packaging/containerisation tools - [Anaconda](https://anaconda.com) diff --git a/README.md b/README.md index 9eb07ccb..5d987582 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ Steps marked with the boat icon are not yet implemented. For the other steps, th - [scrublet](https://scanpy.readthedocs.io/en/stable/api/generated/scanpy.pp.scrublet.html) - [DoubletDetection](https://doubletdetection.readthedocs.io/en/v2.5.2/doubletdetection.doubletdetection.html) - [SCDS](https://bioconductor.org/packages/devel/bioc/vignettes/scds/inst/doc/scds.html) + - [scDblFinder](https://bioconductor.org/packages/release/bioc/html/scDblFinder.html) 2. Sample aggregation 1. Merge into a single h5ad file 2. Present QC for merged counts ([`MultiQC`](http://multiqc.info/)) @@ -87,6 +88,8 @@ sample4,/absolute/path/to/sample3.csv Each entry represents a h5ad, h5, RDS or CSV file. RDS files may contain any object that can be converted to a SingleCellExperiment using the [Seurat `as.SingleCellExperiment`](https://satijalab.org/seurat/reference/as.singlecellexperiment) function. CSV files should contain a matrix with genes as columns and cells as rows. The first column should contain cell names/barcodes. +For `scDblFinder`, you can optionally add a `doublet_rate` column (values between `0` and `1`) to the samplesheet. If omitted, `scDblFinder` estimates the doublet rate internally. + --> Now, you can run the pipeline using: diff --git a/assets/schema_input.json b/assets/schema_input.json index dedad5d7..d2636e85 100644 --- a/assets/schema_input.json +++ b/assets/schema_input.json @@ -122,6 +122,13 @@ "errorMessage": "Number of cells expected from the experimental design, used as input to cellbender.", "meta": ["expected_cells"] }, + "doublet_rate": { + "type": "number", + "minimum": 0, + "maximum": 1, + "errorMessage": "doublet_rate must be a number between 0 and 1.", + "meta": ["doublet_rate"] + }, "ambient_correction": { "type": "boolean", "default": true, diff --git a/conf/modules.config b/conf/modules.config index beae2c2f..0504d6db 100644 --- a/conf/modules.config +++ b/conf/modules.config @@ -213,6 +213,16 @@ process { ] } + withName: SCDBLFINDER { + ext.prefix = { meta.id + '_scdblfinder' } + publishDir = [ + path: { "${params.outdir}/quality_control/doublet_detection/scdblfinder" }, + mode: params.publish_dir_mode, + enabled: params.save_intermediates, + saveAs: { filename -> filename.equals('versions.yml') ? null : filename }, + ] + } + withName: DOUBLET_REMOVAL { publishDir = [ path: { "${params.outdir}/quality_control/doublet_detection" }, diff --git a/conf/test.config b/conf/test.config index 189363f9..c58705ae 100644 --- a/conf/test.config +++ b/conf/test.config @@ -25,7 +25,7 @@ params { // Input data input = params.pipelines_testdata_base_path + 'samplesheet.csv' integration_methods = 'scvi,harmony,bbknn,combat' - doublet_detection = 'solo,scrublet,scds' + doublet_detection = 'solo,scrublet,scds,scdblfinder' celltypist_model = 'Adult_Human_Skin' celldex_reference = 'https://raw.githubusercontent.com/nf-core/test-datasets/scdownstream/singleR/references.csv' integration_hvgs = 500 diff --git a/conf/test_full.config b/conf/test_full.config index 8262e5bf..7d64f3f0 100644 --- a/conf/test_full.config +++ b/conf/test_full.config @@ -25,7 +25,7 @@ params { // Input data for full size test input = params.pipelines_testdata_base_path + 'samplesheet.csv' integration_methods = 'scvi,harmony,bbknn,combat' - doublet_detection = 'solo,scrublet,doubletdetection,scds' + doublet_detection = 'solo,scrublet,doubletdetection,scds,scdblfinder' celltypist_model = 'Adult_Human_Skin' celldex_reference = 'hpca__2024-02-26,monaco_immune__2024-02-26' // Feature: Support offline. celldex_reference_label = 'label.main,label.fine' diff --git a/docs/output.md b/docs/output.md index 27fad158..e08397b8 100644 --- a/docs/output.md +++ b/docs/output.md @@ -25,6 +25,7 @@ The pipeline is built using [Nextflow](https://www.nextflow.io/) and processes d - [scrublet](https://scanpy.readthedocs.io/en/stable/api/generated/scanpy.pp.scrublet.html) - [DoubletDetection](https://doubletdetection.readthedocs.io/en/v2.5.2/doubletdetection.doubletdetection.html) - [SCDS](https://bioconductor.org/packages/devel/bioc/vignettes/scds/inst/doc/scds.html) + - [scDblFinder](https://bioconductor.org/packages/release/bioc/html/scDblFinder.html) 2. Sample aggregation 1. Merge into a single h5ad file 2. Present QC for merged counts ([`MultiQC`](http://multiqc.info/)) @@ -57,7 +58,7 @@ The pipeline is built using [Nextflow](https://www.nextflow.io/) and processes d - `custom_thresholds/`: Results of applying user-defined QC thresholds. - `doublet_detection/`: Directories related to doublet detection. - `input_rds/`: RDS version of the h5ad file that is used as input to the doublet detection tools. - - `(doubletdetection|scds|scrublet|solo)/`: Results of doublet detection. Each directory contains a filtered `h5ad`/`rds` and a `csv`/`pkl` file with the doublet annotations. + - `(doubletdetection|scdblfinder|scds|scrublet|solo)/`: Results of doublet detection. Each directory contains a filtered `h5ad`/`rds` and a `csv`/`pkl` file with the doublet annotations. - `${sample_id}.h5ad`: The h5ad without doublets. - `qc_preprocessed/`: QC plots for the preprocessed data. diff --git a/docs/usage.md b/docs/usage.md index f635963e..d5dd5c52 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -38,10 +38,10 @@ sample3,/absolute/path/to/sample3.csv There are a couple of optional columns that can be used for more advanced features: ```csv title="samplesheet.csv" -sample,filtered,unfiltered,batch_col,label_col,condition_col,unknown_label,min_genes,min_cells,min_counts_cell,min_counts_gene,expected_cells,ambient_correction,ambient_corrected_integration -sample1,/absolute/path/to/sample1_filtered.h5ad,/absolute/path/to/sample1.h5ad,batch,cell_type,condition,unknown,1,2,3,4,5000,true,false -sample2,relative/path/to/sample2_filtered.rds,relative/path/to/sample2.rds,batch_id,annotation,condition,unannotated,5,6,7,8,3000,false, -sample3,/absolute/path/to/sample3_filtered.csv,/absolute/path/to/sample3.csv,,,,,9,10,11,12,,true,true +sample,filtered,unfiltered,batch_col,label_col,condition_col,unknown_label,min_genes,min_cells,min_counts_cell,min_counts_gene,expected_cells,doublet_rate,ambient_correction,ambient_corrected_integration +sample1,/absolute/path/to/sample1_filtered.h5ad,/absolute/path/to/sample1.h5ad,batch,cell_type,condition,unknown,1,2,3,4,5000,0.08,true,false +sample2,relative/path/to/sample2_filtered.rds,relative/path/to/sample2.rds,batch_id,annotation,condition,unannotated,5,6,7,8,3000,,false, +sample3,/absolute/path/to/sample3_filtered.csv,/absolute/path/to/sample3.csv,,,,,9,10,11,12,,,true,true ``` For CSV input files, specifying the `batch_col`, `label_col`, `condition_col`, and `unknown_label` columns will not have any effect, as no additional metadata is available in the CSV file. @@ -63,6 +63,7 @@ For CSV input files, specifying the `batch_col`, `label_col`, `condition_col`, a | `min_counts_cell` | Minimum number of counts required for a cell to be considered. Defaults to `1`. | | `min_counts_gene` | Minimum number of counts required for a gene to be considered. Defaults to `1`. | | `expected_cells` | Number of expected cells, used as input to CellBender for empty droplet detection. | +| `doublet_rate` | Optional expected doublet rate (0-1) for `scDblFinder`. If not provided, `scDblFinder` estimates it internally. | | `max_mito_percentage` | Maximum percentage of mitochondrial reads for a cell to be considered. Defaults to `100`. | | `ambient_correction` | Whether to perform ambient RNA correction for this sample. Set to `true` to use the globally configured method, `false` to skip ambient correction for this sample. Defaults to `true`. | | `ambient_corrected_integration` | Whether to use ambient-corrected counts for integration for this sample. Set to `true` to use corrected counts in downstream integration, `false` to store them only as additional layers. Can override the global `--ambient_corrected_integration` parameter. Defaults to global setting. | diff --git a/modules/local/doublet_detection/scdblfinder/environment.yml b/modules/local/doublet_detection/scdblfinder/environment.yml new file mode 100644 index 00000000..b3c8a625 --- /dev/null +++ b/modules/local/doublet_detection/scdblfinder/environment.yml @@ -0,0 +1,11 @@ +name: scdblfinder +channels: + - conda-forge + - bioconda +dependencies: + - bioconda::bioconductor-scdblfinder=1.24.0 + - bioconda::bioconductor-singlecellexperiment=1.32.0 + - bioconda::bioconductor-biocparallel=1.44.0 + - bioconda::bioconductor-anndatar=1.0.2 + - bioconda::bioconductor-rhdf5=2.54.1 + - conda-forge::r-tidyverse=2.0.0 diff --git a/modules/local/doublet_detection/scdblfinder/main.nf b/modules/local/doublet_detection/scdblfinder/main.nf new file mode 100644 index 00000000..2f643d15 --- /dev/null +++ b/modules/local/doublet_detection/scdblfinder/main.nf @@ -0,0 +1,32 @@ +process SCDBLFINDER { + tag "$meta.id" + label 'process_medium' + + conda "${moduleDir}/environment.yml" + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://community-cr-prod.seqera.io/docker/registry/v2/blobs/sha256/99/993a012a69d920412b090701eb733ccf35c8655c3d012756ca6b0af1cfcd4780/data' : + 'community.wave.seqera.io/library/bioconductor-anndatar_bioconductor-biocparallel_bioconductor-rhdf5_bioconductor-scdblfinder_pruned:0f9db6b0855861de' }" + + input: + tuple val(meta), path(h5ad), val(dbr) + + output: + tuple val(meta), path("${prefix}.h5ad"), emit: h5ad + tuple val(meta), path("${prefix}.csv"), emit: predictions + path "versions.yml", emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + prefix = task.ext.prefix ?: "${meta.id}" + template('scdblfinder.R') + + stub: + prefix = task.ext.prefix ?: "${meta.id}" + """ + touch ${prefix}.h5ad + touch ${prefix}.csv + touch versions.yml + """ +} diff --git a/modules/local/doublet_detection/scdblfinder/meta.yml b/modules/local/doublet_detection/scdblfinder/meta.yml new file mode 100644 index 00000000..566d28ec --- /dev/null +++ b/modules/local/doublet_detection/scdblfinder/meta.yml @@ -0,0 +1,72 @@ +name: "scdblfinder" +description: Detect doublets in single-cell RNA-seq data using scDblFinder +keywords: + - doublet-detection + - single-cell + - scrnaseq + - quality-control +tools: + - "scdblfinder": + description: "scDblFinder: Computational identification of doublets in single-cell transcriptomics data" + homepage: "https://bioconductor.org/packages/scDblFinder" + documentation: "https://bioconductor.org/packages/release/bioc/vignettes/scDblFinder/inst/doc/scDblFinder.html" + tool_dev_url: "https://github.com/plger/scDblFinder" + doi: "10.12688/f1000research.73600.2" + licence: ["GPL-3.0"] + identifier: biotools:scdblfinder + +input: + - - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'sample1' ]` + - h5ad: + type: file + description: AnnData object in h5ad format + pattern: "*.{h5ad}" + ontologies: + - edam: "http://edamontology.org/format_3590" # HDF5 format + - dbr: + type: number + description: | + Optional expected doublet rate (0-1). If null, scDblFinder estimates + the doublet rate internally. + +output: + h5ad: + - - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'sample1' ]` + - "*.h5ad": + type: file + description: AnnData object with doublet annotations + pattern: "*.h5ad" + ontologies: + - edam: "http://edamontology.org/format_3590" # HDF5 format + predictions: + - - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'sample1' ]` + - "*.csv": + type: file + description: CSV file containing doublet predictions (boolean) + pattern: "*.csv" + ontologies: + - edam: "http://edamontology.org/format_3752" # CSV + versions: + - versions.yml: + type: file + description: File containing software versions + pattern: "versions.yml" + ontologies: + - edam: http://edamontology.org/format_3750 # YAML + +authors: + - "@KurayiChawatama" +maintainers: + - "@KurayiChawatama" diff --git a/modules/local/doublet_detection/scdblfinder/templates/scdblfinder.R b/modules/local/doublet_detection/scdblfinder/templates/scdblfinder.R new file mode 100644 index 00000000..50edc27c --- /dev/null +++ b/modules/local/doublet_detection/scdblfinder/templates/scdblfinder.R @@ -0,0 +1,102 @@ +#!/usr/bin/env Rscript + +library(scDblFinder) +library(tidyverse) +library(SingleCellExperiment) +library(BiocParallel) +library(anndataR) + +adata <- read_h5ad("${h5ad}") +sce <- adata\$as_SingleCellExperiment() + +num_threads <- max(1L, as.integer("${task.cpus}")) +bp <- MulticoreParam(workers = num_threads, RNGseed = 123) + +# Save original cell names and count before overwriting sce +original_cell_names <- colnames(sce) + +# Parse per-sample doublet rate from Nextflow input. If unavailable, let +# scDblFinder estimate dbr internally (recommended default for 10X data). +dbr_raw <- trimws("${dbr}") +dbr <- suppressWarnings(as.numeric(dbr_raw)) + +# Run scDblFinder on the counts matrix (first assay) +# scDblFinder creates artificial doublets internally and returns a new SCE +set.seed(123) +if (is.na(dbr)) { + message("No valid doublet_rate provided; using scDblFinder internal dbr estimation") + dbr <- NULL +} else { + message(paste0("Using provided doublet_rate (dbr): ", dbr)) +} + +sce <- scDblFinder( + assays(sce)[[1]], + BPPARAM = bp, + dbr = dbr +) + +# Generate a summary table +message("scDblFinder results summary:") +print(table(sce\$scDblFinder.class)) + +# Rename scDblFinder.* columns for consistency with other doublet methods. +# Replace prefix first, then replace any remaining dots with underscores. +idx <- grep("^scDblFinder\\\\.", colnames(colData(sce))) +colnames(colData(sce))[idx] <- gsub( + "\\\\.", + "_", + sub("^scDblFinder\\\\.", "scdblfinder_", colnames(colData(sce))[idx]) +) + +# The doublet calls must stay keyed by the original cell barcodes. If they are not +# present here, something went wrong during conversion or scDblFinder processing and +# we should fail instead of inventing replacement identifiers. +if (is.null(colnames(sce)) || length(colnames(sce)) != ncol(sce)) { + stop("scDblFinder output is missing valid cell barcodes; cannot write aligned h5ad and prediction outputs.") +} + +# Write the updated SingleCellExperiment directly as h5ad, explicitly mapping the +# primary assay to AnnData X so downstream readers see a valid matrix field. +primary_assay <- assayNames(sce)[1] +if (is.na(primary_assay) || primary_assay == "") { + stop("scDblFinder output is missing a primary assay; cannot write h5ad output.") +} +write_h5ad(sce, "${prefix}.h5ad", x_mapping = primary_assay) + +# Extract predictions for doublet removal step +# Create a binary doublet call based on class + +# Create predictions vector +doublet_calls <- colData(sce)\$scdblfinder_class == "doublet" + +# Create data frame without row.names first, then add them +predictions <- data.frame(doublet = doublet_calls) +row.names(predictions) <- colnames(sce) + +colnames(predictions) <- "${prefix}" + +# Save predictions to CSV +write.csv(predictions, "${prefix}.csv") + +################################################ +################################################ +## VERSIONS FILE ## +################################################ +################################################ + +r.version <- strsplit(version[['version.string']], ' ')[[1]][3] +scDblFinder.version <- as.character(packageVersion('scDblFinder')) + +writeLines( + c( + '"${task.process}":', + paste(' R:', r.version), + paste(' scDblFinder:', scDblFinder.version) + ), +'versions.yml') + +################################################ +################################################ +################################################ +################################################ diff --git a/modules/local/doublet_detection/scdblfinder/tests/main.nf.test b/modules/local/doublet_detection/scdblfinder/tests/main.nf.test new file mode 100644 index 00000000..b0831c94 --- /dev/null +++ b/modules/local/doublet_detection/scdblfinder/tests/main.nf.test @@ -0,0 +1,104 @@ +nextflow_process { + + name "Test Process SCDBLFINDER" + script "modules/local/doublet_detection/scdblfinder/main.nf" + process "SCDBLFINDER" + + tag "modules" + tag "modules_local" + + test("Should run without failures") { + + when { + params { + outdir = "$outputDir" + } + process { + """ + input[0] = channel.of([ + [ id: 'test' ], + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/scrnaseq/h5ad/SRR28679759_filtered_matrix.h5ad', checkIfExists: true), + null + ] + ) + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot( + process.out.versions, + process.out.predictions + ).match() } + , + { assert file(process.out.h5ad.get(0).get(1)).exists() }, + { assert file(process.out.h5ad.get(0).get(1)).size() > 0 } + ) + } + + } + + test("Should run with provided doublet_rate") { + + when { + params { + outdir = "$outputDir" + } + process { + """ + input[0] = channel.of([ + [ id: 'test' ], + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/scrnaseq/h5ad/SRR28679759_filtered_matrix.h5ad', checkIfExists: true), + 0.08 + ] + ) + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot( + process.out.versions, + process.out.predictions + ).match() }, + { assert file(process.out.h5ad.get(0).get(1)).exists() }, + { assert file(process.out.h5ad.get(0).get(1)).size() > 0 } + ) + } + + } + + test("Should run without failures - stub") { + + options '-stub' + + when { + params { + outdir = "$outputDir" + } + process { + """ + input[0] = channel.of([ + [ id: 'test' ], + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/scrnaseq/h5ad/SRR28679759_filtered_matrix.h5ad', checkIfExists: true), + null + ] + ) + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + +} diff --git a/modules/local/doublet_detection/scdblfinder/tests/main.nf.test.snap b/modules/local/doublet_detection/scdblfinder/tests/main.nf.test.snap new file mode 100644 index 00000000..dda2e33e --- /dev/null +++ b/modules/local/doublet_detection/scdblfinder/tests/main.nf.test.snap @@ -0,0 +1,91 @@ +{ + "Should run without failures - stub": { + "content": [ + { + "0": [ + [ + { + "id": "test" + }, + "test_scdblfinder.h5ad:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "1": [ + [ + { + "id": "test" + }, + "test_scdblfinder.csv:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "2": [ + "versions.yml:md5,d41d8cd98f00b204e9800998ecf8427e" + ], + "h5ad": [ + [ + { + "id": "test" + }, + "test_scdblfinder.h5ad:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "predictions": [ + [ + { + "id": "test" + }, + "test_scdblfinder.csv:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "versions": [ + "versions.yml:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + } + ], + "timestamp": "2026-03-12T12:34:23.397301125", + "meta": { + "nf-test": "0.9.4", + "nextflow": "25.10.4" + } + }, + "Should run without failures": { + "content": [ + [ + "versions.yml:md5,ce056c78586769ad5433f5fbb86f70c7" + ], + [ + [ + { + "id": "test" + }, + "test_scdblfinder.csv:md5,e92cd0219440b0caab1afb4b5b7f3e60" + ] + ] + ], + "timestamp": "2026-03-13T12:53:40.597040086", + "meta": { + "nf-test": "0.9.4", + "nextflow": "25.10.4" + } + }, + "Should run with provided doublet_rate": { + "content": [ + [ + "versions.yml:md5,ce056c78586769ad5433f5fbb86f70c7" + ], + [ + [ + { + "id": "test" + }, + "test_scdblfinder.csv:md5,ad5d0bf6045f81b6a04980d1f522420e" + ] + ] + ], + "timestamp": "2026-03-13T13:02:31.168458271", + "meta": { + "nf-test": "0.9.4", + "nextflow": "25.10.4" + } + } +} \ No newline at end of file diff --git a/nextflow_schema.json b/nextflow_schema.json index 5157e224..545f8f8d 100644 --- a/nextflow_schema.json +++ b/nextflow_schema.json @@ -105,8 +105,8 @@ "type": "string", "default": "scrublet", "description": "Specify the tools to use for doublet detection. Setting to 'none' will skip this step", - "help_text": "If you want to use multiple tools, separate them with a comma. Available methods are: solo, scrublet, doubletdetection, scds", - "pattern": "^(none|((solo|scrublet|doubletdetection|scds)?,?)*[^,]+$)" + "help_text": "If you want to use multiple tools, separate them with a comma. Available methods are: solo, scrublet, doubletdetection, scds, scdblfinder", + "pattern": "^(none|(solo|scrublet|doubletdetection|scds|scdblfinder)(,(solo|scrublet|doubletdetection|scds|scdblfinder))*)$" }, "doublet_detection_threshold": { "type": "integer", diff --git a/ro-crate-metadata.json b/ro-crate-metadata.json index 0ce2b699..d1e47b0c 100644 --- a/ro-crate-metadata.json +++ b/ro-crate-metadata.json @@ -23,7 +23,7 @@ "@type": "Dataset", "creativeWorkStatus": "InProgress", "datePublished": "2025-11-20T09:32:29+00:00", - "description": "

\n \n \n \"nf-core/scdownstream\"\n \n

\n\n[![Open in GitHub Codespaces](https://img.shields.io/badge/Open_In_GitHub_Codespaces-black?labelColor=grey&logo=github)](https://github.com/codespaces/new/nf-core/scdownstream)\n[![GitHub Actions CI Status](https://github.com/nf-core/scdownstream/actions/workflows/nf-test.yml/badge.svg)](https://github.com/nf-core/scdownstream/actions/workflows/nf-test.yml)\n[![GitHub Actions Linting Status](https://github.com/nf-core/scdownstream/actions/workflows/linting.yml/badge.svg)](https://github.com/nf-core/scdownstream/actions/workflows/linting.yml)[![AWS CI](https://img.shields.io/badge/CI%20tests-full%20size-FF9900?labelColor=000000&logo=Amazon%20AWS)](https://nf-co.re/scdownstream/results)[![Cite with Zenodo](http://img.shields.io/badge/DOI-10.5281/zenodo.XXXXXXX-1073c8?labelColor=000000)](https://doi.org/10.5281/zenodo.XXXXXXX)\n[![nf-test](https://img.shields.io/badge/unit_tests-nf--test-337ab7.svg)](https://www.nf-test.com)\n\n[![Nextflow](https://img.shields.io/badge/version-%E2%89%A525.10.0-green?style=flat&logo=nextflow&logoColor=white&color=%230DC09D&link=https%3A%2F%2Fnextflow.io)](https://www.nextflow.io/)\n[![nf-core template version](https://img.shields.io/badge/nf--core_template-3.5.1-green?style=flat&logo=nfcore&logoColor=white&color=%2324B064&link=https%3A%2F%2Fnf-co.re)](https://github.com/nf-core/tools/releases/tag/3.5.1)\n[![run with conda](http://img.shields.io/badge/run%20with-conda-3EB049?labelColor=000000&logo=anaconda)](https://docs.conda.io/en/latest/)\n[![run with docker](https://img.shields.io/badge/run%20with-docker-0db7ed?labelColor=000000&logo=docker)](https://www.docker.com/)\n[![run with singularity](https://img.shields.io/badge/run%20with-singularity-1d355c.svg?labelColor=000000)](https://sylabs.io/docs/)\n[![Launch on Seqera Platform](https://img.shields.io/badge/Launch%20%F0%9F%9A%80-Seqera%20Platform-%234256e7)](https://cloud.seqera.io/launch?pipeline=https://github.com/nf-core/scdownstream)\n\n[![Get help on Slack](http://img.shields.io/badge/slack-nf--core%20%23scdownstream-4A154B?labelColor=000000&logo=slack)](https://nfcore.slack.com/channels/scdownstream)[![Follow on Bluesky](https://img.shields.io/badge/bluesky-%40nf__core-1185fe?labelColor=000000&logo=bluesky)](https://bsky.app/profile/nf-co.re)[![Follow on Mastodon](https://img.shields.io/badge/mastodon-nf__core-6364ff?labelColor=FFFFFF&logo=mastodon)](https://mstdn.science/@nf_core)[![Watch on YouTube](http://img.shields.io/badge/youtube-nf--core-FF0000?labelColor=000000&logo=youtube)](https://www.youtube.com/c/nf-core)\n\n## Introduction\n\n**nf-core/scdownstream** is a bioinformatics pipeline that can be used to process already quantified single-cell RNA-seq data. It takes a samplesheet and h5ad-, SingleCellExperiment/Seurat- or CSV files as input and performs quality control, integration, dimensionality reduction and clustering. It produces an integrated h5ad and SingleCellExperiment file and an extensive QC report.\n\nThe pipeline is based on the learnings and implementations from the following pipelines (alphabetical):\n\n- [panpipes](https://github.com/DendrouLab/panpipes)\n- [scFlow](https://combiz.github.io/scFlow/)\n- [scRAFIKI](https://github.com/Mye-InfoBank/scRAFIKI)\n- [YASCP](https://github.com/wtsi-hgi/yascp)\n\n# ![nf-core/scdownstream](docs/images/metromap.png)\n\nSteps marked with the boat icon are not yet implemented. For the other steps, the pipeline uses the following tools:\n\n1. Per-sample preprocessing\n 1. Convert all RDS files to h5ad format\n 2. Create filtered matrix (if not provided)\n 3. Present QC for raw counts ([`MultiQC`](http://multiqc.info/))\n 4. Remove ambient RNA\n - [decontX](https://bioconductor.org/packages/release/bioc/html/decontX.html)\n - [soupX](https://cran.r-project.org/web/packages/SoupX/readme/README.html)\n - [cellbender](https://cellbender.readthedocs.io/en/latest/)\n - [scAR](https://docs.scvi-tools.org/en/stable/user_guide/models/scar.html)\n 5. Apply user-defined QC filters (can be defined per sample in the samplesheet)\n 6. Doublet detection (Majority vote possible)\n - [SOLO](https://docs.scvi-tools.org/en/stable/user_guide/models/solo.html)\n - [scrublet](https://scanpy.readthedocs.io/en/stable/api/generated/scanpy.pp.scrublet.html)\n - [DoubletDetection](https://doubletdetection.readthedocs.io/en/v2.5.2/doubletdetection.doubletdetection.html)\n - [SCDS](https://bioconductor.org/packages/devel/bioc/vignettes/scds/inst/doc/scds.html)\n2. Sample aggregation\n 1. Merge into a single h5ad file\n 2. Present QC for merged counts ([`MultiQC`](http://multiqc.info/))\n 3. Integration\n - [scVI](https://docs.scvi-tools.org/en/stable/user_guide/models/scvi.html)\n - [scANVI](https://docs.scvi-tools.org/en/stable/user_guide/models/scanvi.html)\n - [Harmony](https://portals.broadinstitute.org/harmony/articles/quickstart.html)\n - [BBKNN](https://github.com/Teichlab/bbknn)\n - [Combat](https://scanpy.readthedocs.io/en/latest/api/generated/scanpy.pp.combat.html)\n - [Seurat](https://satijalab.org/seurat/articles/integration_introduction)\n3. Cell type annotation\n - [celltypist](https://www.celltypist.org/)\n4. Clustering and dimensionality reduction\n 1. [Leiden clustering](https://scanpy.readthedocs.io/en/stable/generated/scanpy.tl.leiden.html)\n 2. [UMAP](https://scanpy.readthedocs.io/en/stable/generated/scanpy.tl.umap.html)\n5. Create report ([`MultiQC`](http://multiqc.info/))\n\n## Usage\n\n> [!NOTE]\n> If you are new to Nextflow and nf-core, please refer to [this page](https://nf-co.re/docs/usage/installation) on how to set-up Nextflow. Make sure to [test your setup](https://nf-co.re/docs/usage/introduction#how-to-run-a-pipeline) with `-profile test` before running the workflow on actual data.\n\n> [!NOTE]\n> If you are confused by the terms `filtered` and `unfiltered`, please check out the respective [documentation](https://nf-co.re/scdownstream/dev/docs/usage/#filtered-and-unfiltered-matrices).\n\nFirst, prepare a samplesheet with your input data that looks as follows:\n\n```csv title=\"samplesheet.csv\"\nsample,unfiltered\nsample1,/absolute/path/to/sample1.h5ad\nsample2,/absolute/path/to/sample3.h5\nsample3,relative/path/to/sample2.rds\nsample4,/absolute/path/to/sample3.csv\n```\n\nEach entry represents a h5ad, h5, RDS or CSV file. RDS files may contain any object that can be converted to a SingleCellExperiment using the [Seurat `as.SingleCellExperiment`](https://satijalab.org/seurat/reference/as.singlecellexperiment) function.\nCSV files should contain a matrix with genes as columns and cells as rows. The first column should contain cell names/barcodes.\n\n-->\n\nNow, you can run the pipeline using:\n\n```bash\nnextflow run nf-core/scdownstream \\\n -profile \\\n --input samplesheet.csv \\\n --outdir \n```\n\n> [!WARNING]\n> Please provide pipeline parameters via the CLI or Nextflow `-params-file` option. Custom config files including those provided by the `-c` Nextflow option can be used to provide any configuration _**except for parameters**_; see [docs](https://nf-co.re/docs/usage/getting_started/configuration#custom-configuration-files).\n\nFor more details and further functionality, please refer to the [usage documentation](https://nf-co.re/scdownstream/usage) and the [parameter documentation](https://nf-co.re/scdownstream/parameters).\n\n## Pipeline output\n\nTo see the results of an example test run with a full size dataset refer to the [results](https://nf-co.re/scdownstream/results) tab on the nf-core website pipeline page.\nFor more details about the output files and reports, please refer to the\n[output documentation](https://nf-co.re/scdownstream/output).\n\n## Credits\n\nnf-core/scdownstream was originally written by [Nico Trummer](https://github.com/nictru).\n\nWe thank the following people for their extensive assistance in the development of this pipeline (alphabetical):\n\n- [Fabian Rost](https://github.com/fbnrst)\n- [Fabiola Curion](https://github.com/bio-la)\n- [Gregor Sturm](https://github.com/grst)\n- [Jonathan Talbot-Martin](https://github.com/jtalbotmartin)\n- [Lukas Heumos](https://github.com/zethson)\n- [Matiss Ozols](https://github.com/maxozo)\n- [Nathan Skene](https://github.com/NathanSkene)\n- [Nurun Fancy](https://github.com/nfancy)\n- [Riley Grindle](https://github.com/Riley-Grindle)\n- [Ryan Seaman](https://github.com/RPSeaman)\n- [Steffen M\u00f6ller](https://github.com/smoe)\n- [Wojtek Sowinski](https://github.com/WojtekSowinski)\n\n## Contributions and Support\n\nIf you would like to contribute to this pipeline, please see the [contributing guidelines](.github/CONTRIBUTING.md).\n\nFor further information or help, don't hesitate to get in touch on the [Slack `#scdownstream` channel](https://nfcore.slack.com/channels/scdownstream) (you can join with [this invite](https://nf-co.re/join/slack)).\n\n## Citations\n\n\n\n\n\n\nAn extensive list of references for the tools used by the pipeline can be found in the [`CITATIONS.md`](CITATIONS.md) file.\n\nYou can cite the `nf-core` publication as follows:\n\n> **The nf-core framework for community-curated bioinformatics pipelines.**\n>\n> Philip Ewels, Alexander Peltzer, Sven Fillinger, Harshil Patel, Johannes Alneberg, Andreas Wilm, Maxime Ulysse Garcia, Paolo Di Tommaso & Sven Nahnsen.\n>\n> _Nat Biotechnol._ 2020 Feb 13. doi: [10.1038/s41587-020-0439-x](https://dx.doi.org/10.1038/s41587-020-0439-x).\n", + "description": "

\n \n \n \"nf-core/scdownstream\"\n \n

\n\n[![Open in GitHub Codespaces](https://img.shields.io/badge/Open_In_GitHub_Codespaces-black?labelColor=grey&logo=github)](https://github.com/codespaces/new/nf-core/scdownstream)\n[![GitHub Actions CI Status](https://github.com/nf-core/scdownstream/actions/workflows/nf-test.yml/badge.svg)](https://github.com/nf-core/scdownstream/actions/workflows/nf-test.yml)\n[![GitHub Actions Linting Status](https://github.com/nf-core/scdownstream/actions/workflows/linting.yml/badge.svg)](https://github.com/nf-core/scdownstream/actions/workflows/linting.yml)[![AWS CI](https://img.shields.io/badge/CI%20tests-full%20size-FF9900?labelColor=000000&logo=Amazon%20AWS)](https://nf-co.re/scdownstream/results)[![Cite with Zenodo](http://img.shields.io/badge/DOI-10.5281/zenodo.XXXXXXX-1073c8?labelColor=000000)](https://doi.org/10.5281/zenodo.XXXXXXX)\n[![nf-test](https://img.shields.io/badge/unit_tests-nf--test-337ab7.svg)](https://www.nf-test.com)\n\n[![Nextflow](https://img.shields.io/badge/version-%E2%89%A525.10.0-green?style=flat&logo=nextflow&logoColor=white&color=%230DC09D&link=https%3A%2F%2Fnextflow.io)](https://www.nextflow.io/)\n[![nf-core template version](https://img.shields.io/badge/nf--core_template-3.5.1-green?style=flat&logo=nfcore&logoColor=white&color=%2324B064&link=https%3A%2F%2Fnf-co.re)](https://github.com/nf-core/tools/releases/tag/3.5.1)\n[![run with conda](http://img.shields.io/badge/run%20with-conda-3EB049?labelColor=000000&logo=anaconda)](https://docs.conda.io/en/latest/)\n[![run with docker](https://img.shields.io/badge/run%20with-docker-0db7ed?labelColor=000000&logo=docker)](https://www.docker.com/)\n[![run with singularity](https://img.shields.io/badge/run%20with-singularity-1d355c.svg?labelColor=000000)](https://sylabs.io/docs/)\n[![Launch on Seqera Platform](https://img.shields.io/badge/Launch%20%F0%9F%9A%80-Seqera%20Platform-%234256e7)](https://cloud.seqera.io/launch?pipeline=https://github.com/nf-core/scdownstream)\n\n[![Get help on Slack](http://img.shields.io/badge/slack-nf--core%20%23scdownstream-4A154B?labelColor=000000&logo=slack)](https://nfcore.slack.com/channels/scdownstream)[![Follow on Bluesky](https://img.shields.io/badge/bluesky-%40nf__core-1185fe?labelColor=000000&logo=bluesky)](https://bsky.app/profile/nf-co.re)[![Follow on Mastodon](https://img.shields.io/badge/mastodon-nf__core-6364ff?labelColor=FFFFFF&logo=mastodon)](https://mstdn.science/@nf_core)[![Watch on YouTube](http://img.shields.io/badge/youtube-nf--core-FF0000?labelColor=000000&logo=youtube)](https://www.youtube.com/c/nf-core)\n\n## Introduction\n\n**nf-core/scdownstream** is a bioinformatics pipeline that can be used to process already quantified single-cell RNA-seq data. It takes a samplesheet and h5ad-, SingleCellExperiment/Seurat- or CSV files as input and performs quality control, integration, dimensionality reduction and clustering. It produces an integrated h5ad and SingleCellExperiment file and an extensive QC report.\n\nThe pipeline is based on the learnings and implementations from the following pipelines (alphabetical):\n\n- [panpipes](https://github.com/DendrouLab/panpipes)\n- [scFlow](https://combiz.github.io/scFlow/)\n- [scRAFIKI](https://github.com/Mye-InfoBank/scRAFIKI)\n- [YASCP](https://github.com/wtsi-hgi/yascp)\n\n# ![nf-core/scdownstream](docs/images/metromap.png)\n\nSteps marked with the boat icon are not yet implemented. For the other steps, the pipeline uses the following tools:\n\n1. Per-sample preprocessing\n 1. Convert all RDS files to h5ad format\n 2. Create filtered matrix (if not provided)\n 3. Present QC for raw counts ([`MultiQC`](http://multiqc.info/))\n 4. Remove ambient RNA\n - [decontX](https://bioconductor.org/packages/release/bioc/html/decontX.html)\n - [soupX](https://cran.r-project.org/web/packages/SoupX/readme/README.html)\n - [cellbender](https://cellbender.readthedocs.io/en/latest/)\n - [scAR](https://docs.scvi-tools.org/en/stable/user_guide/models/scar.html)\n 5. Apply user-defined QC filters (can be defined per sample in the samplesheet)\n 6. Doublet detection (Majority vote possible)\n - [SOLO](https://docs.scvi-tools.org/en/stable/user_guide/models/solo.html)\n - [scrublet](https://scanpy.readthedocs.io/en/stable/api/generated/scanpy.pp.scrublet.html)\n - [DoubletDetection](https://doubletdetection.readthedocs.io/en/v2.5.2/doubletdetection.doubletdetection.html)\n - [SCDS](https://bioconductor.org/packages/devel/bioc/vignettes/scds/inst/doc/scds.html)\n - [scDblFinder](https://bioconductor.org/packages/release/bioc/html/scDblFinder.html)\n2. Sample aggregation\n 1. Merge into a single h5ad file\n 2. Present QC for merged counts ([`MultiQC`](http://multiqc.info/))\n 3. Integration\n - [scVI](https://docs.scvi-tools.org/en/stable/user_guide/models/scvi.html)\n - [scANVI](https://docs.scvi-tools.org/en/stable/user_guide/models/scanvi.html)\n - [Harmony](https://portals.broadinstitute.org/harmony/articles/quickstart.html)\n - [BBKNN](https://github.com/Teichlab/bbknn)\n - [Combat](https://scanpy.readthedocs.io/en/latest/api/generated/scanpy.pp.combat.html)\n - [Seurat](https://satijalab.org/seurat/articles/integration_introduction)\n3. Cell type annotation\n - [celltypist](https://www.celltypist.org/)\n4. Clustering and dimensionality reduction\n 1. [Leiden clustering](https://scanpy.readthedocs.io/en/stable/generated/scanpy.tl.leiden.html)\n 2. [UMAP](https://scanpy.readthedocs.io/en/stable/generated/scanpy.tl.umap.html)\n5. Create report ([`MultiQC`](http://multiqc.info/))\n\n## Usage\n\n> [!NOTE]\n> If you are new to Nextflow and nf-core, please refer to [this page](https://nf-co.re/docs/usage/installation) on how to set-up Nextflow. Make sure to [test your setup](https://nf-co.re/docs/usage/introduction#how-to-run-a-pipeline) with `-profile test` before running the workflow on actual data.\n\n> [!NOTE]\n> If you are confused by the terms `filtered` and `unfiltered`, please check out the respective [documentation](https://nf-co.re/scdownstream/dev/docs/usage/#filtered-and-unfiltered-matrices).\n\nFirst, prepare a samplesheet with your input data that looks as follows:\n\n```csv title=\"samplesheet.csv\"\nsample,unfiltered\nsample1,/absolute/path/to/sample1.h5ad\nsample2,/absolute/path/to/sample3.h5\nsample3,relative/path/to/sample2.rds\nsample4,/absolute/path/to/sample3.csv\n```\n\nEach entry represents a h5ad, h5, RDS or CSV file. RDS files may contain any object that can be converted to a SingleCellExperiment using the [Seurat `as.SingleCellExperiment`](https://satijalab.org/seurat/reference/as.singlecellexperiment) function.\nCSV files should contain a matrix with genes as columns and cells as rows. The first column should contain cell names/barcodes.\n\nFor `scDblFinder`, you can optionally add a `doublet_rate` column (values between `0` and `1`) to the samplesheet. If omitted, `scDblFinder` estimates the doublet rate internally.\n\n-->\n\nNow, you can run the pipeline using:\n\n```bash\nnextflow run nf-core/scdownstream \\\n -profile \\\n --input samplesheet.csv \\\n --outdir \n```\n\n> [!WARNING]\n> Please provide pipeline parameters via the CLI or Nextflow `-params-file` option. Custom config files including those provided by the `-c` Nextflow option can be used to provide any configuration _**except for parameters**_; see [docs](https://nf-co.re/docs/usage/getting_started/configuration#custom-configuration-files).\n\nFor more details and further functionality, please refer to the [usage documentation](https://nf-co.re/scdownstream/usage) and the [parameter documentation](https://nf-co.re/scdownstream/parameters).\n\n## Pipeline output\n\nTo see the results of an example test run with a full size dataset refer to the [results](https://nf-co.re/scdownstream/results) tab on the nf-core website pipeline page.\nFor more details about the output files and reports, please refer to the\n[output documentation](https://nf-co.re/scdownstream/output).\n\n## Credits\n\nnf-core/scdownstream was originally written by [Nico Trummer](https://github.com/nictru).\n\nWe thank the following people for their extensive assistance in the development of this pipeline (alphabetical):\n\n- [Fabian Rost](https://github.com/fbnrst)\n- [Fabiola Curion](https://github.com/bio-la)\n- [Gregor Sturm](https://github.com/grst)\n- [Jonathan Talbot-Martin](https://github.com/jtalbotmartin)\n- [Lukas Heumos](https://github.com/zethson)\n- [Matiss Ozols](https://github.com/maxozo)\n- [Nathan Skene](https://github.com/NathanSkene)\n- [Nurun Fancy](https://github.com/nfancy)\n- [Riley Grindle](https://github.com/Riley-Grindle)\n- [Ryan Seaman](https://github.com/RPSeaman)\n- [Steffen M\u00f6ller](https://github.com/smoe)\n- [Wojtek Sowinski](https://github.com/WojtekSowinski)\n\n## Contributions and Support\n\nIf you would like to contribute to this pipeline, please see the [contributing guidelines](.github/CONTRIBUTING.md).\n\nFor further information or help, don't hesitate to get in touch on the [Slack `#scdownstream` channel](https://nfcore.slack.com/channels/scdownstream) (you can join with [this invite](https://nf-co.re/join/slack)).\n\n## Citations\n\n\n\n\n\n\nAn extensive list of references for the tools used by the pipeline can be found in the [`CITATIONS.md`](CITATIONS.md) file.\n\nYou can cite the `nf-core` publication as follows:\n\n> **The nf-core framework for community-curated bioinformatics pipelines.**\n>\n> Philip Ewels, Alexander Peltzer, Sven Fillinger, Harshil Patel, Johannes Alneberg, Andreas Wilm, Maxime Ulysse Garcia, Paolo Di Tommaso & Sven Nahnsen.\n>\n> _Nat Biotechnol._ 2020 Feb 13. doi: [10.1038/s41587-020-0439-x](https://dx.doi.org/10.1038/s41587-020-0439-x).\n", "hasPart": [ { "@id": "main.nf" diff --git a/subworkflows/local/doublet_detection/main.nf b/subworkflows/local/doublet_detection/main.nf index c7371ff3..81e26962 100644 --- a/subworkflows/local/doublet_detection/main.nf +++ b/subworkflows/local/doublet_detection/main.nf @@ -2,6 +2,7 @@ include { SCVITOOLS_SOLO } from '../../../modules/nf-core/scvitools/solo' include { SCANPY_SCRUBLET } from '../../../modules/nf-core/scanpy/scrublet' include { DOUBLETDETECTION } from '../../../modules/nf-core/doubletdetection' include { SCDS } from '../../../modules/local/doublet_detection/scds' +include { SCDBLFINDER } from '../../../modules/local/doublet_detection/scdblfinder' include { DOUBLET_REMOVAL } from '../../../modules/local/doublet_detection/doublet_removal' workflow DOUBLET_DETECTION { @@ -20,13 +21,14 @@ workflow DOUBLET_DETECTION { log.info("DOUBLET_DETECTION: Not performed since no methods selected.") } else { ch_batch_col = ch_h5ad.map { meta, _h5ad -> meta.batch_col } + ch_h5ad_doublet_rate = ch_h5ad.map { meta, h5ad -> [meta, h5ad, meta.doublet_rate] } if (methods.contains('scds')) { SCDS ( ch_h5ad ) ch_predictions = ch_predictions.mix(SCDS.out.predictions) - ch_versions = SCDS.out.versions + ch_versions = ch_versions.mix(SCDS.out.versions) } if (methods.contains('solo')) { @@ -36,7 +38,7 @@ workflow DOUBLET_DETECTION { scvi_max_epochs ?: [] ) ch_predictions = ch_predictions.mix(SCVITOOLS_SOLO.out.predictions) - ch_versions = SCVITOOLS_SOLO.out.versions + ch_versions = ch_versions.mix(SCVITOOLS_SOLO.out.versions) } if (methods.contains('scrublet')) { @@ -45,7 +47,7 @@ workflow DOUBLET_DETECTION { ch_batch_col ) ch_predictions = ch_predictions.mix(SCANPY_SCRUBLET.out.predictions) - ch_versions = SCANPY_SCRUBLET.out.versions + ch_versions = ch_versions.mix(SCANPY_SCRUBLET.out.versions) } if (methods.contains('doubletdetection')) { @@ -53,7 +55,15 @@ workflow DOUBLET_DETECTION { ch_h5ad ) ch_predictions = ch_predictions.mix(DOUBLETDETECTION.out.predictions) - ch_versions = DOUBLETDETECTION.out.versions + ch_versions = ch_versions.mix(DOUBLETDETECTION.out.versions) + } + + if (methods.contains('scdblfinder')) { + SCDBLFINDER ( + ch_h5ad_doublet_rate + ) + ch_predictions = ch_predictions.mix(SCDBLFINDER.out.predictions) + ch_versions = ch_versions.mix(SCDBLFINDER.out.versions) } DOUBLET_REMOVAL ( diff --git a/subworkflows/local/doublet_detection/tests/main.nf.test b/subworkflows/local/doublet_detection/tests/main.nf.test index 26fb4f2b..b8f0ef18 100644 --- a/subworkflows/local/doublet_detection/tests/main.nf.test +++ b/subworkflows/local/doublet_detection/tests/main.nf.test @@ -50,7 +50,7 @@ nextflow_workflow { file(params.modules_testdata_base_path + 'genomics/homo_sapiens/scrnaseq/h5ad/SRR28679759_filtered_matrix.h5ad', checkIfExists: true) ] ) - input[1] = ['scds', 'solo', 'scrublet'] + input[1] = ['scds', 'solo', 'scrublet', 'scdblfinder'] input[2] = 2 input[3] = 1 """