-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathsnakemake-example-pipeline
98 lines (77 loc) · 2.72 KB
/
snakemake-example-pipeline
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
---
title: Example of snakemake pipeline
description: An example of snakemake file to run a pipeline applied to a bunch of files
category: research
subcategory: general_ngs
tags: [snakemake]
---
This file shows how to run a pipeline with snakemake for a bunch of files defined in `SAMPLES` variables.
It shows how to put together different steps and how they are related to each other.
The tricky part is to have always `rule all` step and get all the output filenames you want to generate. If you miss
some files that you want to generate and they are not the input in any other step then that step is not happening.
```
from os.path import join
# Globals ---------------------------------------------------------------------
# Full path to a FASTA file.
GENOME_DIR = '../reference'
# Full path to a folder that holds all of your FASTQ files.
FASTQ_DIR = '../rawdata'
# A Snakemake regular expression matching the forward mate FASTQ files.
SAMPLES, = glob_wildcards(join(FASTQ_DIR, '{sample,[^/]+}_R1_001.fastq.gz'))
# Patterns for the 1st mate and the 2nd mate using the 'sample' wildcard.
PATTERN_R1 = '{sample}_R1_001.fastq.gz'
PATTERN_R2 = '{sample}_R2_001.fastq.gz'
PATTERN_GENOME = '{sample}.fa'
rule all:
input:
index = expand(join(GENOME_DIR, '{sample}.fa.bwt'), sample = SAMPLES),
vcf = expand(join('vcf', '{sample}.vcf'), sample = SAMPLES),
vcfpileup = expand(join('pileup', '{sample}.vcf'), sample = SAMPLES),
sam = expand(join('stats', '{sample}.txt'), sample = SAMPLES)
rule index:
input:
join(GENOME_DIR, '{sample}.fa')
output:
join(GENOME_DIR, '{sample}.fa.bwt')
shell:
'bwa index {input}'
rule map:
input:
genome = join(GENOME_DIR, PATTERN_GENOME),
index = join(GENOME_DIR, '{sample}.fa.bwt'),
r1 = join(FASTQ_DIR, PATTERN_R1),
r2 = join(FASTQ_DIR, PATTERN_R2)
output:
'bam/{sample}.bam'
shell:
'bwa mem -c 250 -M -t 6 -v 1 {input.genome} {input.r1} {input.r2} | samtools sort - > {output}'
rule stats:
input:
bam = 'bam/{sample}.bam'
output:
'stats/{sample}.txt'
shell:
'samtools stats {input} > {output}'
rule pileup:
input:
bam = 'bam/{sample}.bam',
genome = join(GENOME_DIR, PATTERN_GENOME)
output:
'pileup/{sample}.mp'
shell:
'samtools mpileup -f {input.genome} -t DP -t AD -d 10000 -u -g {input.bam} > {output}'
rule mpconvert:
input:
'pileup/{sample}.mp',
output:
'pileup/{sample}.vcf'
shell:
'bcftools convert -O v {input} > {output}'
rule bcf:
input:
'pileup/{sample}.mp',
output:
'vcf/{sample}.vcf'
shell:
'bcftools call -v -m {input} > {output}'
```