From 531975c004dfd573c43a3663f330256289e7f123 Mon Sep 17 00:00:00 2001 From: Natalia Garcia Date: Wed, 27 May 2026 11:59:11 +0000 Subject: [PATCH] Template updates: sort threads param --- lib/common.nf | 4 ++-- lib/ingress.nf | 7 +++++-- main.nf | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/common.nf b/lib/common.nf index 32ccd05..1aed50d 100644 --- a/lib/common.nf +++ b/lib/common.nf @@ -93,7 +93,7 @@ process minimap2_alignment { def fastq_input_cmd = "touch reads.header && fastcat --reheader reads/*" def bam_or_fastq_input = params.bam ? bam_input_cmd : fastq_input_cmd def minimap2_opts = bsargs["minimap2_opts"] - + def sort_threads = bsargs["sort_threads"] """ rm -rf bamstats_results mkdir bamstats_results @@ -103,7 +103,7 @@ process minimap2_alignment { | workflow-glue reheader_samstream reads.header \ --insert \$'@PG\\tID:reset\\tPN:samtools\\tCL:${reset_cmd_body}' \ --insert \$'@PG\\tID:fastq\\tPN:samtools\\tCL:${fastq_cmd_body}' \ - | samtools sort -u -O BAM - \ + | samtools sort -@ ${sort_threads} -u -O BAM - \ | tee >(samtools view --reference ${reference} \ --write-index -o reads.${align_ext}##idx##reads.${align_ext}.${index_ext} -) \ | bamstats -s ${meta.alias} -u \ diff --git a/lib/ingress.nf b/lib/ingress.nf index 35c502c..d457634 100644 --- a/lib/ingress.nf +++ b/lib/ingress.nf @@ -182,6 +182,7 @@ def add_number_of_reads_to_meta(ch, String input_type_format) { * - "alignment_threads": number of threads to use for alignment process (default: 6) * - "output_xam_fmt": alignment output format, `bam` outputs a BAM file with index (.bam, .bai), `cram` outputs a CRAM file with index (.cram, .crai) + * - "sort_threads": number of threads to use for sorting aligned reads (default: 1) * @param aln_ref_ch: optional channel with a reference tuple (ref, ref_idx) to align against. * If provided alignment will be attempted if inputs are unaligned or not already aligned to this ref. * @return: channel of `[Map(alias, barcode, type, ...), Path|null, Path|null]`. @@ -337,7 +338,8 @@ def fastq_ingress(Map arguments, aln_ref_ch = null) * - "alignment_threads": number of threads to use for alignment process (default: 6) * - "output_xam_fmt": alignment output format, `bam` outputs an BAM file with index (.bam, .bai), `cram` outputs a CRAM file with index (.cram, .crai) -* - "force_alignment": boolean. Run alignment regardless of inputs. + * - "sort_threads": number of threads to use for sorting aligned reads (default: 1) + * - "force_alignment": boolean. Run alignment regardless of inputs. * @param aln_ref_ch: optional channel with a reference tuple (ref, ref_idx) to align against. * If provided alignment will be attempted if inputs are unaligned or not already aligned to this ref. * @return: channel of `[Map(alias, barcode, type, ...), Path|null, Path|null]`. @@ -985,7 +987,8 @@ Map parse_arguments(String func_name, Map arguments, Map extra_kwargs=[:]) { "minimap2_memory": ["8GB", "15GB", "31GB"], "minimap2_opts": "-x lr:hq", "alignment_threads": 6, - "output_xam_fmt": "bam" // or cram + "output_xam_fmt": "bam", // or cram + "sort_threads": 1 // TODO hook this up for ingress sorts as well ] ArgumentParser parser = new ArgumentParser( args: required_args, diff --git a/main.nf b/main.nf index d808e89..88b5af7 100644 --- a/main.nf +++ b/main.nf @@ -232,6 +232,7 @@ workflow { "analyse_fail": params.analyse_fail, "fastcat_extra_args": "", "required_sample_types": [], + "sort_threads": 3, ] if (params.fastq) {