-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhic_scaffolding.nf
153 lines (117 loc) · 4.33 KB
/
hic_scaffolding.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
nextflow.preview.dsl=2
date = new Date().format( 'yyyyMMdd' )
params.outdir = "scaf_hic-${date}"
params.reads = "/home/ubuntu/oscheius/0-inputs/test.ccsf.fasta.gz"
params.assemblies = "/home/ubuntu/oscheius/0-inputs/test.fasta"
params.restriction_sites = "GATC"
reads = Channel.fromPath(params.reads, checkIfExists: true)
.map { file -> tuple(file.Name - ~/(_test)?(_R1)?(_R2)?(\.subsamp)?(\.fastq)?(\.fq)?(\.gz)?$/, file.Name - ~/(_test)?(\.subsamp)?(\.fastq)?(\.fq)?(\.gz)?$/, file) }
assemblies = Channel.fromPath(params.assemblies, checkIfExists: true)
.map { file -> tuple(file.Name - ~/(_hifi)?(\.flyemetav2.6_longest20G)?(\.hifiasm)?(\.canu)?(\.flye)?(\.wtdbg2)?(\.purged)?(\.tol)?(\.fa)?(\.fasta)?(\.gz)?$/, file.Name - ~/(\.fasta)?(\.gz)?$/, file) }
process bwa_index {
tag "${assemName}"
input:
tuple val(strain), val(assemName), path(assembly)
output:
tuple val(strain), val(assemName), path("bwa")
script:
"""
mkdir bwa
bwa index -p bwa/${assemName} $assembly
"""
}
process get_restriction_sites {
tag "${assemName}"
input:
tuple val(strain), val(assemName), path(assembly)
output:
tuple val(strain), val(assemName), path("${assemName}_rest_site_positions.bed")
script:
"""
findRestSite --fasta $assembly \
--searchPattern $params.restriction_sites \
-o ${assemName}_rest_site_positions.bed
"""
}
process bwa_mem {
tag "${assemName}_${read_ID}"
input:
tuple val(strain), val(assemName), path(indexBase), val(strain2), val(read_ID), path(readFile)
output:
tuple val(strain), val(assemName), path("${assemName}_${read_ID}.bam")
script:
"""
INDEX=`find -L ./ -name "*.amb" | sed 's/.amb//'`
bwa mem -A1 -B4 -E50 -L0 \
-t ${task.cpus} \
\$INDEX \
$readFile \
| samtools view -@ 2 -bhS -o ${assemName}_${read_ID}.bam -
"""
}
process hic_matrix {
tag "${assemName}"
publishDir "$params.outdir/hic_QC", mode: 'copy'
input:
tuple val(strain), val(assemName), path(bam1), path(bam2), path(bed_sites)
output:
tuple val(strain), val(assemName), path("${assemName}.h5"), emit: h5_matrix
path("${assemName}_QC"), emit: folderQC
script:
"""
hicBuildMatrix --samFiles $bam1 $bam2 \
--binSize 10000 \
--restrictionSequence $params.restriction_sites \
--threads ${task.cpus} \
--inputBufferSize 100000 \
-o ${assemName}.h5 \
--QCfolder ${assemName}_QC
"""
}
process hic_correct {
tag "${assemName}"
input:
tuple val(strain), val(assemName), path(h5_matrix)
output:
tuple val(strain), val(assemName), path("${assemName}_corrected.h5"), emit: h5_corr_matrix
path("hic_diagnostic_${assemName}.png"), emit: hic_diagnostic
script:
"""
hicCorrectMatrix diagnostic_plot -m $h5_matrix -o hic_diagnostic_${assemName}.png
hicCorrectMatrix correct -m $h5_matrix --filterThreshold -4 3 -o ${assemName}_corrected.h5
"""
}
process scaffold {
tag "${assemName}"
publishDir "$params.outdir/scaffold", mode: 'copy'
input:
tuple val(strain), val(assemName), path(h5_matrix), path(assembly)
output:
tuple val(strain), val(assemName), path("${assemName}_scaf")
script:
"""
if [ -f *.gz ]; then
gunzip -c $assembly > assembly.fasta
else
ln -s $assembly assembly.fasta
fi
assemble -m $h5_matrix -o ${assemName}_scaf \
--min_scaffold_length 100000 --bin_size 10000 \
--misassembly_zscore_threshold -5 \
--num_iterations 3 -f assembly.fasta
rm ${assemName}_scaf/*h5 ${assemName}_scaf/*graphml
bgzip ${assemName}_scaf/super_scaffolds.fa
"""
}
workflow {
get_restriction_sites(assemblies)
bwa_index(assemblies)
bwa_mem(bwa_index.out.cross(reads)
.map{it -> tuple(it[0][0], it[0][1], it[0][2], it[1][0], it[1][1], it[1][2]) } )
hic_matrix(bwa_mem.out
.groupTuple(by: [0,1])
.join(get_restriction_sites.out, by: [0,1])
.map{it -> tuple(it[0], it[1], it[2][0], it[2][1], it[3]) })
hic_correct(hic_matrix.out.h5_matrix)
scaffold(hic_correct.out.h5_corr_matrix.join(assemblies, by: [0,1]))
}