Skip to content

Commit 9e59e59

Browse files
committed
chore: add calculation of DP and AD for all sites with coverage
1 parent 759ab18 commit 9e59e59

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

workflow/envs/var_calling.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ channels:
44
dependencies:
55
- ivar==1.4.2
66
- samtools==1.17
7+
- bcftools==1.17

workflow/rules/vaf.smk

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ rule snps_to_ancestor:
1414
bam = get_input_bam,
1515
gff = OUTDIR/"reference.gff3"
1616
output:
17-
tsv = temp(OUTDIR/"vaf"/"{sample}.tsv")
17+
tsv = temp(OUTDIR/"vaf"/"{sample}.tsv"),
18+
reference_fasta_renamed = temp(OUTDIR/"vaf"/"{sample}.reference.fasta"),
1819
log:
1920
LOGDIR / "snps_to_ancestor" / "{sample}.log.txt"
2021
shell:
@@ -27,9 +28,9 @@ rule snps_to_ancestor:
2728
echo Reference: $ref
2829
echo FASTA before:
2930
grep ">" {input.reference_fasta}
30-
sed 's/>.*/>'$ref'/g' {input.reference_fasta} > renamed_reference.fasta
31+
sed 's/>.*/>'$ref'/g' {input.reference_fasta} >{output.reference_fasta_renamed:q}
3132
echo FASTA after:
32-
grep ">" renamed_reference.fasta
33+
grep ">" {output.reference_fasta_renamed:q}
3334
3435
echo Starting VC
3536
samtools mpileup \
@@ -39,15 +40,15 @@ rule snps_to_ancestor:
3940
--count-orphans \
4041
--no-BAQ \
4142
-Q {params.mpileup_quality} \
42-
-f renamed_reference.fasta \
43+
-f {output.reference_fasta_renamed:q} \
4344
{input.bam} \
4445
| ivar variants \
4546
-p variants \
4647
-q {params.ivar_quality} \
4748
-t {params.ivar_freq} \
4849
-m {params.ivar_depth} \
4950
-g {input.gff} \
50-
-r renamed_reference.fasta
51+
-r {output.reference_fasta_renamed:q}
5152
mv variants.tsv {output.tsv:q}
5253
"""
5354

@@ -205,6 +206,43 @@ use rule concat_vcf_fields as concat_variants with:
205206
OUTDIR/f"{OUTPUT_NAME}.variants.tsv",
206207

207208

209+
rule samtools_depth_all_sites:
210+
threads: 1
211+
conda: "../envs/var_calling.yaml"
212+
params:
213+
min_mq = 0,
214+
min_bq = config["VC"]["MIN_QUALITY"],
215+
input:
216+
bam = get_input_bam,
217+
output:
218+
OUTDIR / "samtools_depth_all_sites" / "{sample}.depth.tsv"
219+
log:
220+
LOGDIR / "samtools_depth_all_sites" / "{sample}.txt",
221+
shell:
222+
"samtools depth --threads {threads} -a -H -J -Q {params.min_mq} -q {params.min_bq} -o {output:q} {input:q} >{log:q} 2>&1"
223+
224+
225+
rule bcftools_mpileup_all_sites:
226+
threads: 1
227+
conda: "../envs/var_calling.yaml"
228+
params:
229+
min_mq = 0,
230+
min_bq = config["VC"]["MIN_QUALITY"],
231+
input:
232+
bam = get_input_bam,
233+
reference = OUTDIR/"vaf"/"{sample}.reference.fasta",
234+
output:
235+
mpileup = OUTDIR / "bcftools_mpileup_all_sites" / "{sample}.mpileup.vcf",
236+
query = OUTDIR / "bcftools_mpileup_all_sites" / "{sample}.query.tsv",
237+
log:
238+
mpileup = LOGDIR / "bcftools_mpileup_all_sites" / "{sample}.mpileup.txt",
239+
query = LOGDIR / "bcftools_mpileup_all_sites" / "{sample}.query.txt",
240+
shell:
241+
"bcftools mpileup --ignore-RG -a AD,ADF,ADR --fasta-ref {input.reference:q} --threads {threads} -Q {params.min_mq} -q {params.min_bq} -Ov -o {output.mpileup:q} {input.bam:q} >{log.mpileup:q} 2>&1 && "
242+
"echo 'CHROM\tPOS\tREF\tALT\tDP\tAD\tADF\tADR' >{output.query:q} && "
243+
"bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%DP\t[ %AD]\t[ %ADF]\t[ %ADR]\n' {output.mpileup:q} >>{output.query:q} 2>{log.query:q}"
244+
245+
208246
rule pairwise_trajectory_correlation:
209247
conda: "../envs/renv.yaml"
210248
input:

0 commit comments

Comments
 (0)