-
Notifications
You must be signed in to change notification settings - Fork 1
/
Snakefile
157 lines (129 loc) · 4.78 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
"""
Snakefile for single-cell methylation analysis
Davis McCarthy
EMBL-EBI
April 2017
Run on a cluster with a command like:
snakemake --jobs 1000 --latency-wait 30 --cluster 'bsub -R "rusage[mem=32000]" -M 32000 -o ./snake_logs -e ./snake_logs'
"""
import glob
import os
#from subprocess import run
import pandas as pd
import re
TEST = True
if TEST:
SAMPLES_LONG = glob.glob('data/fastq/test/*.fastq.gz')
SAMPLES = [os.path.basename(w).replace('lane[123]+_', '') for w in SAMPLES_LONG]
SAMPLES = [w.replace('.fastq.gz', '') for w in SAMPLES]
SAMPLES_LONG = [os.path.basename(w).replace('.fastq.gz', '') for w in SAMPLES_LONG]
SAMPLES_MERGE = [w.replace('_R1', '').replace('_R2', '') for w in SAMPLES]
else:
SAMPLES_LONG = glob.glob('data/fastq/*.fastq.gz')
SAMPLES = [w.replace('lane[123]+_', '') for w in SAMPLES_LONG]
SAMPLES = [w.replace('_[ATCG]+_.*.fastq.gz', '') for w in SAMPLES]
SAMPLES_LONG = [os.path.basename(w).replace('.fastq.gz', '') for w in SAMPLES_LONG]
SAMPLES_MERGE = [w.replace('_R1', '').replace('_R2', '') for w in SAMPLES]
fastqc_html_reports = expand('reports/fastqc/{sample}_fastqc.html', sample = SAMPLES_LONG)
print(SAMPLES_MERGE)
rule all:
input:
'results/all.tsv.gz',
'reports/multiqc/multiqc_report.html',
#expand('data/bismark/methyl/{sample}_trimmed_bismark_bt2.deduplicated.bismark.cov.gz', sample = SAMPLES)
rule fastqc_reports:
input:
'data/fastq/test/{sample}.fastq.gz'
## if test = False, remove test/ from path above
output:
'reports/fastqc/{sample}_fastqc.html'
params:
output_dir="reports/fastqc/"
shell:
'/Users/davis/src/FastQC.app/Contents/MacOS/fastqc -o {params.output_dir} {input}'
rule trim_fastq:
input:
'data/fastq/test/{sample}.fastq.gz'
## if test = False, remove test/ from path above
output:
temp('{sample}_trimmed.fq.gz'),
temp('{sample}.fastq.gz_trimming_report.txt')
log:
"logs/trim_fastq/{sample}.log"
shell:
'trim_galore --gzip --non_directional --rrbs '
'{input} '
rule fastqc_reports_trimmed:
input:
'{sample}_trimmed.fq.gz'
output:
temp('reports/fastqc/{sample}_trimmed_fastqc.html')
params:
output_dir="reports/fastqc/"
shell:
'/Users/davis/src/FastQC.app/Contents/MacOS/fastqc -o {params.output_dir} {input}'
rule bismark_prepare_genome:
input:
'genome'
output:
'genome/Bisulfite_Genome'
shell:
'bismark_genome_preparation {input}'
rule bismark:
input:
'{sample}_trimmed.fq.gz',
'genome/Bisulfite_Genome'
output:
temp('data/bismark/raw/{sample}_trimmed_bismark_bt2.bam') ## CHECK BISMARK OUTPUT
shell:
'bismark --non_directional --genome genome -o data/bismark/raw '
'{input}'
rule bismark_dedup:
input:
'data/bismark/raw/{sample}_trimmed_bismark_bt2.bam'
output:
temp('data/bismark/raw/{sample}_trimmed_bismark_bt2.deduplicated.bam') ## CHECK BISMARK OUTPUT
shell:
'deduplicate_bismark --bam {input}'
rule bismark_methylation:
input:
'data/bismark/raw/{sample}_trimmed_bismark_bt2.deduplicated.bam'
output:
'data/bismark/methyl/{sample}_trimmed_bismark_bt2.deduplicated.bismark.cov.gz'
shell:
'bismark_methylation_extractor --gzip --bedGraph '
'-o data/bismark/methyl {input}'
rule multiqc:
input:
fastqc_html_reports,
expand('data/bismark/methyl/{sample}_trimmed_bismark_bt2.deduplicated.bismark.cov.gz', sample = SAMPLES),
expand('{sample}_trimmed.fq.gz', sample = SAMPLES),
expand('{sample}.fastq.gz_trimming_report.txt', sample = SAMPLES)
output:
'reports/multiqc/multiqc_report.html'
shell:
'multiqc --force --filename {output} '
'reports/fastqc ./ '
'data/bismark/methyl data/bismark/raw '
rule merge_methylation:
input:
expand('data/bismark/methyl/{sample}_R1_trimmed_bismark_bt2.deduplicated.bismark.cov.gz', sample = SAMPLES_MERGE),
expand('data/bismark/methyl/{sample}_R2_trimmed_bismark_bt2.deduplicated.bismark.cov.gz', sample = SAMPLES_MERGE)
output:
expand('data/bismark/merged/{sample}.tsv.gz', sample = SAMPLES_MERGE)
params:
indir = 'data/bismark/methyl',
outdir = 'data/bismark/merged'
shell:
'RScript scripts/merge.R -i {params.indir} -o {params.outdir}'
rule annotate_methylation:
input:
expand('data/bismark/merged/{sample}.tsv.gz', sample = SAMPLES_MERGE)
output:
'results/all.tsv.gz'
params:
indir = 'data/bismark/merged',
annodir = 'annotation',
outdir = 'results'
shell:
'RScript scripts/annotate.R -i {params.indir} -a {params.annodir} -o {params.outdir}'