-
Notifications
You must be signed in to change notification settings - Fork 1
/
callVariants.nf
195 lines (163 loc) · 7.37 KB
/
callVariants.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
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include {
getBamFileSet;
getCramFileSet;
getAlignmentFileSet;
getAlignmentGenomicIntervals;
haplotypeCaller;
haplotypeCallerWithIntervals;
concatGvcfs;
haplotypeCallerSpark;
//combineGvcfsPerInterval;
getPedFile;
deepVariantCaller;
glnexusJointCaller;
dysguCallSvs;
indexVcf;
dysguMergeVcfs;
getBamChuncks;
mantaCallSvs;
mergeMantaCandidateSvCalls;
mergeMantaCandidateSmallIndelCalls;
mergeMantaDiploidSvCalls;
convertBcfToVcf;
createGenomicsDb;
createGenomicsDbPerInterval;
callVariantsFromGenomicsDB;
callVariantsFromExistingGenomicsDB;
collectIntervalsPerChromosome;
concatPerChromIntervalVcfs;
concatPerChromosomeVcfs;
getGvcfFiles;
getGvcfList;
getGenomicsdbWorkspaces;
combineGvcfs;
getVcfGenomicIntervals;
getGenomicIntervalList;
getGenomicInterval;
genotypeGvcfs;
updateGenomicsDbPerInterval;
} from "${projectDir}/modules/variantCallingPipeline.nf"
include {
indexAlignment;
} from "${projectDir}/modules/alignmentPipeline.nf"
workflow {
println "\nVariant calling begins here\n"
if(params.mode == 'jvarcall') {
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// YOU'RE EITHER STARING A NEW IMPORT OR UPDATING EXISTING GENOMICSDBs
// OR CALLING VARIANTS FROM EXISTING GENOMICSDBs
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if(params.imprt == true) {
//-=-=-=-=-=-=
// NEW IMPORT
//-=-=-=-=-=-=
gvcfs = getGvcfFiles().toList()
gvcfList = getGvcfList(gvcfs)
genomicInterval = getGenomicInterval(gvcfList)
genomicsDB = createGenomicsDbPerInterval(genomicInterval, gvcfList)
}
else if(params.update == true) {
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// UPDATING EXISTING GENOMICSDBs:
// genomicsdb workspaces must already exist and gvcfs must be provided with interval list
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
gvcfs = getGvcfFiles().toList()
gvcfList = getGvcfList(gvcfs)
genomicInterval = getGenomicInterval(gvcfList)
workspace = getGenomicsdbWorkspaces().map { wrkspc -> tuple(wrkspc.simpleName, wrkspc) }
genomicInterval
.map { interval -> tuple(interval.simpleName + "_${params.output_prefix}-workspace", interval) }
.join(workspace)
.map {workspaceName, interval, workspace -> tuple(workspaceName, interval, workspace)}
.set { workspace_interval }
updateGenomicsDbPerInterval(workspace_interval, gvcfList)
}
else {
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// DEFAULT TO CALL VARIANTS FROM EXISTING GENOMICSDBs:
// genomicsdb workspaces must already exist
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
workspace = getGenomicsdbWorkspaces().map { wrkspc -> tuple(wrkspc.simpleName, wrkspc) }
vcfs = callVariantsFromExistingGenomicsDB(workspace).view().collect()
vcfs_per_chrom_list = collectIntervalsPerChromosome(vcfs).flatten()
vcfs_per_chrom = concatPerChromIntervalVcfs(vcfs_per_chrom_list).collect().view()
concatPerChromosomeVcfs(vcfs_per_chrom).view()
}
}
else {
bamFileSet = getAlignmentFileSet()
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// ONE-STEP VARIANT CALLING FROM ALIGNMENT FILES: DYSGY & MANTA
// SINGLE SAMPLE STRUCTURAL VARIANT CALLING
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if(params.single_caller.toUpperCase() == 'DYSGU') {
dysguCallSvs(bamFileSet)
.set { vcf }
indexVcf(vcf)
.collect()
.set { vcfs }
dysguMergeVcfs(vcfs)
}
else if(params.single_caller.toUpperCase() == 'MANTA') {
bamFileSet
.map { bamName, bamFile, bamIndex -> tuple(bamFile, bamIndex) }
.collect()
.set { manta_input }
getBamChuncks(manta_input)
.flatten().view()
.set { bamlist }
mantaCallSvs(bamlist)
.collect().view()
.set { manta_calls }
mergeMantaDiploidSvCalls(manta_calls).view()
mergeMantaCandidateSmallIndelCalls(manta_calls).view()
mergeMantaCandidateSvCalls(manta_calls).view()
}
else {
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// TWO-STEP SMALL VARIANT CALLING VIA GVCFs: GATK, DEEPVARIANT & GLNEXUS
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if(params.single_caller.toUpperCase() == 'DEEPVARIANT') {
gvcf = deepVariantCaller(bamFileSet)
}
else { // SINGLE CALLER DEFAULTS TO GATK //
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=//
// haplotype caller per interval seems too cumbersome when //
// dealing with large samples sizes since each sample would //
// have to be split into hundreds - thousands of intervals //
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=//
gvcf = haplotypeCaller(bamFileSet)
}
if(params.mode == 'varcall') {
gvcfList = gvcf.collect()
if(params.joint_caller.toUpperCase() == 'GLNEXUS') {
bcf = glnexusJointCaller(gvcfList)
vcf = convertBcfToVcf(bcf)
}
else {
gvcfs = gvcf.collect().toList()
gvcfList = getGvcfList(gvcfs)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// JOINT CALLER DEFAULTS TO GATK
// Using 'GenomicsDBImport' for efficiency
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
genomicInterval = getGenomicInterval(gvcfList)
genomicsDB = createGenomicsDbPerInterval(genomicInterval, gvcfList)
workspace = genomicsDB.map { wrkspc -> tuple(wrkspc.simpleName, wrkspc) }
genomicInterval
.map { interval -> tuple(interval.simpleName + "_${params.output_prefix}-workspace", interval) }
.join(workspace)
.map {workspaceName, interval, workspace -> tuple(workspaceName, interval, workspace)}
.set { workspace_interval }
vcfs = callVariantsFromGenomicsDB(workspace_interval).collect()
vcfs_per_chrom_list = collectIntervalsPerChromosome(vcfs).flatten()
vcfs_per_chrom = concatPerChromIntervalVcfs(vcfs_per_chrom_list).collect().view()
concatPerChromosomeVcfs(vcfs_per_chrom).view()
}
}
}
}
}
workflow.onComplete { println "\nDone! Check results in ${params.output_dir}\n" }