Skip to content

Commit cca4d4b

Browse files
committed
Merge branch 'update-consensus'
2 parents 872734b + ea4db7b commit cca4d4b

3 files changed

Lines changed: 12 additions & 17 deletions

File tree

genome-consensus/environment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ dependencies:
66
- bcftools
77
- bedtools
88
- samtools
9+
- bedops
910

genome-consensus/test/Snakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
rule genome_consensus:
22
input:
3-
alignment="consensusmap.bam",
3+
alignment="refgenome.bam",
44
ref = "NC_045512.fa",
55
vcf = "filtered.vcf"
66
output:
7-
consensus="results/consensus.fa",
7+
"results/consensus.fa",
88
log:
99
"log/test.log"
1010
params:

genome-consensus/wrapper.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,20 @@
1616
log = snakemake.log_fmt_shell(stdout=False, stderr=True)
1717

1818
# Temp files
19-
temp_vcfgz = tempfile.TemporaryFile()
19+
temp_vcfgz = tempfile.NamedTemporaryFile()
2020
vcfgz_index = str(temp_vcfgz.name) + ".csi"
21-
temp_consensus = tempfile.TemporaryFile()
22-
temp_bed = tempfile.TemporaryFile()
21+
del_bed = tempfile.NamedTemporaryFile()
22+
cov_bed = tempfile.NamedTemporaryFile()
23+
mask_bed = tempfile.NamedTemporaryFile()
24+
mask_bed = str(mask_bed.name) + ".bed"
2325

2426
shell(
2527
"""
2628
(bgzip -c {snakemake.input.vcf} > {temp_vcfgz.name}
2729
bcftools index {temp_vcfgz.name}
28-
cat {snakemake.input.ref} | bcftools consensus {temp_vcfgz.name} > {temp_consensus.name}
29-
samtools view -h -b -q {mapping_quality} -f 0x3 {snakemake.input.alignment} | genomeCoverageBed -bga -ibam stdin | awk '$4 < {mask}' | bedtools merge > {temp_bed.name}
30-
bedtools maskfasta -fi {temp_consensus.name} -bed {temp_bed.name} -fo {snakemake.output.consensus}) {log}
31-
"""
32-
)
33-
34-
shell(
35-
"""
36-
rm -f {temp_vcfgz.name}
37-
rm -f {vcfgz_index}
38-
rm -f {temp_consensus.name}
39-
rm -f {temp_bed.name}
30+
samtools view -h -b -q {mapping_quality} {snakemake.input.alignment} | genomeCoverageBed -bga -ibam stdin | awk '$4 < {mask}' | bedtools merge > {cov_bed.name}
31+
vcf2bed --deletions < {snakemake.input.vcf} > {del_bed.name}
32+
bedtools subtract -a {cov_bed.name} -b {del_bed.name} > {mask_bed}
33+
bcftools consensus -f {snakemake.input.ref} -m {mask_bed} {temp_vcfgz.name} > {snakemake.output[0]}) {log}
4034
"""
4135
)

0 commit comments

Comments
 (0)