Skip to content

Commit 1b086b7

Browse files
authored
Merge pull request #658 from broadinstitute/dp-quote-wdl-file-paths
Quote WDL File variable expansions to handle paths with spaces
2 parents 3378184 + d14a1d2 commit 1b086b7

6 files changed

Lines changed: 50 additions & 46 deletions

File tree

pipes/WDL/tasks/tasks_assembly.wdl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ task assemble {
7171
assembly --version | tee VERSION
7272
7373
assembly assemble_spades \
74-
~{reads_unmapped_bam} \
75-
~{trim_clip_db} \
76-
~{sample_name}.assembly1-spades.fasta \
74+
"~{reads_unmapped_bam}" \
75+
"~{trim_clip_db}" \
76+
"~{sample_name}.assembly1-spades.fasta" \
7777
~{'--nReads=' + spades_n_reads} \
7878
~{true="--alwaysSucceed" false="" always_succeed} \
7979
~{'--minContigLen=' + spades_min_contig_len} \
8080
~{'--spadesOpts="' + spades_options + '"'} \
8181
--memLimitGb $mem_in_gb \
82-
--outReads=~{sample_name}.subsamp.bam \
82+
--outReads="~{sample_name}.subsamp.bam" \
8383
--loglevel=DEBUG
8484
8585
samtools view -c ~{sample_name}.subsamp.bam | tee subsample_read_count >&2
@@ -595,13 +595,13 @@ task ivar_trim {
595595
ivar version | head -1 | tee VERSION
596596
if [ -f "~{trim_coords_bed}" ]; then
597597
ivar trim -e \
598-
~{'-b ' + trim_coords_bed} \
598+
~{'-b "' + trim_coords_bed + '"'} \
599599
~{'-m ' + min_keep_length} \
600600
~{'-s ' + sliding_window} \
601601
~{'-q ' + min_quality} \
602602
~{'-x ' + primer_offset} \
603-
-i ~{aligned_bam} -p trim | tee IVAR_OUT
604-
samtools sort -@ $(nproc) -m 1000M -o ~{bam_basename}.trimmed.bam trim.bam
603+
-i "~{aligned_bam}" -p trim | tee IVAR_OUT
604+
samtools sort -@ $(nproc) -m 1000M -o "~{bam_basename}.trimmed.bam" trim.bam
605605
else
606606
echo "skipping ivar trim"
607607
cp "~{aligned_bam}" "~{bam_basename}.trimmed.bam"
@@ -922,16 +922,16 @@ task refine_assembly_with_aligned_reads {
922922
923923
if [ ~{true='true' false='false' mark_duplicates} == "true" ]; then
924924
read_utils mkdup_picard \
925-
~{reads_aligned_bam} \
925+
"~{reads_aligned_bam}" \
926926
temp_markdup.bam \
927927
--JVMmemory "$mem_in_mb"m \
928928
--loglevel=DEBUG
929929
else
930-
ln -s ~{reads_aligned_bam} temp_markdup.bam
930+
ln -s "~{reads_aligned_bam}" temp_markdup.bam
931931
fi
932932
samtools index -@ $(nproc) temp_markdup.bam temp_markdup.bai
933933
934-
ln -s ~{reference_fasta} assembly.fasta
934+
ln -s "~{reference_fasta}" assembly.fasta
935935
assembly refine_assembly \
936936
assembly.fasta \
937937
temp_markdup.bam \

pipes/WDL/tasks/tasks_demux.wdl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,22 @@ task illumina_demux {
239239
fi
240240
241241
# Parse the lane count & run ID from RunInfo.xml file
242-
lane_count=$(xmllint --xpath "string(//Run/FlowcellLayout/@LaneCount)" $RUNINFO_FILE)
242+
lane_count=$(xmllint --xpath "string(//Run/FlowcellLayout/@LaneCount)" "$RUNINFO_FILE")
243243
if [ -z "$lane_count" ]; then
244244
echo "Could not parse LaneCount from RunInfo.xml. Please check RunInfo.xml is properly formatted"
245245
fi
246246
247-
surface_count=$(xmllint --xpath "string(//Run/FlowcellLayout/@SurfaceCount)" $RUNINFO_FILE)
247+
surface_count=$(xmllint --xpath "string(//Run/FlowcellLayout/@SurfaceCount)" "$RUNINFO_FILE")
248248
if [ -z "$surface_count" ]; then
249249
echo "Could not parse SurfaceCount from RunInfo.xml. Please check RunInfo.xml is properly formatted"
250250
fi
251251
252-
swath_count=$(xmllint --xpath "string(//Run/FlowcellLayout/@SwathCount)" $RUNINFO_FILE)
252+
swath_count=$(xmllint --xpath "string(//Run/FlowcellLayout/@SwathCount)" "$RUNINFO_FILE")
253253
if [ -z "$swath_count" ]; then
254254
echo "Could not parse SwathCount from RunInfo.xml. Please check RunInfo.xml is properly formatted"
255255
fi
256256
257-
tile_count=$(xmllint --xpath "string(//Run/FlowcellLayout/@TileCount)" $RUNINFO_FILE)
257+
tile_count=$(xmllint --xpath "string(//Run/FlowcellLayout/@TileCount)" "$RUNINFO_FILE")
258258
if [ -z "$tile_count" ]; then
259259
echo "Could not parse TileCount from RunInfo.xml. Please check RunInfo.xml is properly formatted"
260260
fi
@@ -366,9 +366,9 @@ task illumina_demux {
366366
$FLOWCELL_DIR \
367367
~{lane} \
368368
. \
369-
~{'--sampleSheet=' + samplesheet} \
370-
~{'--runInfo=' + runinfo} \
371-
~{'--sequencing_center=' + sequencingCenter} \
369+
~{'--sampleSheet="' + samplesheet + '"'} \
370+
~{'--runInfo="' + runinfo + '"'} \
371+
~{'--sequencing_center="' + sequencingCenter + '"'} \
372372
--outMetrics=metrics.txt \
373373
--commonBarcodes=barcodes.txt \
374374
~{'--flowcell=' + flowcell} \
@@ -436,7 +436,7 @@ task illumina_demux {
436436
~{'--predemux_trim_r1_3prime ' + inner_barcode_predemux_trim_r1_3prime} \
437437
~{'--predemux_trim_r2_5prime ' + inner_barcode_predemux_trim_r2_5prime} \
438438
~{'--predemux_trim_r2_3prime ' + inner_barcode_predemux_trim_r2_3prime} \
439-
~{'--sampleSheet=' + samplesheet} \
439+
~{'--sampleSheet="' + samplesheet + '"'} \
440440
"--runInfo=${RUNINFO_FILE}" \
441441
--illuminaRunDirectory=$FLOWCELL_DIR \
442442
$demux_threads \
@@ -843,7 +843,7 @@ task get_illumina_run_metadata {
843843
illumina --version | tee VERSION
844844
845845
illumina illumina_metadata \
846-
--runinfo ~{runinfo_xml} \
846+
--runinfo "~{runinfo_xml}" \
847847
~{'--sequencing_center ' + sequencing_center} \
848848
--out_runinfo runinfo.json \
849849
--loglevel=DEBUG
@@ -969,15 +969,15 @@ task demux_fastqs {
969969
illumina --version | tee VERSION
970970
971971
illumina splitcode_demux_fastqs \
972-
--fastq_r1 ~{fastq_r1} \
973-
~{'--fastq_r2 ' + fastq_r2} \
974-
--samplesheet ~{samplesheet} \
975-
--runinfo ~{runinfo_xml} \
976-
~{'--sequencing_center ' + sequencingCenter} \
972+
--fastq_r1 "~{fastq_r1}" \
973+
~{'--fastq_r2 "' + fastq_r2 + '"'} \
974+
--samplesheet "~{samplesheet}" \
975+
--runinfo "~{runinfo_xml}" \
976+
~{'--sequencing_center "' + sequencingCenter + '"'} \
977977
--outdir . \
978978
--append_run_id \
979-
--out_meta_by_sample ~{fastq_basename}-meta_by_sample.json \
980-
--out_meta_by_filename ~{fastq_basename}-meta_by_filename.json \
979+
--out_meta_by_sample "~{fastq_basename}-meta_by_sample.json" \
980+
--out_meta_by_filename "~{fastq_basename}-meta_by_filename.json" \
981981
--loglevel=DEBUG
982982
983983
# Workaround: create empty JSON files if Python code didn't produce them (zero-read FASTQs)

pipes/WDL/tasks/tasks_interhost.wdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ task beast {
311311
~{true="-beagle_double" false="-beagle_single" beagle_double_precision} \
312312
-beagle_scaling always \
313313
~{'-beagle_order ' + beagle_order} \
314-
~{beauti_xml}
314+
"~{beauti_xml}"
315315
>>>
316316

317317
output {

pipes/WDL/tasks/tasks_intrahost.wdl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ task polyphonia_detect_cross_contamination {
8282
fi
8383
8484
polyphonia cross_contamination \
85-
--ref ~{reference_fasta} \
85+
--ref "~{reference_fasta}" \
8686
--vcf ~{sep=' ' lofreq_vcfs} \
8787
--consensus ~{sep=' ' genome_fastas} \
8888
--read-depths ~{sep=' ' select_first([read_depths, []])} \
@@ -94,7 +94,7 @@ task polyphonia_detect_cross_contamination {
9494
~{'--min-matches-proportion ' + min_matches_proportion} \
9595
~{'--min-maf ' + min_maf} \
9696
~{'--masked-positions ' + masked_positions} \
97-
~{'--masked-positions-file ' + masked_positions_file} \
97+
~{'--masked-positions-file "' + masked_positions_file + '"'} \
9898
$PLATE_MAPS_INPUT \
9999
~{'--plate-size ' + plate_size} \
100100
~{'--plate-columns ' + plate_columns} \
@@ -224,8 +224,8 @@ task isnvs_per_sample {
224224
command <<<
225225
intrahost --version | tee VERSION
226226
intrahost vphaser_one_sample \
227-
~{mapped_bam} \
228-
~{assembly_fasta} \
227+
"~{mapped_bam}" \
228+
"~{assembly_fasta}" \
229229
vphaser2.~{sample_name}.txt.gz \
230230
~{'--vphaserNumThreads=' + threads} \
231231
~{true="--removeDoublyMappedReads" false="" removeDoublyMappedReads} \
@@ -286,7 +286,7 @@ task isnvs_vcf {
286286
echo "snpRefAccessions: $snpRefAccessions"
287287
288288
intrahost merge_to_vcf \
289-
~{reference_fasta} \
289+
"~{reference_fasta}" \
290290
isnvs.vcf.gz \
291291
$SAMPLES \
292292
--isnvs ~{sep=' ' vphaser2Calls} \

pipes/WDL/tasks/tasks_megablast.wdl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ task lca_megablast {
9898
command <<<
9999
#Extract BLAST DB tarball
100100
read_utils extract_tarball \
101-
~{blast_db_tgz} . \
101+
"~{blast_db_tgz}" . \
102102
--loglevel=DEBUG
103-
104-
# Extract taxonomy DB tarball
103+
104+
# Extract taxonomy DB tarball
105105
read_utils extract_tarball \
106-
~{taxonomy_db_tgz} . \
106+
"~{taxonomy_db_tgz}" . \
107107
--loglevel=DEBUG
108108
109109
'''
@@ -189,9 +189,9 @@ task ChunkBlastHits {
189189
command <<<
190190
#Extract tarball contents
191191
read_utils extract_tarball \
192-
~{blast_db_tgz} . \
192+
"~{blast_db_tgz}" . \
193193
--loglevel=DEBUG
194-
export LOG_DIR=~{log_dir_final}
194+
export LOG_DIR="~{log_dir_final}"
195195
echo "Using $(nproc) CPU cores."
196196
echo "Asked for ~{machine_mem_gb} memory GB"
197197
#Adding taxidlist input as optional
@@ -274,12 +274,12 @@ task blastoff {
274274
command <<<
275275
#Extract BLAST DB tarball
276276
read_utils extract_tarball \
277-
~{blast_db_tgz} . \
277+
"~{blast_db_tgz}" . \
278278
--loglevel=DEBUG
279279
280280
# Extract taxonomy DB tarball (includes nodes.dmp)
281281
read_utils extract_tarball \
282-
~{taxonomy_db_tgz} . \
282+
"~{taxonomy_db_tgz}" . \
283283
--loglevel=DEBUG
284284
285285
export LOG_DIR=~{log_dir_final}

pipes/WDL/tasks/tasks_utils.wdl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ task md5sum {
599599
}
600600
Int disk_size = 100
601601
command <<<
602-
md5sum ~{in_file} | cut -f 1 -d ' ' | tee MD5
602+
md5sum "~{in_file}" | cut -f 1 -d ' ' | tee MD5
603603
>>>
604604
output {
605605
String md5 = read_string("MD5")
@@ -1138,12 +1138,16 @@ task s3_copy {
11381138
set -e
11391139
S3_PREFIX=$(echo "~{s3_uri_prefix}" | sed 's|/*$||')
11401140
mkdir -p ~/.aws
1141-
cp ~{aws_credentials} ~/.aws/credentials
1141+
cp "~{aws_credentials}" ~/.aws/credentials
11421142
touch OUT_URIS
1143-
for f in ~{sep=' ' infiles}; do
1144-
aws s3 cp $f $S3_PREFIX/
1145-
echo "$S3_PREFIX/$(basename $f)" >> OUT_URIS
1146-
done
1143+
INFILES=~{write_lines(infiles)}
1144+
while IFS= read -r f || [ -n "$f" ]; do
1145+
# Skip empty or whitespace-only lines
1146+
if [ -n "$f" ] && [ -n "$(echo "$f" | tr -d '[:space:]')" ]; then
1147+
aws s3 cp "$f" "$S3_PREFIX/"
1148+
echo "$S3_PREFIX/$(basename "$f")" >> OUT_URIS
1149+
fi
1150+
done < "$INFILES"
11471151
>>>
11481152
output {
11491153
Array[String] out_uris = read_lines("OUT_URIS")

0 commit comments

Comments
 (0)