diff --git a/tools/CHANGELOG.md b/tools/CHANGELOG.md index 4eed0495b..2c8c85863 100644 --- a/tools/CHANGELOG.md +++ b/tools/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ## 2026 November +### Added + +- New `concatenate_fastqs` task in `util.wdl` + ### Changed - Updated all WDL to v1.3 [#338](https://github.com/stjudecloud/workflows/pull/338) diff --git a/tools/test/util.yaml b/tools/test/util.yaml index 6092ecaea..d5048711e 100644 --- a/tools/test/util.yaml +++ b/tools/test/util.yaml @@ -106,4 +106,12 @@ split_fastq: - 100 - 1000 - 10000 - - 100000 \ No newline at end of file + - 100000 +concatenate_fastqs: + - name: works + inputs: + fastqs: + - [fastqs/test_R1.fq.gz, fastqs/random10k.r1.fq.gz] + - [fastqs/test_R1.fq.gz] + outfile_name: + - concatenated.fastq.gz diff --git a/tools/util.wdl b/tools/util.wdl index 868221191..bed859caf 100644 --- a/tools/util.wdl +++ b/tools/util.wdl @@ -470,3 +470,45 @@ task split_fastq { maxRetries: 1 } } + +task concatenate_fastqs { + meta { + description: "Concatenates multiple gzipped FASTQ files into a single gzipped FASTQ file" + help: "Input files are concatenated in the order provided. Gzip streams are concatenated directly without decompression, so all inputs must be gzipped." + outputs: { + concatenated_fastq: "Single gzipped FASTQ file containing all reads from the input FASTQs, in input order", + } + } + + parameter_meta { + fastqs: "Gzipped FASTQ files to concatenate. Order is preserved in the output." + outfile_name: "Name for the concatenated FASTQ file" + modify_disk_size_gb: "Add to or subtract from dynamic disk space allocation. Default disk size is determined by the size of the inputs. Specified in GB." + } + + input { + Array[File]+ fastqs + String outfile_name + Int modify_disk_size_gb = 0 + } + + Float fastqs_size = size(fastqs, "GB") + Int disk_size_gb = ceil(fastqs_size * 2) + 10 + modify_disk_size_gb + + command <<< + set -euo pipefail + + cat ~{sep(" ", squote(fastqs))} > "~{outfile_name}" + >>> + + output { + File concatenated_fastq = outfile_name + } + + requirements { + memory: "4 GB" + disks: "~{disk_size_gb} GB" + container: "ghcr.io/stjudecloud/util:3.0.4" + maxRetries: 1 + } +} diff --git a/workflows/general/CHANGELOG.md b/workflows/general/CHANGELOG.md index 1c654ad7b..e370590e9 100644 --- a/workflows/general/CHANGELOG.md +++ b/workflows/general/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/). +## Added + +- `concatenate` option to `bam_to_fastqs` to merge the per-read-group FASTQs into a single FASTQ (Single-End) or a single pair of FASTQs (Paired-End) + ## Changed - Updated all WDL to v1.3 [#338](https://github.com/stjudecloud/workflows/pull/338) diff --git a/workflows/general/bam-to-fastqs.wdl b/workflows/general/bam-to-fastqs.wdl index a1b85954f..f7c50f5ec 100644 --- a/workflows/general/bam-to-fastqs.wdl +++ b/workflows/general/bam-to-fastqs.wdl @@ -2,6 +2,7 @@ version 1.3 import "../../tools/fq.wdl" import "../../tools/samtools.wdl" +import "../../tools/util.wdl" workflow bam_to_fastqs { meta { @@ -9,20 +10,24 @@ workflow bam_to_fastqs { description: "Converts an input BAM file to one or more FASTQ files, performing QC checks along the way" category: "Utility" outputs: { - read1s: "Array of FASTQ files corresponding to either `first` reads (if `paired_end = true`) or all reads (if `paired_end = false`)", - read2s: "Array of FASTQ files corresponding to `last` reads (if `paired_end = true`)", + read1s: "Array of FASTQ files corresponding to either `first` reads (if `paired_end = true`) or all reads (if `paired_end = false`). If `concatenate = true`, contains a single FASTQ file.", + read2s: "Array of FASTQ files corresponding to `last` reads (if `paired_end = true`). If `concatenate = true`, contains a single (possibly undefined, if `paired_end = false`) FASTQ file.", } allowNestedInputs: true } parameter_meta { bam: "BAM file to split into FASTQs" + prefix: "Prefix for the concatenated FASTQ files. Only used if `concatenate = true`. The extensions `.R1.fastq.gz` and `.R2.fastq.gz` (if `paired_end = true`) or `.fastq.gz` (if `paired_end = false`) will be added." + concatenate: "Concatenate the per-read-group FASTQs into a single FASTQ (Single-End) or a single pair of FASTQs (Paired-End)?" paired_end: "Is the data Paired-End (true) or Single-End (false)?" use_all_cores: "Use all cores for multi-core steps?" } input { File bam + String prefix = basename(bam, ".bam") + Boolean concatenate = false Boolean paired_end = true Boolean use_all_cores = false } @@ -60,10 +65,32 @@ workflow bam_to_fastqs { } } + Array[File] split_read1s = if paired_end + then select_all(bam_to_fastq.read_one_fastq_gz) + else select_all(bam_to_fastq.single_end_reads_fastq_gz) + Array[File?] split_read2s = bam_to_fastq.read_two_fastq_gz + + if (concatenate) { + call util.concatenate_fastqs as concatenate_read1s after fqlint after se_fqlint { + fastqs = split_read1s, + outfile_name = prefix + (if paired_end then ".R1.fastq.gz" else ".fastq.gz"), + } + if (paired_end) { + call util.concatenate_fastqs as concatenate_read2s after fqlint { + fastqs = select_all(split_read2s), + outfile_name = prefix + ".R2.fastq.gz", + } + } + } + output { - Array[File] read1s = if paired_end - then select_all(bam_to_fastq.read_one_fastq_gz) - else select_all(bam_to_fastq.single_end_reads_fastq_gz) - Array[File?] read2s = bam_to_fastq.read_two_fastq_gz + Array[File] read1s = if concatenate + then select_all([ + concatenate_read1s.concatenated_fastq, + ]) + else split_read1s + Array[File?] read2s = if concatenate + then [concatenate_read2s.concatenated_fastq] + else split_read2s } }