-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.nf
283 lines (204 loc) · 7.95 KB
/
main.nf
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
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
process get_images {
stageInMode 'symlink'
stageOutMode 'move'
script:
"""
if [[ "${params.containers}" == "singularity" ]] ;
then
cd ${params.image_folder}
if [[ ! -f star-2.7.11b.sif ]] ;
then
singularity pull star-2.7.11b.sif docker://index.docker.io/mpgagebioinformatics/star:2.7.11b
fi
if [[ ! -f samtools-1.16.1.sif ]] ;
then
singularity pull samtools-1.16.1.sif docker://index.docker.io/mpgagebioinformatics/samtools:1.16.1
fi
if [[ ! -f rnaseq.python-3.8-1.sif ]] ;
then
singularity pull rnaseq.python-3.8-1.sif docker://index.docker.io/mpgagebioinformatics/rnaseq.python:3.8-1
fi
if [[ ! -f irfinder-1.3.1.sif ]] ;
then
singularity pull irfinder-1.3.1.sif docker://index.docker.io/mpgagebioinformatics/irfinder:1.3.1
fi
fi
if [[ "${params.containers}" == "docker" ]] ;
then
docker pull mpgagebioinformatics/star:2.7.11b
docker pull mpgagebioinformatics/samtools:1.16.1
docker pull mpgagebioinformatics/rnaseq.python:3.8-1
docker pull mpgagebioinformatics/irfinder:1.3.1.sif
fi
"""
}
process rename_sample {
stageInMode 'symlink'
stageOutMode 'move'
script:
"""
#!/usr/local/bin/python3
import os
import pandas as pd
import openpyxl
samplesheet = pd.read_excel("${params.sample_sheet_xlsx}",engine="openpyxl")
samplesheet['sample_name'] = ''
samplesheet
groups = dict()
sample_name_colum = samplesheet.columns.get_loc("sample_name")
for index, row in samplesheet.iterrows():
if not row[1] in groups:
groups[row[1]] = 1
else:
groups[row[1]] += 1
print('ln -s %s%s %s%s_%s${params.read1_sufix}' %('${params.fastqc_raw_data}', row[0], '${params.raw_renamed}', row[1], groups[row[1]]))
os.system('ln -s %s%s %s%s_%s${params.read1_sufix}' %('${params.fastqc_raw_data}', row[0], '${params.raw_renamed}', row[1], groups[row[1]]))
row[sample_name_colum] = '%s_%s' %(row[1], groups[row[1]])
if "${params.read2_sufix}" in row[0]:
print('ln -s ${params.fastqc_raw_data}%s ${params.raw_renamed}%s_%s${params.read2_sufix}' % (row[0].replace('${params.read1_sufix}', '${params.read2_sufix}'), row[1], groups[row[1]]))
os.system('ln -s ${params.fastqc_raw_data}%s ${params.raw_renamed}%s_%s${params.read2_sufix}' % (row[0].replace('${params.read1_sufix}', '${params.read2_sufix}'), row[1], groups[row[1]]))
"""
}
process star_indexer {
stageInMode 'symlink'
stageOutMode 'move'
when:
( ! file("${params.star_index}index.fa").exists() )
script:
"""
cd ${params.star_index}
STAR --runMode genomeGenerate \
--genomeDir ${params.star_index} \
--genomeFastaFiles "${params.genomes}${params.organism}/${params.release}/${params.organism}.${params.release}.fa" \
--sjdbGTFfile "${params.genomes}${params.organism}/${params.release}/${params.organism}.${params.release}.gtf" \
--runThreadN 12
"""
}
process star_mapping {
stageInMode 'symlink'
stageOutMode 'move'
input:
tuple val(pair_id), path(fastq)
output:
val pair_id
when:
( ! file("${params.star_out}${pair_id}.Aligned.sortedByCoord.out.bam").exists() )
script:
def single = fastq instanceof Path
if ( single ) {
"""
cd ${params.raw_renamed}
echo ${pair_id}
if [ ! -e ${params.star_out}${pair_id}.Aligned.sortedByCoord.out.bam ] ; then
STAR --readFilesCommand zcat \
--runThreadN 12 \
--genomeDir ${params.star_index} \
--outSAMtype BAM SortedByCoordinate \
--limitBAMsortRAM 15000000000 \
--readFilesIn ${params.raw_renamed}${pair_id}.READ_1.fastq.gz \
--outFileNamePrefix ${params.star_out}${pair_id}. \
--quantMode GeneCounts \
--genomeLoad NoSharedMemory \
--alignIntronMax ${params.max_intron} \
--twopassMode Basic \
--outSAMattributes NH HI AS nM NM MD jM jI XS \
--sjdbGTFfile ${params.genomes}${params.organism}/${params.release}/${params.organism}.${params.release}.gtf
fi
"""
}
else {
"""
cd ${params.raw_renamed}
echo ${pair_id}
echo "pass paired"
if [ ! -e ${params.star_out}${pair_id}.Aligned.sortedByCoord.out.bam ] ; then
STAR --readFilesCommand zcat \
--runThreadN 12 \
--genomeDir ${params.star_index} \
--outSAMtype BAM SortedByCoordinate \
--limitBAMsortRAM 15000000000 \
--readFilesIn ${params.raw_renamed}${pair_id}.READ_1.fastq.gz ${params.raw_renamed}${pair_id}.READ_2.fastq.gz \
--outFileNamePrefix ${params.star_out}${pair_id}. \
--quantMode GeneCounts \
--genomeLoad NoSharedMemory \
--alignIntronMax ${params.max_intron} \
--twopassMode Basic \
--outSAMattributes NH HI AS nM NM MD jM jI XS \
--sjdbGTFfile ${params.genomes}${params.organism}/${params.release}/${params.organism}.${params.release}.gtf
fi
"""
}
}
process samtools_index {
stageInMode 'symlink'
stageOutMode 'move'
input:
val pair_id
tuple val(pair_id), path(fastq)
script:
"""
cd ${params.star_out}
if [ ! -e ${params.star_out}${pair_id}.Aligned.sortedByCoord.out.bam.bai ]; then
samtools index ${params.star_out}${pair_id}.Aligned.sortedByCoord.out.bam
fi
if [ ! -e ${params.star_out}${pair_id}.Aligned.sortedByCoord.out.bed ] ; then
samtools sort -@ ${task.cpus} ${params.star_out}${pair_id}.Aligned.sortedByCoord.out.bam | genomeCoverageBed -bga -split -ibam - > ${params.star_out}${pair_id}.Aligned.sortedByCoord.out.bed
fi
"""
}
process samtools_merge {
stageInMode 'symlink'
stageOutMode 'move'
when:
( ! file("${params.sajr_output}${params.series}.merged.sorted.bam.bai").exists() )
script:
"""
cd ${params.star_out}
if [ ! -e ${params.sajr_output}${params.series}.merged.sorted.bam ] ; then
samtools merge -f -@ ${task.cpus} -O BAM ${params.sajr_output}${params.series}.merged.bam *.bam
fi
cd ${params.sajr_output}
if [ ! -e ${params.series}.merged.sorted.bam ] ; then
samtools sort -@ ${task.cpus} -o ${params.series}.merged.sorted.bam ${params.series}.merged.bam
fi
if [ ! -e ${params.series}.merged.sorted.bam.bai ]; then
samtools index ${params.series}.merged.sorted.bam
fi
"""
}
workflow images {
main:
get_images()
}
workflow rename {
if ( ! file("${params.raw_renamed}").isDirectory() ) {
file("${params.raw_renamed}").mkdirs()
}
rename_sample()
}
workflow index {
main:
if ( ! file("${params.star_index}").isDirectory() ) {
file("${params.star_index}").mkdirs()
}
star_indexer()
}
workflow map_reads {
if ( ! file("${params.star_out}").isDirectory() ) {
file("${params.star_out}").mkdirs()
}
if ( ! file("${params.sajr_output}").isDirectory() ) {
file("${params.sajr_output}").mkdirs()
}
read_files=Channel.fromFilePairs( "${params.raw_renamed}/*.READ_{1,2}.fastq.gz", size: -1 )
star_mapping( read_files )
samtools_index(star_mapping.out.collect(), read_files)
}
workflow merging {
if ( ! file("${params.sajr_output}").isDirectory() ) {
file("${params.sajr_output}").mkdirs()
}
samtools_merge()
}