-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.nf
147 lines (124 loc) · 3.94 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
#!/usr/bin/env nextflow
params.reads = "${params.input}/*.{1,2}.fastq.gz"
def summary = [:]
summary['Output directory'] = params.outdir
summary['Trace directory'] = params.tracedir
log.info "-\033[2m---------------------------------------------------------------\033[0m-"
log.info summary.collect { k,v -> "${k.padRight(25)}: $v" }.join("\n")
log.info "-\033[2m---------------------------------------------------------------\033[0m-"
ch_reads = Channel.fromFilePairs(params.reads)
process REMOVEADAPTERS {
tag "$sample"
publishDir "${params.outdir}/adapters_removed", pattern: "*.round2.fastq.gz", mode: 'copy', overwrite: true
publishDir "${params.outdir}/adapters_removed/logs", pattern: "*.log", mode: 'copy', overwrite: true
cpus '8'
memory '32G'
time '2h'
input:
tuple val(sample), path(reads) from ch_reads
output:
tuple val(sample), path("*.round2.fastq.gz") into ch_trimmed
path "*.log"
"""
cutadapt \
-j ${task.cpus} \
--match-read-wildcards \
--times 1 \
-e 0.1 \
-O 1 \
--quality-cutoff 6 \
-m 18 \
-a NNNNNAGATCGGAAGAGCACACGTCTGAACTCCAGTCAC \
-g CTTCCGATCTACAAGTT \
-g CTTCCGATCTTGGTCCT \
-A AACTTGTAGATCGGA \
-A AGGACCAAGATCGGA \
-A ACTTGTAGATCGGAA \
-A GGACCAAGATCGGAA \
-A CTTGTAGATCGGAAG \
-A GACCAAGATCGGAAG \
-A TTGTAGATCGGAAGA \
-A ACCAAGATCGGAAGA \
-A TGTAGATCGGAAGAG \
-A CCAAGATCGGAAGAG \
-A GTAGATCGGAAGAGC \
-A CAAGATCGGAAGAGC \
-A TAGATCGGAAGAGCG \
-A AAGATCGGAAGAGCG \
-A AGATCGGAAGAGCGT \
-A GATCGGAAGAGCGTC \
-A ATCGGAAGAGCGTCG \
-A TCGGAAGAGCGTCGT \
-A CGGAAGAGCGTCGTG \
-A GGAAGAGCGTCGTGT \
-o ${sample}.1.adapterTrim.round1.fastq.gz \
-p ${sample}.2.adapterTrim.round1.fastq.gz \
${reads[0]} \
${reads[1]} \
> ${sample}.cutadapt_r1.log
cutadapt \
-j ${task.cpus} \
--match-read-wildcards \
--times 1 \
-e 0.1 \
-O 5 \
--quality-cutoff 6 \
-m 18 \
-A AACTTGTAGATCGGA \
-A AGGACCAAGATCGGA \
-A ACTTGTAGATCGGAA \
-A GGACCAAGATCGGAA \
-A CTTGTAGATCGGAAG \
-A GACCAAGATCGGAAG \
-A TTGTAGATCGGAAGA \
-A ACCAAGATCGGAAGA \
-A TGTAGATCGGAAGAG \
-A CCAAGATCGGAAGAG \
-A GTAGATCGGAAGAGC \
-A CAAGATCGGAAGAGC \
-A TAGATCGGAAGAGCG \
-A AAGATCGGAAGAGCG \
-A AGATCGGAAGAGCGT \
-A GATCGGAAGAGCGTC \
-A ATCGGAAGAGCGTCG \
-A TCGGAAGAGCGTCGT \
-A CGGAAGAGCGTCGTG \
-A GGAAGAGCGTCGTGT \
-o ${sample}.1.adapterTrim.round2.fastq.gz \
-p ${sample}.2.adapterTrim.round2.fastq.gz \
${sample}.1.adapterTrim.round1.fastq.gz \
${sample}.2.adapterTrim.round1.fastq.gz \
> ${sample}.cutadapt_r2.log
"""
}
process MOVEUMI {
tag "$sample"
publishDir "${params.outdir}/umi_moved", mode: 'copy', overwrite: true
cpus '1'
memory '32G'
time '2h'
input:
tuple val(sample), path(reads) from ch_trimmed
output:
tuple val(sample), path("*.umi.fastq.gz") into ch_moved
"""
#!/usr/bin/env python
import os
import sys
import gzip
from Bio import SeqIO
input_fq = "${reads[1]}"
output_fq = "${sample}.umi.fastq"
with gzip.open(input_fq, mode = 'rt') as f_in:
with open(output_fq, mode = 'w') as f_out:
for record in SeqIO.parse(f_in, 'fastq'):
header = record.id.split(":")
if '_' not in header[-1]:
rearranged = ":".join(header[1:]) + '_' + header[0]
record.id = rearranged
record.name = rearranged
record.description = rearranged
SeqIO.write(record, f_out, 'fastq')
os.system('pigz ' + output_fq)
"""
}