-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphaseAndImputeGenotypes.nf
143 lines (127 loc) · 5.62 KB
/
phaseAndImputeGenotypes.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
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include {
getChromosomes;
listChromosomes;
getHapmapGeneticMap;
getPlinkGeneticMap;
getEagleHapmapGeneticMap;
getShapeitGeneticMap;
getKgpPanel;
getVcf;
//getVcfFileset;
splitVcfByChrom;
beaglephase;
eaglePhaseWithoutRef;
eaglePhaseWithRef;
shapeitPhaseWithRef;
shapeitPhaseWithoutRef;
getVcfIndex;
getVcfIndex as getPhasedVcfIndex;
getCustomVcfPanel;
getm3vcf;
getCustomM3Panel;
imputeVariantsWithMinimac4;
} from "${projectDir}/modules/phasing_and_imputation.nf"
include {
getPhasedVcf;
validateVcf;
} from "${projectDir}/modules/custom_panel.nf"
workflow {
if(params.phase == true && params.impute == false) {
println "\nMODE: PHASE ONLY\n"
getChromosomes().set { chromosome }
vcf = getVcf()
chromosome.combine(vcf).set { split_vcf_input }
per_chr_vcf = splitVcfByChrom(split_vcf_input)
vcf_fileset = getVcfIndex(per_chr_vcf)
vcf_fileset.map { chr, vcf, index -> tuple("${chr}", vcf, index) }.set { vcfFileset }
if(params.phase_tool == 'eagle2') {
if(params.with_ref == true) {
geneticmap = getEagleHapmapGeneticMap()
refpanel = getKgpPanel()
refpanel.combine(geneticmap).set { panel_map }
vcfFileset.join(panel_map).set { phase_input }
phased = eaglePhaseWithRef(phase_input)
} else {
geneticmap = getEagleHapmapGeneticMap()
vcfFileset.combine(geneticmap).set { phase_input }
phased = eaglePhaseWithoutRef(phase_input)
}
} else if(params.phase_tool == 'shapeit4') {
if(params.with_ref == true) {
geneticmap = getShapeitGeneticMap()
refpanel = getKgpPanel()
refpanel.join(geneticmap).set { panel_map }
vcfFileset.join(panel_map).set { phase_input }
phased = shapeitPhaseWithRef(phase_input).view()
} else {
geneticmap = getShapeitGeneticMap()
vcfFileset.join(geneticmap).set { phase_input }
shapeitPhaseWithoutRef(phase_input).view().set { phased }
}
} else if(params.phase_tool == 'beagle5') {
geneticmap = getPlinkGeneticMap()
}
} else if(params.phase == false && params.impute == true) {
println "\nMODE: IMPUTE ONLY\n"
getVcf().set { vcf }
getChromosomes().set { chromosome }
chromosome.combine(vcf).set { split_vcf_input }
splitVcfByChrom(split_vcf_input).set { per_chr_vcf }
getVcfIndex(per_chr_vcf).set { vcf_fileset }
vcf_fileset.map { chr, vcf, index -> tuple("${chr}", vcf, index) }.set { vcfFileset }
if(params.impute_tool == 'minimac4') {
vcf = getPhasedVcf()
validateVcf(vcf).map { chr, vcf_file, vcf_index -> tuple(chr.baseName, vcf_file, vcf_index) }.set { vcf_fileset }
getCustomM3Panel().set{ minimac_ref_panel }
vcf_fileset.join(minimac_ref_panel).set{ minimac_input }
imputeVariantsWithMinimac4(minimac_input)
}
} else if(params.phase == true && params.impute == true) {
println "\nMODE: PHASE AND IMPUTE\n"
getVcf().set { vcf }
getChromosomes().set { chromosome }
chromosome.combine(vcf).set { split_vcf_input }
splitVcfByChrom(split_vcf_input).set { per_chr_vcf }
getVcfIndex(per_chr_vcf).set { vcf_fileset }
vcf_fileset.map { chr, vcf, index -> tuple("${chr}", vcf, index) }.set { vcfFileset }
if(params.phase_tool == 'eagle2' && params.impute_tool == 'minimac4') {
if(params.with_ref == true) {
getEagleHapmapGeneticMap().set { geneticmap }
getKgpPanel().set { refpanel }
refpanel.combine(geneticmap).set { panel_map }
vcfFileset.join(panel_map).set { phase_input }
eaglePhaseWithRef(phase_input).set { phased }
} else {
getEagleHapmapGeneticMap().set { geneticmap}
vcfFileset.combine(geneticmap).set { phase_input }
eaglePhaseWithoutRef(phase_input).set {phased }
}
getPhasedVcfIndex(phased).set { phased_vcf_fileset }
getCustomM3Panel().set{ minimac_ref_panel }
phased_vcf_fileset.join(minimac_ref_panel).set{ minimac_input }
imputeVariantsWithMinimac4(minimac_input)
} else if(params.phase_tool == 'shapeit4' && params.impute_tool == 'minimac4') {
if(params.with_ref == true) {
geneticmap = getShapeitGeneticMap()
refpanel = getKgpPanel()
refpanel.join(geneticmap).set { panel_map }
vcfFileset.join(panel_map).set { phase_input }
phased = shapeitPhaseWithRef(phase_input).view()
} else {
geneticmap = getShapeitGeneticMap()
vcfFileset.join(geneticmap).set { phase_input }
shapeitPhaseWithoutRef(phase_input).view().set { phased }
}
getPhasedVcfIndex(phased).set { phased_vcf_fileset }
getCustomM3Panel().set{ minimac_ref_panel }
phased_vcf_fileset.join(minimac_ref_panel).set{ minimac_input }
imputeVariantsWithMinimac4(minimac_input)
} else if(params.phase_tool == 'beagle5') {
geneticmap = getPlinkGeneticMap()
}
} else {
error: println "\nWORKFLOW STOPPED: Please select a run mode - 'phase' and/or 'impute' -\n"
}
}