-
Notifications
You must be signed in to change notification settings - Fork 1
/
qc_assem.nf
180 lines (146 loc) · 5.75 KB
/
qc_assem.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
nextflow.preview.dsl=2
date = new Date().format( 'yyyyMMdd' )
params.outdir = "assemblyQC-${date}"
params.reads = "mini_DF5120.ccs.fasta.gz"
params.assemblies = "mini_DF5120.hifiasm.fasta.gz"
params.odb = 'nematoda_odb10'
params.busco_downloads = './busco_downloads'
params.telomere = 'TTAGGC'
params.busco2nigons = "gene2Nigon_busco20200927.tsv.gz"
params.min_occurr = 3
params.teloRepeatWindowSize = 1000
params.minimumGenesPerSequence = 15
params.minimumNigonFrac = 0.9
params.minimumFracAlignedTeloReads = 0.1
params.windowSizeQC = 5e5
reads = Channel.fromPath(params.reads, checkIfExists: true)
.map { file -> tuple(file.Name - ~/(_filtered)?(\.telo)?(\.ccs)?(\.fa)?(\.fasta)?(\.gz)?$/, file) }
fastFiles = Channel.fromPath(params.assemblies, checkIfExists: true)
assemblies = fastFiles.map { file -> tuple(file.Name - ~/(\.hifiasm)?(\.flye)?(\.wtdbg2)?(\.canu_plus_flye)?(\.canu)?(\.fa)?(\.fasta)?(\.gz)?$/, file.Name - ~/(\.fa)?(\.fasta)?(\.gz)?$/, file) }
busco2nigons = Channel.fromPath(params.busco2nigons, checkIfExists: true).collect()
busco_dbs = Channel.of(params.odb.split(','))
busco_db_dir = file(params.busco_downloads)
geno_busco = assemblies.combine(busco_dbs)
process busco {
tag "${assembler}_${busco_db}"
publishDir "$params.outdir/busco", mode: 'copy'
input:
tuple val(strain), val(assembler), path(genome), val(busco_db)
path busco_db_dir
output:
path "*single_copy_busco_sequences.{faa,fna}"
path "${assembler}_${busco_db}_short_summary.txt"
tuple val(assembler), path( "${assembler}_${busco_db}_full_table.tsv"), emit: busco_full
script:
"""
if [ -f *.gz ]; then
gunzip -c $genome > assembly.fasta
else
ln -s $genome assembly.fasta
fi
busco -c ${task.cpus} -l $busco_db -i assembly.fasta --out run_busco --mode geno
awk 'BEGIN{FS="\\t";OFS=FS}(\$3 !~ /:/){print}' run_busco/run_*/full_table.tsv > ${assembler}_${busco_db}_full_table.tsv
mv run_busco/short_summary* ${assembler}_${busco_db}_short_summary.txt
#mv run_busco/run_*/full_table.tsv ${assembler}_${busco_db}_full_table.tsv
for ext in .faa; do
seqFile=${assembler}_${busco_db}_single_copy_busco_sequences\$ext
for file in run_busco/run_nematoda_odb10/busco_sequences/single_copy_busco_sequences/*\$ext; do
echo \">\$(basename \${file%\$ext})\" >> \$seqFile; tail -n +2 \$file >> \$seqFile;
done
done
rm -rf run_busco/ assembly.fasta
"""
}
process get_telomeric_reads {
tag "${strain}"
publishDir "$params.outdir/teloReads", mode: 'copy'
input:
tuple val(strain), path(reads)
output:
tuple val(strain), path("${strain}.telo.fasta.gz")
script:
"""
zcat $reads | filter_telomeric_reads.py -m ${params.telomere} --times ${params.min_occurr} -o ${strain}.telo.fasta.gz
"""
}
process map_telomeric_reads {
tag "${assemblies[1]}"
label 'nemaQC'
input:
tuple val(reads), val(assemblies)
output:
tuple val("${assemblies[1]}"), path("${assemblies[1]}.teloMapped.paf.gz")
script:
"""
minimap2 ${assemblies[2]} ${reads[1]} | \
gzip -c > ${assemblies[1]}.teloMapped.paf.gz
"""
}
process count_telomeric_repeat {
tag "${assembler}"
publishDir "$params.outdir/teloRepeatCounts", mode: 'copy'
label 'nemaQC'
input:
tuple val(strain), val(assembler), path(assembly)
output:
tuple val(assembler), path( "${assembler}_teloRepeatCounts.tsv.gz")
script:
"""
zcat $assembly | \
awk '/^>/{if (l!="") print l; printf "%s\\t", \$1; l=0; next}{l+=length(\$0)}END{print l}' | \
sed "s/>//" > ${assembler}.seqlen.tsv
seqkit locate --bed -M -G -p ${params.telomere} $assembly | \
cut -f 1,2,3 | \
sort -k1,1 -k2,2n > ${assembler}.teloRepeats.tsv
bedtools makewindows -g ${assembler}.seqlen.tsv -w ${params.teloRepeatWindowSize} | \
bedtools intersect -a stdin -b ${assembler}.teloRepeats.tsv -wa -wb | \
bedtools groupby -i stdin -g 1,2,3 -c 1 -o count | \
awk -F '\\t' 'BEGIN{OFS=FS}{print \$0, "telomeres"}' | \
gzip -c > ${assembler}_teloRepeatCounts.tsv.gz
rm ${assembler}.seqlen.tsv ${assembler}.teloRepeats.tsv
"""
}
process nematode_chromosome_QC {
tag "${assembler}"
publishDir "$params.outdir/nemaChromQC", mode: 'copy'
label 'nemaQC'
input:
tuple val(assembler), path(buscoTable), path(teloMappedReads), path(teloRepeats)
path(busco2nigons)
output:
path "${assembler}.{pdf,buscoString.txt,teloMappedBlocks.tsv}"
path "${assembler}.chromQC.tsv" , emit: busco_full
script:
"""
nemaChromQC.R --assemblyName $assembler \
--nigon $busco2nigons --busco $buscoTable \
--teloMappedPaf $teloMappedReads \
--teloRepeats $teloRepeats \
--minimumGenesPerSequence $params.minimumGenesPerSequence \
--minimumNigonFrac $params.minimumNigonFrac \
--minimumFracAlignedTeloReads $params.minimumFracAlignedTeloReads \
--windowSize $params.windowSizeQC
"""
}
process get_contiguity_stats {
tag "all"
publishDir "$params.outdir/", mode: 'copy'
label 'nemaQC'
input:
path(assemblies)
output:
path "assemblies_contiguity_stats.tsv"
script:
"""
seqkit stats -a -T $assemblies > assemblies_contiguity_stats.tsv
"""
}
workflow {
busco(geno_busco, busco_db_dir)
count_telomeric_repeat(assemblies)
get_telomeric_reads(reads)
map_telomeric_reads(get_telomeric_reads.out.cross(assemblies))
get_contiguity_stats(fastFiles.collect())
nematode_chromosome_QC(busco.out.busco_full.join(map_telomeric_reads.out.join(count_telomeric_repeat.out)),
busco2nigons)
}