-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDbNsfp.scala
282 lines (218 loc) · 10.8 KB
/
DbNsfp.scala
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
package galliaexample.dbnsfp
import aptus.{Anything_, String_}
import aptus.FilePath
import gallia._
// ===========================================================================
object DbNsfp {
import DbNsfpConstants._
import DbNsfpInputFields._
import DbNsfpOutputFields._
// ===========================================================================
def apply(in: FilePath): HeadS =
in
.stream {
_.tsv.noInferring /* treat everything as string */ }
.logProgress(1000)
// ===========================================================================
// handle trivially missing values
// so gets picked up by next removal (only fields with dash instead of dot (eg for 1:986633))
.translate(MutPred_score, MutPred_Top5features).using(
"-" -> MainMissingValue,
"," -> MainMissingValue /* only for "18:58537057;A>T", "19:41425799;A>C", "20:2655741;G>A" and "20:51613792;G>A" (in 4.0c) */)
// leave more complex ones untouched for now
.forAllKeys(_.removeIfValueFor(_).is(MainMissingValue))
.convert(ref, alt).toRequired // TODO: more here
// ===========================================================================
.rename(
`#chr` ~> chr,
`pos(1-based)` ~> pos)
// ---------------------------------------------------------------------------
.filterBy(
_.string_(pos),
_.string (ref),
_.string (alt))
.matches {
(pos, ref, alt) =>
pos.nonEmpty &&
ref != alt }
.convert(chr, pos).toRequired
// ---------------------------------------------------------------------------
// add shorthand (to act as ID)
.generate(shorthand).from(
_.string(chr),
_.string(pos),
_.string(ref),
_.string(alt))
.using { (chr, pos, ref, alt) =>
assert(BasicNucleotideSet.contains(ref))
assert(BasicNucleotideSet.contains(alt))
assert( chr != MainMissingValue)
s"${chr}:${pos.toLong};${ref}>${alt}" }
// ---------------------------------------------------------------------------
.map(rejig)
// ===========================================================================
def rejig(obj: HeadU): HeadU = {
obj
// ===========================================================================
// transposing
// ---------------------------------------------------------------------------
// GTEx
.zipStrings(
GTEx_V7_gene ~> gene,
GTEx_V7_tissue ~> tissue)
.splitBy(MainTupleSeparator)
.underNewKey(V7)
.nest(V7).under(GTEx)
// ---------------------------------------------------------------------------
// MutationTaster
.zipStrings(
MutationTaster_score ~> score,
MutationTaster_AAE ~> AA_exchange,
MutationTaster_model ~> model,
MutationTaster_pred ~> prediction )
.splitBy(MainTupleSeparator).underNewKey(MutationTaster)
// ---------------------------------------------------------------------------
// genes
.zipStrings(Transposing.GeneKeys.keyz)
.splitBy(MainTupleSeparator)
.underNewKey(genes)
// handle the "." parts of eg ".;.;.;.;." or ".;.;.;YES;." (see "21:44473990;T>A" for instance)
.transformAllEntities(genes).using {
_.forAllKeys {
_.removeIfValueFor(_).is(MainMissingValue) } }
// ===========================================================================
// gnomad
// ---------------------------------------------------------------------------
// exomes
.split(gnomAD_exomes_flag).by(";")
.rename( // add _overall manually for those (easier)
gnomAD_exomes_AN ~> 'gnomAD_exomes_overall_AN,
gnomAD_exomes_AC ~> 'gnomAD_exomes_overall_AC,
gnomAD_exomes_AF ~> 'gnomAD_exomes_overall_AF,
gnomAD_exomes_nhomalt ~> 'gnomAD_exomes_overall_nhomalt,
gnomAD_exomes_flag ~> 'gnomAD_exomes_overall_flag )
.forKeysMatching(_.startsWith("gnomAD_exomes_controls_"))
.thn {
_.rename(_).using {
_.replace( // eg: gnomAD_exomes_controls_AC ~> gnomAD_exomes_controls_overall_AC
"gnomAD_exomes_controls_",
"gnomAD_exomes_controls_overall_") } }
.forKeysMatching { key =>
key.startsWith("gnomAD_exomes_") &&
key.notContains("overall_") }
.thn {
_.rename(_).using {
_.replace( // eg: gnomAD_exomes_POPMAX_AC ~> gnomAD_exomes_default_POPMAX_AC
"gnomAD_exomes_",
"gnomAD_exomes_default_") } }
// ---------------------------------------------------------------------------
// genomes
.split(gnomAD_genomes_flag).by(";")
.rename( // add _overall manually for those (easier)
gnomAD_genomes_AN ~> 'gnomAD_genomes_overall_AN,
gnomAD_genomes_AC ~> 'gnomAD_genomes_overall_AC,
gnomAD_genomes_AF ~> 'gnomAD_genomes_overall_AF,
gnomAD_genomes_nhomalt ~> 'gnomAD_genomes_overall_nhomalt,
gnomAD_genomes_flag ~> 'gnomAD_genomes_overall_flag )
.forKeysMatching(_.startsWith("gnomAD_genomes_controls_")).thn {
_.rename(_).using {
_.replace( // eg: gnomAD_genomes_controls_AC ~> gnomAD_genomes_controls_overall_AC
"gnomAD_genomes_controls_",
"gnomAD_genomes_controls_overall_") } }
.forKeysMatching { key =>
key.startsWith("gnomAD_genomes_") &&
!key.contains("overall_") }
.thn {
_.rename(_).using {
_.replace( // eg: gnomAD_genomes_POPMAX_AC ~> gnomAD_genomes_default_POPMAX_AC
"gnomAD_genomes_",
"gnomAD_genomes_default_") } }
// ===========================================================================
// ExAC
.rename(
ExAC_AC ~> 'ExAC_overall_AC,
ExAC_AF ~> 'ExAC_overall_AF,
ExAC_nonTCGA_AC ~> 'ExAC_nonTCGA_overall_AC,
ExAC_nonTCGA_AF ~> 'ExAC_nonTCGA_overall_AF,
ExAC_nonpsych_AC ~> 'ExAC_nonpsych_overall_AC,
ExAC_nonpsych_AF ~> 'ExAC_nonpsych_overall_AF)
// default as opposed to nonTCGA and nonpsych
.forKeysMatching { key =>
key.startsWith("ExAC_") &&
key.notContains("_overall_") }
.thn {
_.rename(_).using {
_.replace("ExAC_", "ExAC_default") } }
// ===========================================================================
// clinvar
.transformString(clinvar_review).using(DbNsfpUtils.normalizeClinvarReview)
.rename(
clinvar_clnsig ~> 'clinvar_significance,
clinvar_hgvs ~> 'clinvar_HGVS,
clinvar_var_source ~> 'clinvar_source)
.split(
'clinvar_source,
clinvar_trait ,
clinvar_MedGen_id ,
clinvar_OMIM_id ,
clinvar_Orphanet_id)
.by("|")
// ===========================================================================
// renestings
// there are ~700 underscores, most actually represent nesting
// we use '@' temporarily to avoid unwanted renesting
.transformAllEntities(genes).using {
_ .rename( Renesting.GeneObjectExplicitRenamings ) // eg: "genename" to "symbol"
.rename(DbNsfpRenesting.geneObjectRuleBasedRenamings _) // eg: append "iction" to "_pred"-ending fields
.renestAllKeys.usingSeparator("_") }
// ---------------------------------------------------------------------------
.rename( Renesting.RootObjectExplicitRenamings ) // eg: "aaalt" to "AA_alt"
.rename(DbNsfpRenesting.rootObjectRuleBasedRenamings _) // eg: append "iction" to "_pred"-ending fields
.renestAllKeys.usingSeparator("_")
// ---------------------------------------------------------------------------
.forPathsMatching(_.key.name.contains("@")).thn { // this is a fairly costly operation as is
_.rename(_).using {
_.replace("@", "_") } }
// ===========================================================================
// MutPred top 5 features
.transformEntity(MutPred).using {
_ .rename('Top5features ~> top_5_features)
.split (top_5_features).by("; ") // has space following semi-colon (only one like that)
.transformString (top_5_features).using(MutPredTransformer.apply) }
// ===========================================================================
// misc
.nest(alt, ref).under(change)
.nest(
'ancestral_allele, // TODO: keep?
Denisova,
AltaiNeandertal,
VindijiaNeandertal)
.under('genotypes)
// ---------------------------------------------------------------------------
// genes
.transformAllEntities(genes).using {
_ .convert(VEP_canonical).toStrictFlag("YES")
.transformString(TSL).using(_.prepend("tsl"))
.split(Interpro_domain).by(DbNsfpUtils.splitInterproDomain) }
// ---------------------------------------------------------------------------
// these have cardinalities that vary independently of "genes"
// (the gnomAD and the MutationTaster counterparts are handled in their dedicated processors)
.split(rs_dbSNP151).by(";")
.transformEntity(Geuvadis |> eQTL)
.using(_.split(target_gene).by(";"))
.split(SiPhy |> `29way` |> pi).by(":") // only one like that
// ===========================================================================
// conversions (to numbers)
.forPathsMatching(_.key.containedIn(Converting.IntegerKeys)).thn(_.convert(_).toInt )
.forPathsMatching(_.key.containedIn(Converting. RealKeys)).thn(_.convert(_).toDouble)
// ---------------------------------------------------------------------------
.forEachKey(rankscores, phyloP, phastCons).thn {
_.transformEntity(_).using {
_.forLeafPaths(_.convert(_).toDouble) } }
// ---------------------------------------------------------------------------
// TODO:
// - can probably make some fields required at this point, eg MutationTaster.score, ...
// - couple of more fields to be turned from string to numbers?
}
}
// ===========================================================================