-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenomics_pipeline.nf
372 lines (278 loc) · 9.7 KB
/
genomics_pipeline.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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
params.reads = "/TFM/genomics_pipeline/data/SRR*_{1,2}.fastq"
params.outdir = "/TFM/genomics_pipeline/results/fastqc_results"
// Define el canal de lecturas, asegurando que se encuentren archivos fastq
Channel
.fromFilePairs(params.reads, size: 2)
.ifEmpty { error "No se encontraron archivos fastq." }
.set { reads_ch }
//Se define el flujo de trabajo principal
workflow {
// Proceso para realizar FastQC antes de cualquier recorte
runFastQC(reads_ch)
// Proceso para recortar adaptadores usando Cutadapt
cutadapt_results = CUTADAPT(reads_ch)
// Proceso para mejorar la calidad de las lecturas con Trimmomatic
trimmomatic_results = TRIMMOMATIC(cutadapt_results.collect())
// Proceso para realizar FastQC después del recorte
fastqc_trimmomatic = FastQC_PostTrim(trimmomatic_results)
// Proceso para eliminar duplicados despues de aplicar trimmomatic
dedup_results = DeduplicateReads(trimmomatic_results)
// Proceso para normalizar
normalized_results = NormalizeReads(dedup_results)
// Proceso para realizar FastQC en lecturas normalizadas
fastqc_normalized = FastQC_Normalized(normalized_results)
// Alineamiento de lecturas normalizadas
aligned_results = AlignReads(normalized_results)
// Ordenar las lecturas
sorted_bam = SortBam(aligned_results)
// Proceso para agregar los readGroups
read_group_bam = AddReadGroup(sorted_bam)
// Proceso para el llamado de variantes
variants = CallVariants(read_group_bam)
//Generar estadisticas
variant_stats = GenerateVariantStats(variants)
//Filtrar variantes de baja calidad
filtered_variants = FilterLowQualityVariants(variants)
//Generar estadisticas de las variables filtradas
filtered_variant_stats = GenerateFilteredVariantStats(filtered_variants)
// Anotar variantes
annotated_variants = AnnotateVariants(filtered_variants)
// Preparar archivo para visualización en IGV
igv_index = PrepareForIGV(filtered_variants_gz)
}
process runFastQC {
tag "${sample_id}"
publishDir params.outdir, mode: 'copy'
input:
tuple val(sample_id), path(reads)
output:
path "*.html", emit: html
path "*.zip", emit: zip
script:
"""
echo "Ejecutando FastQC para ${sample_id}..."
fastqc -o . ${reads.join(' ')}
"""
}
process CUTADAPT {
tag "${pair_id}"
publishDir "/TFM/fastq_2", mode: 'copy' // Especifica dónde se guardarán los archivos de salida.
input:
tuple val(pair_id), path(reads)
output:
tuple val(pair_id), path("${pair_id}_1_trimmed.fastq"), path("${pair_id}_2_trimmed.fastq"), emit: trimmed_files
script:
"""
echo "Eliminando adaptadores Poly-A con Cutadapt..."
cutadapt -a "A{10}" -A "A{10}" \
-o ${pair_id}_1_trimmed.fastq -p ${pair_id}_2_trimmed.fastq \
${reads[0]} ${reads[1]}
echo "Verificación de archivos creados:"
ls -l ${pair_id}_1_trimmed.fastq ${pair_id}_2_trimmed.fastq
"""
}
process TRIMMOMATIC {
tag "${sample_id}"
publishDir "/TFM/trimmomatic_results_2", mode: 'copy'
input:
tuple val(sample_id), path(read1), path(read2)
output:
tuple val(sample_id), path("${sample_id}_1_paired.fastq"), path("${sample_id}_2_paired.fastq"), emit: trimmed_paired
script:
"""
echo "Ejecutando Trimmomatic para mejorar la calidad de las lecturas..."
java -jar /usr/share/java/trimmomatic-0.39.jar PE -phred33 \\
$read1 $read2 \\
${sample_id}_1_paired.fastq ${sample_id}_1_unpaired.fastq \\
${sample_id}_2_paired.fastq ${sample_id}_2_unpaired.fastq \\
ILLUMINACLIP:/usr/share/trimmomatic/adapters/TruSeq3-PE.fa:2:30:10 \\
LEADING:5 TRAILING:5 SLIDINGWINDOW:4:20 MINLEN:36
"""
}
process FastQC_PostTrim {
tag "${sample_id}"
publishDir "/TFM/fastqc_results_2", mode: 'copy'
input:
tuple val(sample_id), path(read1), path(read2)
output:
path "*.html", emit: qc_html
path "*.zip", emit: qc_zip
script:
"""
fastqc -o . ${read1} ${read2}
"""
}
process DeduplicateReads {
tag "${sample_id}"
publishDir "/TFM/dedupe_results_2", mode: 'copy'
input:
tuple val(sample_id), path(read1), path(read2)
output:
tuple val(sample_id), path ("${sample_id}_interleaved_dedup.fastq"), emit: interleaved_dedup
script:
"""
if [[ ! -f $read1 ]] || [[ ! -f $read2 ]]; then
echo "Error: Archivos de entrada faltantes para ${sample_id}."
exit 1
fi
echo "Archivos de entrada verificados para ${sample_id}. Procediendo con la deduplicación..."
/TFM/BBMap_39.11/bbmap/dedupe.sh in1=$read1 in2=$read2 out=${sample_id}_interleaved_dedup.fastq
"""
}
process NormalizeReads {
tag "${sample_id}"
publishDir "/TFM/normalized_2", mode: 'copy'
input:
tuple val(sample_id), path(interleaved_dedup)
output:
tuple val(sample_id), path ("${sample_id}_norm.fastq.gz"), emit: normalized_fastq
script:
"""
echo "Iniciando la normalización de lecturas para ${sample_id}..."
/TFM/BBMap_39.11/bbnorm.sh in=$interleaved_dedup out=${sample_id}_norm.fastq.gz target=150 min=5
echo "Normalización completada para ${sample_id}."
"""
}
process FastQC_Normalized {
tag "${sample_id}"
publishDir "/TFM/fastqc_results_2", mode: 'copy'
input:
tuple val(sample_id), path(norm_reads)
output:
path "*.html", emit: html
path "*.zip", emit: zip
script:
"""
echo "Ejecutando FastQC en lecturas normalizadas para ${sample_id}..."
fastqc -o . ${norm_reads}
"""
}
process AlignReads {
tag "${sample_id}"
publishDir "/TFM/aligned_2", mode: 'copy'
input:
tuple val(sample_id), path(reads)
output:
tuple val(sample_id), path ("${sample_id}_aligned.sam"), emit: aligned_sam
script:
"""
echo "Alineando lecturas al genoma de referencia para ${sample_id}..."
bwa mem /TFM/reference/Homo_sapiens.GRCh38.dna.primary_assembly.fa $reads > ${sample_id}_aligned.sam
"""
}
process SortBam {
tag "${sample_id}"
publishDir "/TFM/aligned_2", mode: 'copy'
input:
tuple val(sample_id), path(aligned_sam)
output:
tuple val(sample_id), path ("${sample_id}_sorted.bam"), emit: sorted_bam
script:
"""
echo "Convirtiendo SAM a BAM y ordenando para ${sample_id}..."
samtools view -S -b $aligned_sam > ${sample_id}_aligned.bam
samtools sort ${sample_id}_aligned.bam -o ${sample_id}_sorted.bam
"""
}
process AddReadGroup {
tag "${sample_id}"
publishDir "/TFM/aligned_2", mode: 'copy'
input:
tuple val(sample_id), path(sorted_bam)
output:
tuple val(sample_id), path ("${sample_id}_sorted_rg.bam"), emit: sorted_rg_bam
script:
"""
echo "Agregando Read Group ID a ${sample_id}..."
samtools addreplacerg -r 'ID:${sample_id}' -r 'LB:lib1' -r 'PL:ILLUMINA' -r 'PU:unit1' -r 'SM:${sample_id}' -o ${sample_id}_sorted_rg.bam $sorted_bam
"""
}
process CallVariants {
tag "${sample_id}"
publishDir "/TFM/variants_2", mode: 'copy'
input:
tuple val(sample_id), path(rg_bam)
output:
tuple val(sample_id), path ("${sample_id}_variants.vcf.gz"), emit: vcf
script:
"""
echo "Llamando variantes con bcftools para ${sample_id}..."
bcftools mpileup -Ou -f /TFM/reference/Homo_sapiens.GRCh38.dna.primary_assembly.fa $rg_bam | \
bcftools call -mv -Oz -o ${sample_id}_variants.vcf.gz
"""
}
process GenerateVariantStats {
tag "${sample_id}"
publishDir "/TFM/variants_2", mode: 'copy'
input:
tuple val(sample_id), path(vcf_file)
output:
tuple val(sample_id), path ("${sample_id}_variants_stats.txt"), emit: vcf_stats
script:
"""
echo "Generando estadísticas del archivo de variantes para ${sample_id}..."
bcftools stats $vcf_file > ${sample_id}_variants_stats.txt
"""
}
process FilterLowQualityVariants {
tag "${sample_id}"
publishDir "/TFM/variants_2", mode: 'copy'
input:
tuple val(sample_id), path(vcf_file)
output:
tuple val(sample_id), path ("${sample_id}_variants_filtered.vcf.gz"), emit: filtered_vcf
script:
"""
echo "Filtrando variantes de baja calidad para ${sample_id}..."
bcftools filter -e 'QUAL<30' -Oz -o ${sample_id}_variants_filtered.vcf.gz $vcf_file
"""
}
process GenerateFilteredVariantStats {
tag "${sample_id}"
publishDir "/TFM/variants_2", mode: 'copy'
input:
tuple val(sample_id), path(filtered_vcf)
output:
tuple val(sample_id), path ("${sample_id}_variants_filtered_stats.txt"), emit: filtered_stats
script:
"""
echo "Generando estadísticas del archivo de variantes filtrado para ${sample_id}..."
bcftools stats $filtered_vcf > ${sample_id}_variants_filtered_stats.txt
"""
}
process AnnotateVariants {
tag "${sample_id}"
publishDir "/TFM/variants_2", mode: 'copy'
input:
tuple val(sample_id), path(filtered_vcf)
output:
path "${sample_id}_annotated_variants.hg38_multianno.csv", emit: annotated_csv
script:
"""
echo "Iniciando la anotación de variantes para ${sample_id}..."
bcftools convert $filtered_vcf -O u -o ${sample_id}_filtered.avinput
perl /TFM/annovar/table_annovar.pl ${sample_id}_filtered.avinput /TFM/annovar/humandb/ \
-buildver hg38 \
-out ${sample_id}_annotated_variants \
-remove \
-protocol refGene,exac03,dbnsfp33a \
-operation g,f,f \
-nastring . \
-csvout
"""
}
process PrepareForIGV {
tag "${sample_id}"
publishDir "/TFM/variants_2", mode: 'copy'
input:
tuple val(sample_id), path(filtered_vcf_gz)
output:
path "${sample_id}_variants_filtered.vcf.gz.tbi", emit: igv_index
script:
"""
echo "Indexando archivo para visualización en IGV..."
tabix -p vcf ${filtered_vcf_gz}
"""
}