diff --git a/tasks/utilities/file_handling/task_cat_lanes.wdl b/tasks/utilities/file_handling/task_cat_lanes.wdl index 8636a951c..555a9c533 100644 --- a/tasks/utilities/file_handling/task_cat_lanes.wdl +++ b/tasks/utilities/file_handling/task_cat_lanes.wdl @@ -25,38 +25,23 @@ task cat_lanes { command <<< # exit task if anything throws an error (important for proper gzip format) set -euo pipefail + + exists() { [[ -f $1 ]]; } - # move reads into single directory - mkdir -v reads - mv -v ~{read1_lane1} \ - ~{read2_lane1} \ - ~{read1_lane2} \ - ~{read2_lane2} \ - ~{read1_lane3} \ - ~{read2_lane3} \ - ~{read1_lane4} \ - ~{read2_lane4} \ - reads/ + set -euo pipefail - # check for valid gzipped format (this task assumes FASTQ files are gzipped - they should be coming from ILMN instruments) - gzip -t reads/*.gz + cat ~{read1_lane1} ~{read1_lane2} ~{read1_lane3} ~{read1_lane4} > "~{samplename}_merged_R1.fastq.gz" - # run concatenate script and send STDOUT/ERR to STDOUT - # reminder: script will skip over samples that only have R1 file present - # reminder: script REQUIRES standard illumina file endings like: _L001_R1_001.fastq.gz and _L002_R2_001.fastq.gz - # see script here: https://github.com/theiagen/utilities/blob/main/scripts/concatenate-across-lanes.sh - concatenate-across-lanes.sh reads/ + if exists ~{read2_lane1} ; then + cat ~{read2_lane1} ~{read2_lane2} ~{read2_lane3} ~{read2_lane4} > "~{samplename}_merged_R2.fastq.gz" + fi # ensure newly merged FASTQs are valid gzipped format - gzip -t reads/*merged*.gz - - # determine output filenames for outputs - mv -v reads/*_merged_R1.fastq.gz reads/~{samplename}_merged_R1.fastq.gz - mv -v reads/*_merged_R2.fastq.gz reads/~{samplename}_merged_R2.fastq.gz + gzip -t *merged*.gz >>> output { - File read1_concatenated = "reads/~{samplename}_merged_R1.fastq.gz" - File? read2_concatenated = "reads/~{samplename}_merged_R2.fastq.gz" + File read1_concatenated = "~{samplename}_merged_R1.fastq.gz" + File? read2_concatenated = "~{samplename}_merged_R2.fastq.gz" } runtime { docker: "~{docker}"