/
store.funcs.spec.js
175 lines (168 loc) · 4.23 KB
/
store.funcs.spec.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
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import { extractVariantZygosity } from '@/store/modules/clinvarExport'
import { copy } from '../../testUtils.js'
// Set up extended Vue constructor
const localVue = createLocalVue()
localVue.use(Vuex)
describe('helper functions', () => {
let store
const termsRecessive = [
{ term_id: 'HP:0000007', term_name: 'Autosomal recessive inheritance' },
]
let individuals
beforeEach(() => {
// Individuals
individuals = {
'singleton-index-uuid': {
sodar_uuid: 'singleton-index-uuid',
name: 'singleton-index',
phenotype_terms: [],
sex: 'female',
},
'trio-index-uuid': {
sodar_uuid: 'trio-index-uuid',
name: 'trio-index',
phenotype_terms: [],
sex: 'female',
},
'trio-father-uuid': {
sodar_uuid: 'trio-father-uuid',
name: 'trio-father',
phenotype_terms: [],
sex: 'male',
},
'trio-mother-uuid': {
sodar_uuid: 'trio-mother-uuid',
name: 'trio-mother',
phenotype_terms: [],
sex: 'female',
},
}
// Setup relevant store/state fragment
const clinvarExport = {
namespaced: true,
state: () => copy({ individuals }),
}
store = new Vuex.Store({
modules: {
clinvarExport,
},
})
})
const genotypes = ['0/1', '1/0', '1/1', '0|1', '1/0', '1|1', '1']
const sexes = ['male', 'female']
let testTable = []
for (const gt of genotypes) {
for (const sex of sexes) {
for (const recessive of [true, false]) {
const variantAlleles = gt.match(/1/g).length
let zygosity
if (variantAlleles === 1) {
if (recessive) {
zygosity = 'Compound heterozygote'
} else {
zygosity = 'Single heterozygote'
}
} else {
zygosity = 'Homozygote'
}
testTable.push(['chr11', sex, gt, zygosity, variantAlleles, recessive])
}
}
}
testTable = testTable.concat(
['0/1', '1/0', '1/1', '0|1', '1/0', '1|1', '1'].map((gt) => [
'chrX',
'male',
gt,
'Hemizygote',
1,
false,
]),
['0/1', '1/0', '1/1', '0|1', '1/0', '1|1', '1'].map((gt) => [
'chrX',
'female',
gt,
gt.match(/1/g).length === 1 ? 'Single heterozygote' : 'Homozygote',
gt.match(/1/g).length,
false,
]),
['0/1', '1/0', '1/1', '0|1', '1/0', '1|1', '1'].map((gt) => [
'chrX',
'male',
gt,
'Hemizygote',
1,
true,
]),
['0/1', '1/0', '1/1', '0|1', '1/0', '1|1', '1'].map((gt) => [
'chrX',
'female',
gt,
gt.match(/1/g).length === 1 ? 'Compound heterozygote' : 'Homozygote',
gt.match(/1/g).length,
true,
]),
['0/1', '1/0', '1/1', '0|1', '1/0', '1|1', '1'].map((gt) => [
'chrY',
'male',
gt,
'Hemizygote',
1,
false,
]),
['0/1', '1/0', '1/1', '0|1', '1/0', '1|1', '1'].map((gt) => [
'chrY',
'female',
gt,
'not provided',
0,
false,
]),
['0/1', '1/0', '1/1', '0|1', '1/0', '1|1', '1'].map((gt) => [
'chrY',
'male',
gt,
'Hemizygote',
1,
true,
]),
['0/1', '1/0', '1/1', '0|1', '1/0', '1|1', '1'].map((gt) => [
'chrY',
'female',
gt,
'not provided',
0,
true,
])
)
test.each(testTable)(
'extractVariantZygosity on %p with %p singleton gt=%p expecting %p zygosity with %p variant alleles, recessive=%p',
(chromosome, sex, gt, variantZygosity, variantAlleleCount, recessive) => {
const smallVariant = {
chromosome,
genotype: {
'singleton-index': {
gt,
},
},
}
store.state.clinvarExport.individuals['singleton-index-uuid'].sex = sex
if (recessive) {
store.state.clinvarExport.individuals[
'singleton-index-uuid'
].phenotype_terms = termsRecessive
}
const actual = extractVariantZygosity(
smallVariant,
['singleton-index-uuid'],
store.state.clinvarExport
)
expect(actual).toStrictEqual({
variantAlleleCount,
variantZygosity,
})
}
)
})