Skip to content

Commit 101325d

Browse files
authored
Merge pull request #124 from broadinstitute/dp-assembly
add run_discordance task
2 parents fd7bc67 + 68e8900 commit 101325d

6 files changed

Lines changed: 91 additions & 12 deletions

File tree

pipes/WDL/tasks/tasks_assembly.wdl

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,70 @@ task refine_2x_and_plot {
648648
dx_instance_type: "mem1_ssd1_v2_x8"
649649
}
650650
}
651+
652+
task run_discordance {
653+
meta {
654+
description: "This step evaluates discordance between sequencing runs of the same sample. The input is a merged, aligned BAM file for a single sample. If multiple runs (read groups) exist, we split the aligned reads by read group and separately evaluate consensus calls per read group using bcftools mpileup and call. A VCF is emitted that describes variation between runs."
655+
}
656+
657+
input {
658+
File reads_aligned_bam
659+
File reference_fasta
660+
String out_basename = "run"
661+
662+
String docker="quay.io/broadinstitute/viral-core"
663+
}
664+
665+
command {
666+
set -ex -o pipefail
667+
668+
read_utils.py --version | tee VERSION
669+
670+
# create 2-col table with read group ids in both cols
671+
python3 <<CODE
672+
import tools.samtools
673+
header = tools.samtools.SamtoolsTool().getHeader("${reads_aligned_bam}")
674+
rgids = [[x[3:] for x in h if x.startswith('ID:')][0] for h in header if h[0]=='@RG']
675+
with open('readgroups.txt', 'wt') as outf:
676+
for rg in rgids:
677+
outf.write(rg+'\t'+rg+'\n')
678+
CODE
679+
680+
# bcftools call snps while treating each RG as a separate sample
681+
bcftools mpileup \
682+
-G readgroups.txt -d 10000 -a "FORMAT/DP,FORMAT/AD" \
683+
-q 1 -m 2 -Ou \
684+
-f "${reference_fasta}" "${reads_aligned_bam}" \
685+
| bcftools call \
686+
-P 0 -m --ploidy 1 \
687+
--threads $(nproc) \
688+
-Ov -o everything.vcf
689+
690+
# mask all GT calls when less than 3 reads
691+
cat everything.vcf | bcftools filter -e 'FMT/DP<3' -S . > filtered.vcf
692+
cat filtered.vcf | bcftools filter -i 'MAC>0' > "${out_basename}.discordant.vcf"
693+
694+
# tally outputs
695+
set +o pipefail # to handle empty grep
696+
cat filtered.vcf | bcftools filter -i 'MAC=0' | grep -v '^#' | wc -l | tee num_concordant
697+
cat "${out_basename}.discordant.vcf" | bcftools filter -i 'TYPE="snp"' | grep -v '^#' | wc -l | tee num_discordant_snps
698+
cat "${out_basename}.discordant.vcf" | bcftools filter -i 'TYPE!="snp"' | grep -v '^#' | wc -l | tee num_discordant_indels
699+
}
700+
701+
output {
702+
File discordant_sites_vcf = "${out_basename}.discordant.vcf"
703+
Int concordant_sites = read_int("num_concordant")
704+
Int discordant_snps = read_int("num_discordant_snps")
705+
Int discordant_indels = read_int("num_discordant_indels")
706+
String viralngs_version = read_string("VERSION")
707+
}
708+
709+
runtime {
710+
docker: "${docker}"
711+
memory: "3 GB"
712+
cpu: 2
713+
disks: "local-disk 100 HDD"
714+
dx_instance_type: "mem1_ssd1_v2_x2"
715+
preemptible: 1
716+
}
717+
}

