-
Notifications
You must be signed in to change notification settings - Fork 5
/
Snakefile
231 lines (208 loc) · 5.55 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
ACCESSIONS = [
"ACBarrie",
# "Alsen",
# "Baxter",
# "Chara",
# "Drysdale",
# "Excalibur",
# "Gladius",
# "H45",
# "Kukri",
# "Pastor",
# "RAC875",
# "Volcanii",
# "Westonia",
# "Wyalkatchem",
# "Xiaoyan",
# "Yitpi",
]
MAX_THREADS = 32
ADAPTERS = "TruSeq3-PE.fa"
CHR = "chr4A"
CHR_START = "688000000"
CHR_END = "688100000"
REFERENCE = "references/" + CHR + ":" + CHR_START + "-" + CHR_END + ".fasta.gz"
N_BENCHMARKS = 1
from snakemake.remote.HTTP import RemoteProvider as HTTPRemoteProvider
HTTP = HTTPRemoteProvider()
singularity:
# "docker://continuumio/miniconda3:4.6.14"
"docker://rsuchecki/miniconda3:4.6.14_050661b0ef92865fde5aea442f3440d1a7532659"
############################
# Include other Snakefiles #
############################
include:
"rules/setup_data.smk"
#######################################
# Convienient rules to define targets #
#######################################
localrules:
all,
setup_data,
qc_reads
rule all:
input:
expand("reports/{chr}:{start}-{end}/raw_reads_multiqc.html", chr=CHR, start=CHR_START, end=CHR_END),
expand("qc_reads/{chr}:{start}-{end}/{accession}_R{read}.fastq.gz", chr=CHR, start=CHR_START, end=CHR_END, accession=ACCESSIONS, read=[1,2]),
expand("reports/{chr}:{start}-{end}/qc_reads_multiqc.html", chr=CHR, start=CHR_START, end=CHR_END),
expand("mapped/{chr}:{start}-{end}/{accession}.bam", chr=CHR, start=CHR_START, end=CHR_END, accession=ACCESSIONS),
rule setup_data:
input:
REFERENCE,
expand("raw_reads/{chr}:{start}-{end}/{accession}_R{read}.fastq.gz", chr=CHR, start=CHR_START, end=CHR_END, accession=ACCESSIONS, read=[1,2]),
rule qc_reads:
input:
expand("qc_reads/{chr}:{start}-{end}/{accession}_R{read}.fastq.gz", chr=CHR, start=CHR_START, end=CHR_END, accession=ACCESSIONS, read=[1,2]),
################
# Rules Proper #
################
rule fastqc_raw:
input:
"raw_reads/{prefix}.fastq.gz",
output:
zip = "reports/raw_reads/{prefix}_fastqc.zip",
html = "reports/raw_reads/{prefix}_fastqc.html",
conda:
"envs/tutorial.yml"
threads:
MAX_THREADS
benchmark:
repeat("benchmarks/fastqc_raw/{prefix}.txt", N_BENCHMARKS),
wrapper:
"0.31.1/bio/fastqc"
# shell:
# """
# fastqc --threads {threads} {input}
# """
rule multiqc_raw:
input:
expand("reports/raw_reads/{{chr}}:{{start}}-{{end}}/{accession}_R{read}_fastqc.zip", accession=ACCESSIONS, read=[1,2]),
output:
"reports/{chr}:{start}-{end}/raw_reads_multiqc.html",
conda:
"envs/tutorial.yml"
benchmark:
repeat("benchmarks/multiqc_raw/{chr}:{start}-{end}/benchmark.txt", N_BENCHMARKS),
wrapper:
"0.31.1/bio/multiqc"
# shell:
# """
# multiqc --filename {output} {input}
# """
rule download_trimmomatic_pe_adapters:
input:
lambda wildcards: HTTP.remote("raw.githubusercontent.com/timflutre/trimmomatic/master/adapters/" + wildcards.adapters, keep_local=True),
output:
"misc/trimmomatic_adapaters/{adapters}"
conda:
"envs/tutorial.yml"
shell:
"""
mv {input} {output}
"""
rule trimmomatic_pe:
input:
r1 = "raw_reads/{prefix}_R1.fastq.gz",
r2 = "raw_reads/{prefix}_R2.fastq.gz",
adapaters = lambda wildcards: "misc/trimmomatic_adapaters/" + ADAPTERS
output:
r1 = "qc_reads/{prefix}_R1.fastq.gz",
r2 = "qc_reads/{prefix}_R2.fastq.gz",
# reads where trimming entirely removed the mate
r1_unpaired = "qc_reads/{prefix}_R1.unpaired.fastq.gz",
r2_unpaired = "qc_reads/{prefix}_R2.unpaired.fastq.gz",
conda:
"envs/tutorial.yml"
params:
trimmer = [
"ILLUMINACLIP:misc/trimmomatic_adapaters/" + ADAPTERS + ":2:30:10:3:true",
"LEADING:2",
"TRAILING:2",
"SLIDINGWINDOW:4:15",
"MINLEN:36",
],
benchmark:
repeat("benchmarks/trimmomatic_pe/{prefix}.txt", N_BENCHMARKS),
wrapper:
"0.31.1/bio/trimmomatic/pe"
rule fastqc_trimmed:
input:
"qc_reads/{prefix}.fastq.gz",
output:
zip = "reports/qc_reads/{prefix}_fastqc.zip",
html = "reports/qc_reads/{prefix}_fastqc.html",
conda:
"envs/tutorial.yml"
benchmark:
repeat("benchmarks/fastqc_trimmed/{prefix}.txt", N_BENCHMARKS),
wrapper:
"0.31.1/bio/fastqc"
# shell:
# """
# fastqc {input}
# """
rule multiqc_trimmed:
input:
expand("reports/qc_reads/{{chr}}:{{start}}-{{end}}/{accession}_R{read}_fastqc.zip", accession=ACCESSIONS, read=[1,2]),
output:
"reports/{chr}:{start}-{end}/qc_reads_multiqc.html",
conda:
"envs/tutorial.yml"
benchmark:
repeat("benchmarks/multiqc_trimmed/{chr}:{start}-{end}/benchmark.txt", N_BENCHMARKS),
wrapper:
"0.31.1/bio/multiqc"
# shell:
# """
# multiqc --filename {output} {input}
# """
rule bwa_index:
input:
"{ref}"
output:
"{ref}.amb",
"{ref}.ann",
"{ref}.bwt",
"{ref}.pac",
"{ref}.sa"
conda:
"envs/tutorial.yml"
# log:
# "logs/bwa_index/{ref}.log"
params:
prefix = "{ref}",
algorithm = "bwtsw"
benchmark:
repeat("benchmarks/bwa_index/{ref}.txt", N_BENCHMARKS),
wrapper:
"0.31.1/bio/bwa/index"
# shell:
# """
# bwa index \
# -p {params.prefix} \
# -a {params.algorithm} \
# {input} \
# 2> {log}
# """
rule bwa_mem:
input:
reference = expand(REFERENCE + ".{ext}", ext=["amb","ann","bwt","pac","sa"]),
reads = [ "qc_reads/{sample}_R1.fastq.gz", "qc_reads/{sample}_R2.fastq.gz"],
# r1 = "qc_reads/{sample}_R1.fastq.gz",
# r2 = "qc_reads/{sample}_R2.fastq.gz",
output:
"mapped/{sample}.bam"
conda:
"envs/tutorial.yml"
params:
index = REFERENCE,
extra = r"-R '@RG\tID:{sample}\tSM:{sample}'",
sort = "none",
sort_order = "queryname",
sort_extra = ""
threads:
MAX_THREADS
benchmark:
repeat("benchmarks/bwa_mem/{sample}.txt", N_BENCHMARKS),
wrapper:
"0.31.1/bio/bwa/mem"