forked from fbartusch/snakemake_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Snakefile
85 lines (68 loc) · 2.07 KB
/
Snakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
configfile: "config.yaml"
workdir: "/scif/data"
rule bwa_index:
input:
"{ref}.fa"
output:
"{ref}.fa.bwt"
shell:
"scif run bwa index {input}"
rule bwa_map:
input:
index="genome.fa.bwt",
ref="genome.fa",
reads="samples/{sample}.fastq"
output:
"mapped_reads/{sample}.sam"
shell:
"scif run bwa mem -o {output} {input.ref} {input.reads}"
rule samtools_sam_to_bam:
input:
"mapped_reads/{sample}.sam"
output:
"mapped_reads/{sample}.bam"
shell:
"scif --quiet run samtools 'view -bS $SCIF_DATA/{input} > $SCIF_DATA/{output}'"
rule samtools_sort:
input:
"mapped_reads/{sample}.bam"
output:
"sorted_reads/{sample}.bam"
shell:
"scif --quiet run samtools 'sort -T $SCIF_DATA/sorted_reads/{wildcards.sample} -O bam $SCIF_DATA/{input} > $SCIF_DATA/{output}'"
rule samtools_index:
input:
"sorted_reads/{sample}.bam"
output:
"sorted_reads/{sample}.bam.bai"
shell:
"scif run samtools 'index $SCIF_DATA/{input}'"
rule bcftools_call:
input:
fa="genome.fa",
bam=expand("sorted_reads/{sample}.bam", sample=config["samples"]),
bai=expand("sorted_reads/{sample}.bam.bai", sample=config["samples"])
output:
"calls/all.vcf"
shell:
"scif --quiet run samtools 'mpileup -g -f $SCIF_DATA/{input.fa} $SCIF_DATA/{input.bam} | bcftools call -mv - > $SCIF_DATA/{output}'"
rule report:
input:
"calls/all.vcf"
output:
"report.html"
run:
from snakemake.utils import report
with open(input[0]) as vcf:
n_calls = sum(1 for l in vcf if not l.startswith("#"))
report("""
An example variant calling workflow
===================================
Reads were mapped to the Yeast
reference genome and variants were called jointly with
SAMtools/BCFtools.
This resulted in {n_calls} variants (see Table T1_).
""", output[0], T1=input[0])
rule all:
input:
"report.html"