forked from jasteen/nextflow-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhiplexpipe_BRASTRAP_exome_panel_statsONLY.nf
256 lines (213 loc) · 7.99 KB
/
hiplexpipe_BRASTRAP_exome_panel_statsONLY.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
#!/usr/bin/env nextflow
// Required Inputs
refFolder = file("/projects/vh83/reference/genomes/b37/bwa_0.7.12_index/")
inputDirectory = file('./fastqs')
tmp_dir = file('/scratch/vh83/tmp/')
//project specific bed files
vardictBed = file("/projects/vh83/reference/brastrap_specific/vardict/BRASTRAP_721717_8column.bed")
intervalFile = file("/projects/vh83/reference/brastrap_specific/BRA-STRAP_621717_100.final.roverfile_g37.numsort.sorted.bed")
restrictedBed = file("/projects/vh83/reference/brastrap_specific/BRA-STRAP_coding_regions_targeted_sort.bed")
primer_bedpe_file= file("/projects/vh83/reference/prostrap/final_prostrap_b37_bedpe_bamclipper.txt")
// Getting Reference Files
refBase = "$refFolder/human_g1k_v37_decoy"
ref = file("${refBase}.fasta")
refDict = file("${refBase}.dict")
refFai = file("${refBase}.fasta.fai")
millsIndels = file("${refFolder}/accessory_files/Mills_and_1000G_gold_standard.indels.b37.vcf")
dbSNP = file("${refFolder}/accessory_files/dbsnp_138.b37.vcf")
genome_file = file("/projects/vh83/reference/genomes/b37/accessory_files/human_g1k_v37_decoy_GenomeFile.txt")
header = file("/home/jste0021/vh83/reference/genomes/b37/vcf_contig_header_lines.txt")
af_thr = 0.1
rheader = file("/projects/vh83/pipelines/code/Rheader.txt")
//Annotation resources
dbsnp_b37 = file("/projects/vh83/reference/genomes/b37/accessory_files/dbsnp_138.b37.vcf")
other_vep = file("/usr/local/vep/90/ensembl-vep/cache")
vep_brcaex = file("/projects/vh83/reference/annotation_databases/BRCA-Exchange/BRCA-exchange_accessed-180118/BRCA-exchange_accessed-180118.sort.vcf.gz")
vep_gnomad = file("/projects/vh83/reference/annotation_databases/gnomAD/gnomad.exomes.r2.0.2.sites/gnomad.exomes.r2.0.2.sites.vcf.gz")
vep_revel = file("/projects/vh83/reference/annotation_databases/REVEL/REVEL-030616/revel_all_chromosomes.vcf.gz")
vep_maxentscan = file("/projects/vh83/reference/annotation_databases/MaxEntScan/MaxEntScan_accessed-240118")
vep_exac = file("/projects/vh83/reference/annotation_databases/ExAC/ExAC_nonTCGA.r0.3.1/ExAC_nonTCGA.r0.3.1.sites.vep.vcf.gz")
vep_dbnsfp = file("/projects/vh83/reference/annotation_databases/dbNSFP/dbNSFPv2.9.3-VEP/dbNSFP-2.9.3.gz")
vep_dbscsnv = file("/projects/vh83/reference/annotation_databases/dbscSNV/dbscSNV1.0-VEP/dbscSNV.txt.gz")
vep_cadd = file("/projects/vh83/reference/annotation_databases/CADD/CADD-v1.3/1000G_phase3.tsv.gz")
// Tools
picardJar = '~/picard.jar'
bwaModule = 'bwa/0.7.17-gcc5'
samtoolsModule = 'samtools/1.9'
bamclipper_exe = '/projects/vh83/local_software/bamclipper/bamclipper.sh'
// Global Resource Configuration Options
globalExecutor = 'slurm'
globalStageInMode = 'symlink'
globalCores = 1
bwaCores = 4
vepCores = 4
globalMemoryS = '6 GB'
globalMemoryM = '8 GB'
globalMemoryL = '64 GB'
globalTimeS = '8m'
globalTimeM = '1h'
globalTimeL = '24h'
globalQueueS = 'short'
globalQueueL = 'comp'
// Creating channel from input directory
ch_inputFiles = Channel.fromFilePairs("${inputDirectory}/*_R{1,2}_001.fastq.gz")
process align_bwa {
input:
set baseName, file(fastqs) from ch_inputFiles
output:
set baseName, file("${baseName}.hq.sorted.bam"), file("${baseName}.hq.sorted.bam.bai") into ch_mappedBams
publishDir path: './bam_out', mode: 'copy'
executor globalExecutor
stageInMode globalStageInMode
module bwaModule
module samtoolsModule
cpus bwaCores
memory globalMemoryM
time globalTimeM
queue globalQueueL
"""
bwa mem -M -t ${task.cpus} -R "@RG\\tID:${baseName}\\tSM:${baseName}\\tPU:lib1\\tPL:Illumina" $ref ${fastqs[0]} ${fastqs[1]} \
| samtools view -u -h -q 1 -f 2 -F 4 -F 8 -F 256 - \
| samtools sort -@ $bwaCores -o "${baseName}.hq.sorted.bam"
samtools index "${baseName}.hq.sorted.bam" "${baseName}.hq.sorted.bam.bai"
"""
}
ch_mappedBams.into{ch_mappedBam1;ch_mappedBam2;ch_mappedBam3;ch_mappedBam4;ch_mappedBam5;ch_forBamClipper}
process InstersectBed {
input:
set sample, file(bam), file(bai) from ch_mappedBam2
output:
set sample, file("${sample}.intersectbed.bam") into ch_intersectBam
executor globalExecutor
stageInMode globalStageInMode
cpus 1
memory globalMemoryM
time globalTimeM
queue globalQueueL
script:
"""
module load bedtools/2.27.1-gcc5
intersectBed -abam ${bam} -b ${restrictedBed} > ${sample}.intersectbed.bam
"""
}
process CoverageBed {
input:
set sample, file(bam), file(bai) from ch_mappedBam3
output:
set sample, file("${sample}.bedtools_hist_all.txt") into ch_bedtools
executor globalExecutor
stageInMode globalStageInMode
cpus 1
memory globalMemoryM
time globalTimeM
queue globalQueueL
errorStrategy 'ignore'
script:
"""
module load bedtools/2.27.1-gcc5
coverageBed -b ${bam} -a ${restrictedBed} \
-sorted -hist -g ${genome_file} | \
grep all > "${sample}.bedtools_hist_all.txt"
"""
}
process ReadsMapped {
input:
set sample, file(bam), file(bai) from ch_mappedBam4
output:
set sample, file("${sample}.mapped_to_genome.txt") into ch_onGenome
executor globalExecutor
stageInMode globalStageInMode
cpus 1
module 'samtools/1.9'
memory globalMemoryM
time globalTimeM
queue globalQueueL
errorStrategy 'ignore'
script:
"""
samtools view -c -F4 ${bam} > "${sample}.mapped_to_genome.txt"
"""
}
process ReadsTotal {
input:
set sample, file(bam), file(bai) from ch_mappedBam5
output:
set sample, file("${sample}.total_raw_reads.txt") into ch_onTotal
executor globalExecutor
stageInMode globalStageInMode
cpus 1
module 'samtools/1.9'
memory globalMemoryM
time globalTimeM
queue globalQueueL
errorStrategy 'ignore'
script:
"""
samtools view -c ${bam} > "${sample}.total_raw_reads.txt"
"""
}
process TargetMapped {
input:
set sample, file(bam) from ch_intersectBam
output:
set sample, file("${sample}.mapped_to_target.txt") into ch_onTarget
executor globalExecutor
stageInMode globalStageInMode
cpus 1
memory globalMemoryM
module 'samtools/1.9'
time globalTimeM
queue globalQueueL
errorStrategy 'ignore'
script:
"""
samtools view -c -F4 ${bam} > ${sample}.mapped_to_target.txt
"""
}
ch_final = ch_bedtools.join(ch_onGenome)
ch_final2 = ch_final.join(ch_onTarget)
ch_final3 = ch_final2.join(ch_onTotal)
process collateData {
input:
set sample, file(bedtools), file(onGenome), file(onTarget), file(onTotal) from ch_final3
output:
set sample, file("${sample}_summary_coverage.txt") into ch_out
executor globalExecutor
stageInMode globalStageInMode
cpus 1
memory globalMemoryM
time globalTimeM
queue globalQueueL
errorStrategy 'ignore'
script:
"""
module purge
module load R/3.5.1
Rscript --vanilla /projects/vh83/pipelines/code/modified_summary_stat.R \
${bedtools} \
${onGenome} \
${onTarget} \
${onTotal} \
${sample} \
"${sample}_summary_coverage.txt"
"""
}
ch_out.map{a,b -> b}.collect().set{ch_out2}
process catStats {
input:
file(stats) from ch_out2
output:
file("project_summary.txt") into ch_out3
publishDir path: './metrics/', mode: 'copy'
executor globalExecutor
stageInMode globalStageInMode
cpus 1
memory globalMemoryM
time globalTimeM
queue globalQueueL
errorStrategy 'ignore'
script:
"""
cat ${rheader} ${stats} > "project_summary.txt"
"""
}