Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion tools/test/util.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,12 @@ split_fastq:
- 100
- 1000
- 10000
- 100000
- 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
42 changes: 42 additions & 0 deletions tools/util.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
4 changes: 4 additions & 0 deletions workflows/general/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 33 additions & 6 deletions workflows/general/bam-to-fastqs.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@ version 1.3

import "../../tools/fq.wdl"
import "../../tools/samtools.wdl"
import "../../tools/util.wdl"

workflow bam_to_fastqs {
meta {
name: "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
}
Expand Down Expand Up @@ -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
}
}
Loading