-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
349 lines (294 loc) · 9.73 KB
/
index.js
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// NOTE: See this: https://github.com/brentp/slivar#how-it-works
// NOTE: Sets up default values. Since ducktape is using basic JS, we can't use
// ES5 defaults in functions
function allelic_balance_high_quality(sample) {
// This function ensures that the allelic balance observed
// is what is expected for given zygosity
if (sample.alts == 0) return sample.AB <= 0.01
else if (sample.alts == 1) return sample.AB >= 0.2 && sample.AB <= 0.8
return sample.AB >= 0.9
}
function high_quality(sample, depth, gq) {
if (depth == undefined) depth = 5
if (gq == undefined) gq = 10
return sample.DP > depth && sample.GQ > gq
}
function trio_quality(proband, mom, dad) {
if (proband == undefined) return false
if (mom == undefined) mom = {}
if (dad == undefined) dad = {}
if (high_quality(proband) == false || allelic_balance_high_quality(proband) == false) return false
if (mom.DP != undefined && mom.GQ != undefined && mom.AB != undefined) {
if (high_quality(mom) == false || allelic_balance_high_quality(mom) == false) return false
}
if (dad.DP != undefined && dad.GQ != undefined && dad.AB != undefined) {
if (high_quality(dad) == false || allelic_balance_high_quality(dad) == false) return false
}
return true
}
function uniparental_disomy(proband, mom, dad) {
if (mom == undefined) return false
if (dad == undefined) return false
return (
(proband.alts == 0 || proband.alts == 2) && ((mom.alts == 2 && dad.alts == 0) || (mom.alts == 0 && dad.alts == 2))
)
}
function sample_meets_dominant(sample) {
if (sample.affected == true && sample.alts == 1) return true
if (sample.affected == false && sample.alts == 0) return true
return false
}
function dominant(proband, mom, dad) {
if (mom == undefined) mom = {}
if (dad == undefined) dad = {}
if (mom.affected == false && dad.affected == false) return false
if (proband.alts == 1) {
if (sample_meets_dominant(mom) == false) return false
if (sample_meets_dominant(dad) == false) return false
} else {
return false
}
return true
}
function denovo(proband, mom, dad) {
if (mom == undefined) return false
if (dad == undefined) return false
if (proband.alts == 1) {
if (mom.alts != undefined && mom.alts != 0) return false
if (dad.alts != undefined && dad.alts != 0) return false
if (mom.AD[1] + dad.AD[1] > 0) return false
} else {
return false
}
return true
}
function x_linked_denovo(proband, mom, dad) {
if (mom == undefined) return false
if (dad == undefined) return false
if (proband.sex == 'male' && proband.alts == 0) return false
if (proband.sex == 'female' && proband.alts != 1) return false
if (mom.alts != undefined && mom.alts != 0) return false
if (dad.alts != undefined && dad.alts != 0) return false
return true
}
function homozygous_recessive(proband, mom, dad) {
if (mom == undefined) mom = {}
if (dad == undefined) dad = {}
if (proband.alts == 2) {
if (mom.alts != undefined && mom.alts != 1) return false
if (dad.alts != undefined && dad.alts != 1) return false
} else {
return false
}
return true
}
function relaxed_homozygous_recessive(proband, mom, dad) {
// NOTE: This decision was decided by Laura Conlin.
// Decided that in case of deletion, some parents could be HOM REF, but really be hemizygous
if (mom == undefined) mom = {}
if (dad == undefined) dad = {}
if (proband.alts == 2) {
if (mom.alts != undefined && mom.alts == 2) return false
if (dad.alts != undefined && dad.alts == 2) return false
} else {
return false
}
if (mom.alts == 0 && dad.alts == 0) return false
return true
}
function x_linked_homozygous_recessive(proband, parent1, parent2) {
if (parent1 == undefined) parent1 = {}
if (parent2 == undefined) parent2 = {}
if (parent1.alts != undefined && parent1.alts != 0 && parent1.sex == 'male') return false
if (parent2.alts != undefined && parent2.alts != 0 && parent2.sex == 'male') return false
if (parent1.alts != undefined && parent1.alts != 1 && parent1.sex == 'female') return false
if (parent2.alts != undefined && parent2.alts != 1 && parent2.sex == 'female') return false
if (proband.sex == 'male' && proband.alts == 0) return false
if (proband.sex == 'female' && proband.alts != 2) return false
return true
}
function compound_heterozygous_side(proband, mom, dad) {
// NOTE: this identifies if a variant is potentially a compound heterozygous
// NOTE: This is the 1st half, it then needs to run through slivar comphets to do in-phase transmission
if (mom == undefined) mom = {}
if (dad == undefined) dad = {}
if (proband.alts == 1) {
if (mom.alts != undefined && mom.alts == 2) return false
if (dad.alts != undefined && dad.alts == 2) return false
} else {
return false
}
return true
}
function remove_compound_heterozygous_side(INFO, key) {
// NOTE: this is useful for removing all the intermediate comphet side variants
// after running slivar comp-hets
if (key == undefined) key = 'compound_heterozygous_side'
if (key in INFO) return false
else return true
}
function proband_has_variant(proband) {
return proband.alts > 0
}
function present_in_database(INFO, headers, key) {
if (!('CSQ' in INFO)) return false
if (key == undefined) return false
if (headers == undefined) return false
const position = headers.indexOf(key)
var result = false
const effects = INFO.CSQ.split(',')
effects.forEach(function(effect) {
const data = effect.split('|')
if (data[position]) result = true
else result = false
})
return result
}
function includes_filter(INFO, headers, key, types) {
if (!('CSQ' in INFO)) return false
if (key == undefined) return false
if (headers == undefined) return false
if (types == undefined) types = []
const position = headers.indexOf(key)
var result = false
const effects = INFO.CSQ.split(',')
effects.forEach(function(effect) {
const data = effect.split('|')
const element = data[position]
types.forEach(function(type) {
if (element.includes(type)) result = true
})
})
return result
}
function does_not_includes_filter(INFO, headers, key, types) {
if (!('CSQ' in INFO)) return false
if (key == undefined) return false
if (headers == undefined) return false
if (types == undefined) return true
const position = headers.indexOf(key)
var result = false
const effects = INFO.CSQ.split(',')
effects.forEach(function(effect) {
const data = effect.split('|')
const element = data[position]
if (!types.includes(element)) result = true
})
return result
}
function match_filter(INFO, headers, key, types) {
if (!('CSQ' in INFO)) return false
if (key == undefined) return false
if (headers == undefined) return false
if (types == undefined) types = []
const position = headers.indexOf(key)
var result = false
const effects = INFO.CSQ.split(',')
effects.forEach(function(effect) {
const data = effect.split('|')
const element = data[position]
types.forEach(function(type) {
const values = splitVEPItem(element)
values.forEach(function(value) {
if (value == type) result = true
})
})
})
return result
}
function gte_filter(INFO, headers, key, cutoff) {
if (!('CSQ' in INFO)) return false
if (key == undefined) return false
if (headers == undefined) return false
if (cutoff == undefined) return false
const position = headers.indexOf(key)
var impact = false
const effects = INFO.CSQ.split(',')
effects.forEach(function(effect) {
const data = effect.split('|')
if (!data[position]) impact = false
else {
const scores = []
const values = splitVEPItem(data[position])
values.forEach(function(value) {
scores.push(parseFloat(value))
})
const score = Math.max.apply(null, scores)
if (score >= parseFloat(cutoff)) impact = true
}
})
return impact
}
function lte_filter(INFO, headers, key, cutoff) {
if (!('CSQ' in INFO)) return false
if (key == undefined) return false
if (headers == undefined) return false
if (cutoff == undefined) return false
const position = headers.indexOf(key)
var impact = false
const effects = INFO.CSQ.split(',')
effects.forEach(function(effect) {
const data = effect.split('|')
if (!data[position]) impact = false
else {
const scores = []
const values = splitVEPItem(data[position])
values.forEach(function(value) {
scores.push(parseFloat(value))
})
const score = Math.min.apply(null, scores)
if (score <= parseFloat(cutoff)) impact = true
}
})
return impact
}
function maf_filter(INFO, headers, key, cutoff) {
if (!('CSQ' in INFO)) return false
if (key == undefined) return false
if (headers == undefined) return false
if (cutoff == undefined) return false
const position = headers.indexOf(key)
var impact = false
const effects = INFO.CSQ.split(',')
effects.forEach(function(effect) {
const data = effect.split('|')
if (!data[position]) impact = true
else {
const scores = []
const values = splitVEPItem(data[position])
values.forEach(function(score) {
scores.push(parseFloat(score))
})
const score = Math.min.apply(null, scores)
if (score <= parseFloat(cutoff)) impact = true
}
})
return impact
}
function splitVEPItem(data) {
return data.split('&')
}
module.exports = {
allelic_balance_high_quality,
high_quality,
trio_quality,
uniparental_disomy,
sample_meets_dominant,
dominant,
denovo,
x_linked_denovo,
homozygous_recessive,
relaxed_homozygous_recessive,
x_linked_homozygous_recessive,
compound_heterozygous_side,
remove_compound_heterozygous_side,
proband_has_variant,
present_in_database,
includes_filter,
does_not_includes_filter,
match_filter,
gte_filter,
lte_filter,
maf_filter,
splitVEPItem,
}