-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
175 lines (137 loc) · 4.29 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
__author__ = 'Marc Dabad'
__email__ = "marc.dabad@cnag.crg.cat"
import os
### Prepare pipeline and enviroment
shell.prefix("source ~/.bashrc")
path_snakemake = os.path.dirname(workflow.snakefile)
out = os.path.abspath(config.get('output', os.getcwd()))
workdir: out
mappings = out+"/mappings/"
calls = out+"/calls/"
results = out+"/results/"
os.makedirs(mappings, exist_ok=True)
os.makedirs(calls, exist_ok=True)
os.makedirs(results, exist_ok=True)
config['splitted'] = False
BASENAME = dict()
for i in config['fastq']:
BASENAME[os.path.basename(i).split(".fastq")[0]] = i
analysis_set = ['cpg', 'gpc', 'dam', 'dcm']
### Pipeline's rules
if config['splitted']:
rule all:
input:
expand(results+'whole.{analysis}', analysis=analysis_set)
else:
rule all:
input:
expand(results+'{sample}.{analysis}', sample=BASENAME.keys(), analysis=analysis_set)
### Mapping step
rule mappings:
input:
fastq = lambda wildcards: BASENAME[wildcards.sample]
params:
ref = config['reference'],
time= "2:00:00",
name= "mapping.{sample}"
threads: 16
output:
bam = mappings+'{sample}.bam',
bai = mappings+'{sample}.bam.bai'
shell:
'''
module purge
module load gcc/6.3.0 samtools/1.6 MINIMAP2 NANOPOLISH/0.11.0
minimap2 -t {threads} -L --MD -a -x map-ont {params.ref} {input.fastq} | \
samtools view -@ {threads} -q 10 -b - | \
samtools sort -@ {threads} -T $TMPDIR -o {output.bam}
samtools index {output.bam}
'''
### Index fastq
if config['summary']:
rule nanopolish_index_summary:
input:
fastq = lambda wildcards: BASENAME[wildcards.sample]
params:
fast5 = config['path_fast5'],
summary_seq= config['summary'],
time = "10:00:00",
name = "index_fastq.summary.{sample}"
threads: 8
output:
touch(out+'/{sample}.index.done')
shell:
'''
module purge
module load gcc/6.3.0 samtools/1.6 minimap2 nanopolish
nanopolish index -d {params.fast5} -s {params.summary_seq} {input.fastq}
'''
else:
rule nanopolish_index:
input:
fastq = lambda wildcards: BASENAME[wildcards.sample]
params:
fast5 = config['path_fast5'],
time = "3-00:00:00",
qos = "xlong",
name= "index_fastq.{sample}"
threads: 8
output:
touch(out+'/{sample}.index.done')
shell:
'''
module purge
module load gcc/6.3.0 samtools/1.6 minimap2 nanopolish
nanopolish index -d {params.fast5} {input.fastq}
#touch {output}
'''
#### CALL methyl
if config['splitted']:
rule join_methCalls:
input:
methCalls = expand(calls+"{sample}.{{analysis}}",
sample=BASENAME.keys())
threads: 8
params:
name= 'join_methCalls.{analysis}.whole'
output:
results+'whole.{analysis}'
shell:
'''
{path_snakemake}/bin/calc_methyl_freq -t {threads} {input.methCalls} > {output}
'''
else:
rule methCalls_step:
input:
methCalls = calls+"{sample}.{analysis}"
threads: 8
params:
name= 'methCalls.{sample}.{analysis}'
output:
results+'{sample}.{analysis}'
shell:
'''
{path_snakemake}/bin/calc_methyl_freq -t {threads} {input.methCalls} > {output}
'''
rule nanopolish_call:
input:
bam = mappings+'{sample}.bam',
fastq = lambda wildcards: BASENAME[wildcards.sample],
index = rules.nanopolish_index_summary.output if config['summary'] else rules.nanopolish_index.output
params:
ref = config['reference'],
analysis = '{analysis}',
time = "48:00:00",
name= "nanopolish_call.{sample}.{analysis}"
threads: 8
output:
calls+'{sample}.{analysis}'
shell:
'''
module purge
module load gcc/6.3.0 samtools/1.6 minimap2 nanopolish
nanopolish call-methylation -t {threads} \
-r {input.fastq} \
-b {input.bam} \
-g {params.ref} -q {params.analysis} > {output}
'''