-
Notifications
You must be signed in to change notification settings - Fork 0
/
snakefile
106 lines (74 loc) · 2.19 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from snakemake.utils import min_version, validate
from pathlib import Path
from os import path
min_version("7.18")
configfile:"config.yml"
validate(config, schema="config_schema.yml")
WORKDIR = config["workdir"]
SNAKEDIR = path.dirname(workflow.snakefile)
sample = config["sample_name"]
target_list = [
"mapping/" + sample + ".bam",
"sniffles/" + sample + ".vcf"
]
rule all:
input:
target_list
# --------------
in_fastq = config["fastq"]
if not path.isabs(in_fastq):
in_fastq = path.join(SNAKEDIR, in_fastq)
assert os.path.exists(in_fastq)
rule concatenate_reads:
input:
fq = in_fastq
output:
fq_concat = path.join("processed_reads", f"{sample}_reads.fq")
threads: config["threads"]
shell:"""
find {input.fq} -regextype posix-extended -regex '.*\.(fastq.gz|fq.gz)$' -exec zcat {{}} \\; > {output.fq_concat}
"""
# ------------------------
rule nanostat:
input:
rules.concatenate_reads.output.fq_concat
output:
ns = path.join("Nanostat", f"{sample}_stat_out.txt")
threads: config["threads"]
shell: """
NanoStat -n {output.ns} -t {threads} --tsv --fastq {input.fq}
"""
# ------------------------
rule mapping:
input:
fq = rules.concatenate_reads.output.fq_concat,
ref = config["genome"]
output:
sam = path.join("mapping", f"{sample}.sam")
threads: config["threads"]
params:
opts = config["minimap2_opts"]
shell:"""
minimap2 {params.opts} -y -x map-ont -t {threads} -a --eqx -k 17 -K 5g {input.ref} {input.fq} -o {output.sam}
"""
rule sam_to_bam:
input:
sam = rules.mapping.output.sam
output:
bam = path.join("mapping", f"{sample}.bam")
threads: config["threads"]
shell:"""
samtools sort -@ {threads} -O BAM -o {output.bam} {input.sam};
samtools index {output.bam}
"""
rule sniffles:
input:
bam = rules.sam_to_bam.output.bam
output:
vcf = path.join("sniffles", f"{sample}.vcf")
params:
sn_opts = config["sniffles_opts"]
threads: config["threads"]
shell:"""
sniffles -i {input.bam} -v {output.vcf} {params.sn_opts} --threads {threads}
"""