-
Notifications
You must be signed in to change notification settings - Fork 0
/
PenGU-testdata-build.nf
137 lines (95 loc) · 3.48 KB
/
PenGU-testdata-build.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
#!/usr/bin/env nextflow
params.csv = 'genome_urls.csv'
params.refreads = 'SRR8062313'
params.fq_header = '@M04531:123:000000000-T3STP:1'
params.read_lengths = '150,200,225,250'
params.outdir = 'output'
fq_header = params.fq_header
read_lengths = params.read_lengths.split(',')
outdir = params.outdir
Channel.fromPath(params.csv).splitCsv(header: true).set{ assemblyUrlsCsv }
Channel.from( read_lengths ).set{ readLengths }
Channel.fromSRA(params.refreads).set{ referenceFastq }
process DOWNLOAD_ASSEMBLY {
tag {cols.Name}
publishDir "${outdir}/assembly_fasta", mode: 'copy', pattern: "${cols.Name}.fa"
input:
val cols from assemblyUrlsCsv
output:
set val("${cols.Name}"), val("${cols.targetCov}"), val("${cols.ReadPrefix}"), file("${cols.Name}.fa"), val("${cols.extract_amplicon}"), val("${cols.amplicon_region}") into choiceExtractRegion
script:
"""
curl -fssL '${cols.RefSeqFTPURL}' | gzip -d > ${cols.Name}.fa
"""
}
Channel.create().set{ extractRegion }
Channel.create().set{ simulateReadsNoRegion }
choiceExtractRegion.choice( extractRegion, simulateReadsNoRegion) { it[4].toLowerCase() ==~ /true/ ? 0 : 1}
process EXTRACT_REGION {
tag { name }
input:
set name, coverage, prefix, file(assembly), extract, region from extractRegion
output:
set val(name), val(coverage), val(prefix), file("${assembly}") into simulateReadsRegion
script:
"""
samtools faidx ${assembly} ${region} > ${name}.${region}.fa
mv ${name}.${region}.fa ${assembly}
"""
}
simulateReadsRegion.mix(
simulateReadsNoRegion.map {
[ it[0], it[1], it[2], it[3] ]
}
).set{
getFirstFastaHeader
}
process GETFIRSTFASTAHEADER {
tag { name }
input:
set name, coverage, prefix, file(assembly) from getFirstFastaHeader
output:
set val(name), val(coverage), val(prefix), file("${assembly}"), stdout into simulateReads
script:
"""
grep -m 1 ">" ${assembly} | awk '{print \$1}' | tr -d '\\n'
"""
}
process STAGE_AND_DECOMPRESS_REF_FASTQ {
tag { name }
stageInMode 'copy'
input:
set file(forward), file(reverse) from referenceFastq.map{ [ it[1][0], it[1][1] ] }
output:
set file("*_1.fastq"), file ("*_2.fastq") into decompressedReferenceFastq
script:
"""
gzip -d *.fastq.gz
"""
}
process SIMULATE_READS {
tag { name }
cpus 4
maxForks 10
input:
set name, coverage, prefix, file(assembly), header, length, file(forward), file(reverse) from simulateReads.combine(readLengths).combine(decompressedReferenceFastq)
output:
set name, length, prefix, file("${name}.1.fastq"), file("${name}.2.fastq") into simulatedReads
script:
"""
afg -O ${name} -R ${assembly} -F1 ${forward} -F2 ${reverse} -RL ${length} -URQS true -CMP ${coverage} -TLM 500 -N 1000 -S \'${header}\'
"""
}
process CLEAN_SIMULATED_FASTQ {
tag { name }
publishDir "${outdir}/fastq", mode: 'copy', pattern: "*_R?_001.fastq.gz"
input:
set name, length, prefix, file(forward), file(reverse) from simulatedReads
output:
set name, file("*_R1_001.fastq.gz"), file("*_R2_001.fastq.gz")
script:
"""
sed "s/^@HWI-ST745_0097:7/${fq_header}/g" ${forward} | sed 's/#0\\/1/ 1:N:0:10/g' | sed '/^+HWI/s/.*/+/' | gzip > ${prefix}-${name}_S${length}_L001_R1_001.fastq.gz
sed "s/^@HWI-ST745_0097:7/${fq_header}/g" ${reverse} | sed 's/#0\\/2/ 2:N:0:10/g' | sed '/^+HWI/s/.*/+/' | gzip > ${prefix}-${name}_S${length}_L001_R2_001.fastq.gz
"""
}