From 313e8132b4a4a55da1c803a4348e22ec0b0e0d09 Mon Sep 17 00:00:00 2001 From: Sam Minot Date: Tue, 29 Jul 2025 11:11:41 -0700 Subject: [PATCH 1/7] Account for the case where no whitelist was provided --- modules/local/star_align.nf | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/local/star_align.nf b/modules/local/star_align.nf index d5751084..1c8f7044 100644 --- a/modules/local/star_align.nf +++ b/modules/local/star_align.nf @@ -61,10 +61,18 @@ process STAR_ALIGN { // separate forward from reverse pairs def (forward, reverse) = reads.collate(2).transpose() """ - if [[ $whitelist == *.gz ]]; then - gzip -cdf $whitelist > whitelist.uncompressed.txt + # If the whitelist was not provided + if [[ -z "$whitelist" ]]; then + echo "Whitelist file not provided." >&2 + soloCBwhitelistArg="" else - cp $whitelist whitelist.uncompressed.txt + if [[ "$whitelist" == *.gz ]]; then + gzip -cdf "$whitelist" > whitelist.uncompressed.txt + else + cp "$whitelist" whitelist.uncompressed.txt + fi + soloCBwhitelistArg="--soloCBwhitelist whitelist.uncompressed.txt" + echo "Whitelist file provided - $whitelist." >&2 fi STAR \\ @@ -72,7 +80,7 @@ process STAR_ALIGN { --readFilesIn ${reverse.join( "," )} ${forward.join( "," )} \\ --runThreadN $task.cpus \\ --outFileNamePrefix $prefix. \\ - --soloCBwhitelist whitelist.uncompressed.txt \\ + \$soloCBwhitelistArg \\ --soloType $protocol \\ --soloFeatures $star_feature \\ $other_10x_parameters \\ From 409b14a8435bf7b6476ddc6e39b4fdea66627d4e Mon Sep 17 00:00:00 2001 From: Sam Minot Date: Tue, 29 Jul 2025 11:31:29 -0700 Subject: [PATCH 2/7] If the SmartSeq protocol is used, set soloUMIdedup to NoDedup --- modules/local/star_align.nf | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/local/star_align.nf b/modules/local/star_align.nf index 1c8f7044..82a40721 100644 --- a/modules/local/star_align.nf +++ b/modules/local/star_align.nf @@ -75,6 +75,12 @@ process STAR_ALIGN { echo "Whitelist file provided - $whitelist." >&2 fi + # If the SmartSeq protocol is used, set soloUMIdedup to NoDedup + if [[ "$protocol" == "SmartSeq" ]]; then + echo "SmartSeq protocol detected, setting --soloUMIdedup to NoDedup." >&2 + soloUMIdedupArg="--soloUMIdedup NoDedup" + fi + STAR \\ --genomeDir $index \\ --readFilesIn ${reverse.join( "," )} ${forward.join( "," )} \\ @@ -83,6 +89,7 @@ process STAR_ALIGN { \$soloCBwhitelistArg \\ --soloType $protocol \\ --soloFeatures $star_feature \\ + \$soloUMIdedupArg \\ $other_10x_parameters \\ $out_sam_type \\ $ignore_gtf \\ From 8c741401ac2ea2fdff9611674557b6ca92d4241a Mon Sep 17 00:00:00 2001 From: Sam Minot Date: Tue, 29 Jul 2025 15:33:07 -0700 Subject: [PATCH 3/7] Skip seurat object when only 1 cell is detected --- modules/local/templates/anndatar_convert.R | 35 +++++++++++++--------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/modules/local/templates/anndatar_convert.R b/modules/local/templates/anndatar_convert.R index 6f78e282..4d4bc989 100755 --- a/modules/local/templates/anndatar_convert.R +++ b/modules/local/templates/anndatar_convert.R @@ -9,20 +9,27 @@ library(SingleCellExperiment) # read input adata <- read_h5ad("${h5ad}") - -# convert to Seurat -obj <- adata\$to_Seurat() - -# save files -dir.create(file.path("$meta.id"), showWarnings = FALSE) -saveRDS(obj, file = "${meta.id}_${meta.input_type}_matrix.seurat.rds") - -# convert to SingleCellExperiment -obj <- adata\$to_SingleCellExperiment() - -# save files -dir.create(file.path("$meta.id"), showWarnings = FALSE) -saveRDS(obj, file = "${meta.id}_${meta.input_type}_matrix.sce.rds") +print("Read in ${h5ad} successfully.") +print(adata) + +# If there is only 1 cell +if(adata$shape()[1] == 1) { + print("The input file contains only one cell. Cannot create Seurat object.") +}else{ + # convert to Seurat + obj <- adata\$to_Seurat() + + # save files + dir.create(file.path("$meta.id"), showWarnings = FALSE) + saveRDS(obj, file = "${meta.id}_${meta.input_type}_matrix.seurat.rds") + + # convert to SingleCellExperiment + obj <- adata\$to_SingleCellExperiment() + + # save files + dir.create(file.path("$meta.id"), showWarnings = FALSE) + saveRDS(obj, file = "${meta.id}_${meta.input_type}_matrix.sce.rds") +} # # save versions file From 4034422bc3f9bd61bcce9645ffc276be90b7cf29 Mon Sep 17 00:00:00 2001 From: Sam Minot Date: Tue, 29 Jul 2025 16:22:49 -0700 Subject: [PATCH 4/7] Must escape in a template --- modules/local/templates/anndatar_convert.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/local/templates/anndatar_convert.R b/modules/local/templates/anndatar_convert.R index 4d4bc989..5604d2d5 100755 --- a/modules/local/templates/anndatar_convert.R +++ b/modules/local/templates/anndatar_convert.R @@ -13,7 +13,7 @@ print("Read in ${h5ad} successfully.") print(adata) # If there is only 1 cell -if(adata$shape()[1] == 1) { +if(adata\$shape()[1] == 1) { print("The input file contains only one cell. Cannot create Seurat object.") }else{ # convert to Seurat From 7f9c592aad7c13fa439f488e94d52d1c43d80e91 Mon Sep 17 00:00:00 2001 From: Sam Minot Date: Wed, 30 Jul 2025 10:01:23 -0700 Subject: [PATCH 5/7] rds is optional --- modules/local/anndatar_convert.nf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/local/anndatar_convert.nf b/modules/local/anndatar_convert.nf index f17e0483..67e39051 100644 --- a/modules/local/anndatar_convert.nf +++ b/modules/local/anndatar_convert.nf @@ -14,7 +14,7 @@ process ANNDATAR_CONVERT { tuple val(meta), path(h5ad) output: - tuple val(meta), path("${meta.id}_${meta.input_type}_matrix*.rds"), emit: rds + tuple val(meta), path("${meta.id}_${meta.input_type}_matrix*.rds"), emit: rds, optional: true path "versions.yml" , emit: versions when: From b0ba2e5bab3eff2d3b2d5dc87145ad4e8e5252e0 Mon Sep 17 00:00:00 2001 From: Sam Minot Date: Thu, 31 Jul 2025 14:12:24 -0700 Subject: [PATCH 6/7] Fix unbound variable --- modules/local/star_align.nf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/local/star_align.nf b/modules/local/star_align.nf index 82a40721..7e78b33e 100644 --- a/modules/local/star_align.nf +++ b/modules/local/star_align.nf @@ -79,6 +79,8 @@ process STAR_ALIGN { if [[ "$protocol" == "SmartSeq" ]]; then echo "SmartSeq protocol detected, setting --soloUMIdedup to NoDedup." >&2 soloUMIdedupArg="--soloUMIdedup NoDedup" + else + soloUMIdedupArg="" fi STAR \\ From 65feb08cdbf0401245ebed48938bbec1debba368 Mon Sep 17 00:00:00 2001 From: Sam Minot Date: Fri, 1 Aug 2025 10:56:32 -0700 Subject: [PATCH 7/7] Filtered counts are not always present --- modules/local/star_align.nf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/local/star_align.nf b/modules/local/star_align.nf index 7e78b33e..42d1bfa9 100644 --- a/modules/local/star_align.nf +++ b/modules/local/star_align.nf @@ -29,7 +29,7 @@ process STAR_ALIGN { tuple val(meta), path('*d.out.bam') , emit: bam tuple val(meta), path('*.Solo.out') , emit: counts tuple val(meta), path ("*.Solo.out/Gene*/raw") , emit: raw_counts - tuple val(meta), path ("*.Solo.out/Gene*/filtered") , emit: filtered_counts + tuple val(meta), path ("*.Solo.out/Gene*/filtered") , emit: filtered_counts, optional: true tuple val(meta), path ("*.Solo.out/Velocyto/velocyto_raw") , emit: raw_velocyto, optional:true tuple val(meta), path ("*.Solo.out/Velocyto/velocyto_filtered"), emit: filtered_velocyto, optional:true tuple val(meta), path('*Log.final.out') , emit: log_final