Skip to content

Commit f5341c0

Browse files
dpark01claude
andcommitted
Add read counting to demux_fastqs task and update workflows
- Add samtools view -c to count reads in demux_fastqs task - Add read_counts Array[Int] output to demux_fastqs task - Add read_counts_raw output to load_illumina_fastqs workflow - Update load_illumina_fastqs_deplete to use demux read counts instead of spikein counts (which default to 0 when no spikein_db) - Move test input/output JSONs to test/input/WDL/ with symlinks to miniwdl-local/ and cromwell-local/ - Add read_counts_raw validation to test output JSONs - Remove outdated comments about viral-core bug #127 (now fixed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0da20ce commit f5341c0

15 files changed

Lines changed: 196 additions & 188 deletions

pipes/WDL/tasks/tasks_demux.wdl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -893,9 +893,6 @@ task get_illumina_run_metadata {
893893
894894
illumina.py --version | tee VERSION
895895
896-
# NOTE: This command currently fails in viral-core:2.5.1 due to bug #127
897-
# See: https://github.com/broadinstitute/viral-core/issues/127
898-
# Will work once viral-core is updated
899896
illumina.py illumina_metadata \
900897
--samplesheet ~{samplesheet} \
901898
--runinfo ~{runinfo_xml} \
@@ -976,10 +973,6 @@ task demux_fastqs {
976973
977974
illumina.py --version | tee VERSION
978975
979-
# NOTE: This command currently fails in viral-core:2.5.1 due to bug #127
980-
# See: https://github.com/broadinstitute/viral-core/issues/127
981-
# Also note: run_date and flowcell_id are extracted from RunInfo.xml internally
982-
# and cannot be overridden (feature request in same issue)
983976
illumina.py splitcode_demux_fastqs \
984977
--fastq_r1 ~{fastq_r1} \
985978
~{'--fastq_r2 ' + fastq_r2} \
@@ -992,9 +985,16 @@ task demux_fastqs {
992985
# Count output BAMs
993986
ls -lh *.bam || echo "No BAM files found"
994987
995-
# Run FastQC on output BAMs (optional, if BAMs were created)
988+
# Initialize read counts file (empty in case no BAMs are created)
989+
touch read_counts.txt
990+
991+
# Run FastQC and count reads for output BAMs
996992
if ls *.bam 1> /dev/null 2>&1; then
997993
for bam in *.bam; do
994+
# Count reads in BAM and append to read counts file
995+
samtools view -c "$bam" >> read_counts.txt
996+
997+
# Run FastQC
998998
reports.py fastqc \
999999
"$bam" \
10001000
"${bam%.bam}_fastqc.html" \
@@ -1007,6 +1007,7 @@ task demux_fastqs {
10071007

10081008
output {
10091009
Array[File] output_bams = glob("*.bam")
1010+
Array[Int] read_counts = read_lines("read_counts.txt")
10101011
Array[File] fastqc_html = glob("*_fastqc.html")
10111012
Array[File] fastqc_zip = glob("*_fastqc.zip")
10121013
String viralngs_version = read_string("VERSION")

pipes/WDL/workflows/load_illumina_fastqs.wdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ workflow load_illumina_fastqs {
5555
output {
5656
# BAM outputs (flattened)
5757
Array[File] raw_reads_unaligned_bams = flatten(demux_fastqs.output_bams)
58+
Array[Int] read_counts_raw = flatten(demux_fastqs.read_counts)
5859

5960
# QC outputs (flattened)
6061
Array[File] fastqc_html = flatten(demux_fastqs.fastqc_html)

pipes/WDL/workflows/load_illumina_fastqs_deplete.wdl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ workflow load_illumina_fastqs_deplete {
8686
}
8787
8888
Array[File] raw_bams = flatten(demux_fastqs.output_bams)
89+
Array[Int] raw_read_counts = flatten(demux_fastqs.read_counts)
8990
9091
# Step 6: Spike-in counting and depletion for all BAMs
91-
scatter (raw_reads in raw_bams) {
92+
scatter (idx in range(length(raw_bams))) {
93+
File raw_reads = raw_bams[idx]
94+
Int raw_count = raw_read_counts[idx]
95+
9296
# Spike-in counting (if spikein_db provided)
9397
if (defined(spikein_db)) {
9498
call reports.align_and_count as spikein {
@@ -97,7 +101,6 @@ workflow load_illumina_fastqs_deplete {
97101
ref_db = select_first([spikein_db])
98102
}
99103
}
100-
Int reads_total_count = select_first([spikein.reads_total, 0])
101104
102105
# Depletion (if any depletion db provided)
103106
if (length(flatten(select_all([bmtaggerDbs, blastDbs, bwaDbs]))) > 0) {
@@ -110,7 +113,7 @@ workflow load_illumina_fastqs_deplete {
110113
}
111114
}
112115
113-
Int read_count_post_depletion = select_first([deplete.depletion_read_count_post, reads_total_count])
116+
Int read_count_post_depletion = select_first([deplete.depletion_read_count_post, raw_count])
114117
File cleaned_bam = select_first([deplete.cleaned_bam, raw_reads])
115118
116119
if (read_count_post_depletion >= min_reads_per_bam) {
@@ -120,7 +123,7 @@ workflow load_illumina_fastqs_deplete {
120123
File empty_bam = raw_reads
121124
}
122125

123-
Pair[String,Int] count_raw = (basename(raw_reads, '.bam'), reads_total_count)
126+
Pair[String,Int] count_raw = (basename(raw_reads, '.bam'), raw_count)
124127
Pair[String,Int] count_cleaned = (basename(raw_reads, '.bam'), read_count_post_depletion)
125128
}
126129

@@ -212,7 +215,7 @@ workflow load_illumina_fastqs_deplete {
212215
output {
213216
# Raw BAM outputs
214217
Array[File] raw_reads_unaligned_bams = raw_bams
215-
Array[Int] read_counts_raw = reads_total_count
218+
Array[Int] read_counts_raw = raw_read_counts
216219

217220
# Metadata outputs (with defaults applied)
218221
Map[String,Map[String,String]] meta_by_sample = read_json(meta_default_sample.out_json)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../test_inputs-load_illumina_fastqs-local.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../test_inputs-load_illumina_fastqs_deplete-local.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../test_outputs-load_illumina_fastqs-local.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../test_outputs-load_illumina_fastqs_deplete-local.json

test/input/WDL/miniwdl-local/test_inputs-load_illumina_fastqs-local.json

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../test_inputs-load_illumina_fastqs-local.json

test/input/WDL/miniwdl-local/test_inputs-load_illumina_fastqs_deplete-local.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)