pipes/WDL/tasks/tasks_reports.wdl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ task align_and_count {
145145
input {
146146
File reads_bam
147147
File ref_db
148-
Int? minScoreToFilter
149148
Int? topNHits = 3
150149

151150
Int? machine_mem_gb
@@ -161,11 +160,10 @@ task align_and_count {
161160
read_utils.py --version | tee VERSION
162161
163162
ln -s ${reads_bam} ${reads_basename}.bam
164-
read_utils.py bwamem_idxstats \
163+
read_utils.py minimap2_idxstats \
165164
${reads_basename}.bam \
166165
${ref_db} \
167166
--outStats ${reads_basename}.count.${ref_basename}.txt.unsorted \
168-
${'--minScoreToFilter=' + minScoreToFilter} \
169167
--loglevel=DEBUG
170168
171169
sort -b -r -n -k3 ${reads_basename}.count.${ref_basename}.txt.unsorted > ${reads_basename}.count.${ref_basename}.txt
@@ -179,7 +177,7 @@ task align_and_count {
179177
}
180178

181179
runtime {
182-
memory: select_first([machine_mem_gb, 7]) + " GB"
180+
memory: select_first([machine_mem_gb, 3]) + " GB"
183181
cpu: 4
184182
docker: "${docker}"
185183
disks: "local-disk 375 LOCAL"
@@ -367,7 +365,7 @@ task tsv_join {
367365
String join_type="inner"
368366
String out_basename
369367

370-
String docker="stratdat/csvkit"
368+
String docker="quay.io/broadinstitute/viral-core"
371369
}
372370

373371
command {
@@ -408,7 +406,7 @@ task tsv_stack {
408406
input {
409407
Array[File]+ input_tsvs
410408
String out_basename
411-
String docker="stratdat/csvkit"
409+
String docker="quay.io/broadinstitute/viral-core"
412410
}
413411

414412
command {

pipes/WDL/workflows/assemble_refbased.wdl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ workflow assemble_refbased {
9494
out_basename = "${sample_name}.align_to_ref.trimmed"
9595
}
9696
97+
call assembly.run_discordance {
98+
input:
99+
reads_aligned_bam = merge_align_to_ref.out_bam,
100+
reference_fasta = reference_fasta,
101+
out_basename = sample_name
102+
}
103+
97104
call reports.plot_coverage as plot_ref_coverage {
98105
input:
99106
aligned_reads_bam = merge_align_to_ref.out_bam,
@@ -140,6 +147,11 @@ workflow assemble_refbased {
140147
Int reference_genome_length = plot_ref_coverage.assembly_length
141148
Float assembly_mean_coverage = plot_ref_coverage.mean_coverage
142149

150+
Int replicate_concordant_sites = run_discordance.concordant_sites
151+
Int replicate_discordant_snps = run_discordance.discordant_snps
152+
Int replicate_discordant_indels = run_discordance.discordant_indels
153+
File replicate_discordant_vcf = run_discordance.discordant_sites_vcf
154+
143155
Array[File] align_to_ref_per_input_aligned_flagstat = align_to_ref.aligned_bam_flagstat
144156
Array[Int] align_to_ref_per_input_reads_provided = align_to_ref.reads_provided
145157
Array[Int] align_to_ref_per_input_reads_aligned = align_to_ref.reads_aligned

pipes/WDL/workflows/diff_genome_sets.wdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ workflow diff_genome_sets {
2121
call reports.tsv_stack {
2222
input:
2323
input_tsvs = compare_two_genomes.comparison_table,
24-
out_basename = "diff_genome_sets.txt"
24+
out_basename = "diff_genome_sets"
2525
}
2626
2727
output {

requirements-modules.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
broadinstitute/viral-core=2.1.3
2-
broadinstitute/viral-assemble=2.1.3.1
3-
broadinstitute/viral-classify=2.1.3.1
4-
broadinstitute/viral-phylo=2.1.3.1
1+
broadinstitute/viral-core=2.1.4
2+
broadinstitute/viral-assemble=2.1.4.0
3+
broadinstitute/viral-classify=2.1.4.0
4+
broadinstitute/viral-phylo=2.1.4.0
55
broadinstitute/beast-beagle-cuda=1.10.5pre
66
broadinstitute/ncbi-tools=2.10.7.0
77
nextstrain/base=build-20200608T223413Z

test/input/WDL/test_outputs-assemble_refbased-local.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
"assemble_refbased.align_to_self_merged_reads_aligned": 18409,
88
"assemble_refbased.reference_genome_length": 18959,
99
"assemble_refbased.assembly_length_unambiguous": 18889,
10-
"assemble_refbased.assembly_length": 18889
10+
"assemble_refbased.assembly_length": 18889,
11+
"assemble_refbased.replicate_discordant_indels": 0,
12+
"assemble_refbased.replicate_discordant_snps": 0
1113
}

0 commit comments

Comments
 (0)