-
Notifications
You must be signed in to change notification settings - Fork 0
/
TutMinicondaSnakemake.Rmd
316 lines (217 loc) · 6.6 KB
/
TutMinicondaSnakemake.Rmd
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
---
title: "Pipelines with Miniconda and Snakemake"
subtitle: "Tutorial"
author: "David Lähnemann"
date: "February 8, 2017"
output:
ioslides_presentation:
widescreen: true
fig_width: 10
fig_height: 4
fig_caption: false
transition: faster
---
<style>
#margin-15-percent > p {
margin-top: 15%;
}
#margin-10-percent > p {
margin-top: 10%;
}
#margin-5-percent > p {
margin-top: 5%
}
#margin-0-percent > p {
margin-top: 0%
}
#margin-minus5-percent > h3 {
margin-top: -5%;
}
</style>
## Get the slides
### Linux / OS X
```{bash, eval=FALSE}
cd YourFavoriteTutorialFolder
git clone https://github.com/dlaehnemann/TutMinicondaSnakemake.git
cd TutMinicondaSnakemake
firefox TutMinicondaSnakemake.html
```
### Windows
* git for windows: https://git-scm.com/download/win
* OR: "Clone or download" > "Download ZIP" at https://github.com/dlaehnemann/TutMinicondaSnakemake
# Part 1: Miniconda | easily managing software
## Minimal installation of package manager
```{r, echo=FALSE}
knitr::include_url("https://conda.io/docs/")
```
## Maintained by a company, but Open Source {.centered #margin-10-percent}
```{r, echo=FALSE, out.width="66%"}
knitr::include_graphics("figures/logo-continuum-black.svg")
```
https://github.com/conda/conda
## Cross-platform
```{r, echo=FALSE}
knitr::include_url("https://conda.io/miniconda.html")
```
## No admin rights needed {.centered}
```{r, echo=FALSE, out.height="120%"}
knitr::include_graphics("figures/sandwich.png")
```
https://xkcd.com/149/
## Easy installation and updates {#margin-10-percent}
```{bash, eval=FALSE}
conda install numpy
conda update numpy
```
## Software in any programming language | C/C++, Java, Javascript, Ruby, Lua, ... {.centered #margin-10-percent}
```{r, echo=FALSE, out.width="75%"}
knitr::include_graphics("figures/logos.svg")
```
## Bioconda channel: all the software you need
```{r, echo=FALSE}
knitr::include_url("https://bioconda.github.io/")
```
## Get started: (un)[Install Miniconda](https://conda.io/docs/install/quick.html)
```{r, echo=FALSE}
knitr::include_url("https://conda.io/docs/install/quick.html")
```
## Bioconda channel setup
```{r, echo=FALSE}
knitr::include_url("https://bioconda.github.io/#set-up-channels")
```
# Part 2: Snakemake | easy pipelining
## Input data 1: | raw, paired-end Illumina reads
```{bash}
head -n 12 examples/AF346983_1.1.fastq
```
## Input data 2: | reference sequence of German human mitochondrium (+ bwa index)
```{bash}
head -n 12 examples/AF346983_1_Mitochondrium_HomoSapiens_de.fa
```
## Install software
### bwa: mapping fastq files
http://bio-bwa.sourceforge.net/bwa.shtml
```{bash, eval=FALSE}
conda install bwa
```
### samtools: all kinds of alignment file magic
http://bio-bwa.sourceforge.net/bwa.shtml
```{bash, eval=FALSE}
conda install samtools
```
### Snakemake: pipelining
https://snakemake.readthedocs.io/en/latest/
```{bash, eval=FALSE}
conda install snakemake
```
## Snakemake for pipelining
```{r, echo=FALSE}
knitr::include_url("https://snakemake.readthedocs.io/en/latest/")
```
## Think back from the target {.build}
### Our target for today:
`samtools flagstat` output for our `AF346983_1` sequencing dataset (`AF346983_1.1.fastq` and `AF346983_1.2.fastq`).
### Create a `Snakefile`
Use an editor of your choice and create it in the folder `example`.
### Write your first rule
As the first rule in `Snakefile`, create a `rule target` with the target file as input, e.g. `AF346983_1.flagstat`.
```{python, eval=FALSE}
rule target:
input:
"AF346983_1.flagstat"
```
## 1st step back: 2nd rule samtools_flagstat {.build}
### Define input, output and shell command
Check `samtools flagstat` command.
### Abstract the sample/dataset name
Replace it with a wildcard, e.g. `{sample}`, in output and input definition.
```{python, eval=FALSE}
rule samtools_flagstat:
input:
"{sample}.sam"
output:
"{sample}.flagstat"
shell:
"samtools flagstat {input} > {output}"
```
## 2nd step back: 3rd rule bwa_mem {.build}
### Define output and shell command, then input.
Check `bwa mem` command.
### Abstract the sample/dataset name
Replace it with a wildcard, e.g. `{sample}`, in output and input definition.
```{python, eval=FALSE}
rule bwa_mem:
input:
"AF346983_1_Mitochondrium_HomoSapiens_de.fa",
"{sample}.1.fastq",
"{sample}.2.fastq"
output:
"{sample}.sam"
shell:
"bwa mem {input} > {output}"
```
## Run the pipeline in the example folder {.build}
### Save and close `Snakefile`
### Run the pipeline (requires `Snakefile` in working directory)
```{bash, eval=FALSE}
snakemake
```
### Check the output
```{bash, eval=FALSE}
cat examples/AF346983_1.flagstat
```
```{bash, echo=FALSE}
cat examples/results/AF346983_1.flagstat
```
## Visualise the workflow
### install Graphviz:
```{bash, eval=FALSE}
conda install graphviz
```
### create a DAG image: the directed acyclic graph of your pipeline
```{bash, eval=FALSE}
snakemake --dag | dot -Tsvg > dag.svg
```
```{r, echo=FALSE, out.height="50%"}
knitr::include_graphics("examples/results/dag.svg")
```
## Go crazy... {.build .centered}
```{r, echo=FALSE, out.width="40%"}
knitr::include_graphics("figures/rulegraph.svg")
```
## Leverage features such as: {.build}
### Direct server cluster support
```{bash, eval=FALSE}
snakemake --cluster "qsub -pe threaded {threads}" --jobs 100
```
### Automatic re-run of pipeline parts upon file update
### Automatic cleanup of incomplete output files when rule fails
### Statistics of time spent in rules: `--stats <filename>`
### HTML-based GUI: `--gui <port>`
### ...
## Well, actually...
### Just use it and check out the extensive docs:
https://snakemake.readthedocs.io/en/latest/index.html
### Extended Snakemake introduction (see all the most important features):
http://slides.com/johanneskoester/snakemake-tutorial-2016#/
### Extensive tutorials with best practices:
https://snakemake.readthedocs.io/en/latest/tutorial/welcome.html
# P.S.: Rmarkdown + ioslides
### Rmarkdown: http://rmarkdown.rstudio.com/
* https://www.rstudio.com/wp-content/uploads/2016/03/rmarkdown-cheatsheet-2.0.pdf
### Rmarkdown ioslides:
* http://rmarkdown.rstudio.com/ioslides_presentation_format.html
## HowTo produce these slides
```{r, eval = FALSE}
git clone https://github.com/dlaehnemann/TutMinicondaSnakemake
cd TutMinicondaSnakemake
# Edit TutMinicondaSnakemake.Rmd
R
> install.packages("rmarkdown")
> library("rmarkdown")
> install.packages("knitr")
> library("knitr")
> render("TutMinicondaSnakemake.Rmd")
q()
```
Open the provided or your produced `TutMinicondaSnakemake.html` with any current web browser.