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: diff --git a/modules/local/star_align.nf b/modules/local/star_align.nf index d5751084..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 @@ -61,10 +61,26 @@ 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 + + # 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" + else + soloUMIdedupArg="" fi STAR \\ @@ -72,9 +88,10 @@ process STAR_ALIGN { --readFilesIn ${reverse.join( "," )} ${forward.join( "," )} \\ --runThreadN $task.cpus \\ --outFileNamePrefix $prefix. \\ - --soloCBwhitelist whitelist.uncompressed.txt \\ + \$soloCBwhitelistArg \\ --soloType $protocol \\ --soloFeatures $star_feature \\ + \$soloUMIdedupArg \\ $other_10x_parameters \\ $out_sam_type \\ $ignore_gtf \\ diff --git a/modules/local/templates/anndatar_convert.R b/modules/local/templates/anndatar_convert.R index 6f78e282..5604d2d5 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