@jbrowse/plugin-variants 4.0.4 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/esm/LDDisplay/SharedLDConfigSchema.d.ts +102 -0
  2. package/esm/LDDisplay/SharedLDConfigSchema.js +83 -0
  3. package/esm/LDDisplay/afterAttach.d.ts +2 -0
  4. package/esm/LDDisplay/afterAttach.js +123 -0
  5. package/esm/LDDisplay/components/BaseDisplayComponent.d.ts +15 -0
  6. package/esm/LDDisplay/components/BaseDisplayComponent.js +39 -0
  7. package/esm/LDDisplay/components/LDColorLegend.d.ts +15 -0
  8. package/esm/LDDisplay/components/LDColorLegend.js +75 -0
  9. package/esm/LDDisplay/components/LDDisplayComponent.d.ts +5 -0
  10. package/esm/LDDisplay/components/LDDisplayComponent.js +203 -0
  11. package/esm/LDDisplay/components/LinesConnectingMatrixToGenomicPosition.d.ts +16 -0
  12. package/esm/LDDisplay/components/LinesConnectingMatrixToGenomicPosition.js +109 -0
  13. package/esm/LDDisplay/configSchema1.d.ts +115 -0
  14. package/esm/LDDisplay/configSchema1.js +16 -0
  15. package/esm/LDDisplay/configSchema2.d.ts +115 -0
  16. package/esm/LDDisplay/configSchema2.js +16 -0
  17. package/esm/LDDisplay/index.d.ts +2 -0
  18. package/esm/LDDisplay/index.js +35 -0
  19. package/esm/LDDisplay/renderSvg.d.ts +3 -0
  20. package/esm/LDDisplay/renderSvg.js +36 -0
  21. package/esm/LDDisplay/shared.d.ts +367 -0
  22. package/esm/LDDisplay/shared.js +467 -0
  23. package/esm/LDDisplay/stateModel1.d.ts +365 -0
  24. package/esm/LDDisplay/stateModel1.js +10 -0
  25. package/esm/LDDisplay/stateModel2.d.ts +365 -0
  26. package/esm/LDDisplay/stateModel2.js +10 -0
  27. package/esm/LDRenderer/LDRenderer.d.ts +30 -0
  28. package/esm/LDRenderer/LDRenderer.js +109 -0
  29. package/esm/LDRenderer/components/LDRendering.d.ts +2 -0
  30. package/esm/LDRenderer/components/LDRendering.js +4 -0
  31. package/esm/LDRenderer/configSchema.d.ts +8 -0
  32. package/esm/LDRenderer/configSchema.js +10 -0
  33. package/esm/LDRenderer/index.d.ts +2 -0
  34. package/esm/LDRenderer/index.js +11 -0
  35. package/esm/LDRenderer/makeImageData.d.ts +20 -0
  36. package/esm/LDRenderer/makeImageData.js +157 -0
  37. package/esm/LDRenderer/types.d.ts +8 -0
  38. package/esm/LDRenderer/types.js +1 -0
  39. package/esm/LDTrack/configSchema.d.ts +85 -0
  40. package/esm/LDTrack/configSchema.js +7 -0
  41. package/esm/LDTrack/index.d.ts +2 -0
  42. package/esm/LDTrack/index.js +14 -0
  43. package/esm/LinearVariantDisplay/model.d.ts +126 -42
  44. package/esm/LinearVariantDisplay/model.js +46 -8
  45. package/esm/MultiLinearVariantDisplay/configSchema.d.ts +27 -1
  46. package/esm/MultiLinearVariantDisplay/model.d.ts +2635 -31
  47. package/esm/MultiLinearVariantDisplay/model.js +6 -0
  48. package/esm/MultiLinearVariantDisplay/renderSvg.d.ts +10 -2
  49. package/esm/MultiLinearVariantMatrixDisplay/configSchema.d.ts +25 -0
  50. package/esm/MultiLinearVariantMatrixDisplay/configSchema.js +26 -0
  51. package/esm/MultiLinearVariantMatrixDisplay/model.d.ts +2636 -32
  52. package/esm/MultiLinearVariantMatrixDisplay/model.js +6 -0
  53. package/esm/MultiLinearVariantMatrixRenderer/MultiLinearVariantMatrixRenderer.d.ts +2 -2
  54. package/esm/MultiLinearVariantMatrixRenderer/MultiLinearVariantMatrixRenderer.js +11 -9
  55. package/esm/MultiLinearVariantMatrixRenderer/components/MultiLinearVariantMatrixRendering.d.ts +8 -0
  56. package/esm/MultiLinearVariantMatrixRenderer/components/MultiLinearVariantMatrixRendering.js +14 -2
  57. package/esm/MultiLinearVariantMatrixRenderer/makeImageData.js +8 -11
  58. package/esm/MultiLinearVariantRenderer/MultiVariantRenderer.d.ts +2 -2
  59. package/esm/MultiLinearVariantRenderer/MultiVariantRenderer.js +4 -3
  60. package/esm/MultiLinearVariantRenderer/components/MultiLinearVariantRendering.d.ts +4 -0
  61. package/esm/MultiLinearVariantRenderer/components/MultiLinearVariantRendering.js +23 -2
  62. package/esm/MultiLinearVariantRenderer/makeImageData.js +12 -12
  63. package/esm/PlinkLDAdapter/PlinkLDAdapter.d.ts +25 -0
  64. package/esm/PlinkLDAdapter/PlinkLDAdapter.js +147 -0
  65. package/esm/PlinkLDAdapter/PlinkLDTabixAdapter.d.ts +24 -0
  66. package/esm/PlinkLDAdapter/PlinkLDTabixAdapter.js +156 -0
  67. package/esm/PlinkLDAdapter/configSchema.d.ts +10 -0
  68. package/esm/PlinkLDAdapter/configSchema.js +25 -0
  69. package/esm/PlinkLDAdapter/configSchemaTabix.d.ts +24 -0
  70. package/esm/PlinkLDAdapter/configSchemaTabix.js +46 -0
  71. package/esm/PlinkLDAdapter/index.d.ts +2 -0
  72. package/esm/PlinkLDAdapter/index.js +25 -0
  73. package/esm/PlinkLDAdapter/types.d.ts +29 -0
  74. package/esm/PlinkLDAdapter/types.js +1 -0
  75. package/esm/VariantFeatureWidget/VariantSampleGrid/VariantSampleGrid.js +1 -1
  76. package/esm/VariantRPC/MultiVariantGetFeatureDetails.d.ts +14 -0
  77. package/esm/VariantRPC/MultiVariantGetFeatureDetails.js +15 -0
  78. package/esm/VariantRPC/MultiVariantGetGenotypeMatrix.js +4 -1
  79. package/esm/VariantRPC/MultiVariantGetSimplifiedFeatures.js +3 -3
  80. package/esm/VariantRPC/executeClusterGenotypeMatrix.js +6 -3
  81. package/esm/VariantRPC/getGenotypeMatrix.d.ts +2 -3
  82. package/esm/VariantRPC/getGenotypeMatrix.js +4 -5
  83. package/esm/VariantRPC/getLDMatrix.d.ts +47 -0
  84. package/esm/VariantRPC/getLDMatrix.js +387 -0
  85. package/esm/VariantRPC/getLDMatrixFromPlink.d.ts +16 -0
  86. package/esm/VariantRPC/getLDMatrixFromPlink.js +105 -0
  87. package/esm/VariantRPC/getPhasedGenotypeMatrix.d.ts +2 -3
  88. package/esm/VariantRPC/getPhasedGenotypeMatrix.js +4 -5
  89. package/esm/VariantRPC/types.d.ts +3 -0
  90. package/esm/VcfAdapter/VcfAdapter.d.ts +1 -1
  91. package/esm/VcfAdapter/VcfAdapter.js +1 -2
  92. package/esm/VcfExtensionPoints/index.js +29 -3
  93. package/esm/VcfFeature/index.d.ts +2 -1
  94. package/esm/VcfFeature/index.js +4 -2
  95. package/esm/index.d.ts +1 -0
  96. package/esm/index.js +23 -0
  97. package/esm/shared/MultiVariantBaseModel.d.ts +2626 -26
  98. package/esm/shared/MultiVariantBaseModel.js +88 -39
  99. package/esm/shared/SharedVariantConfigSchema.d.ts +27 -1
  100. package/esm/shared/SharedVariantConfigSchema.js +28 -1
  101. package/esm/shared/VariantFeatureCache.d.ts +27 -0
  102. package/esm/shared/VariantFeatureCache.js +48 -0
  103. package/esm/shared/VariantRendererType.d.ts +23 -0
  104. package/esm/shared/VariantRendererType.js +15 -0
  105. package/esm/shared/applyColorPalette.d.ts +9 -0
  106. package/esm/shared/applyColorPalette.js +23 -0
  107. package/esm/shared/colorByAutorun.d.ts +10 -0
  108. package/esm/shared/colorByAutorun.js +39 -0
  109. package/esm/shared/components/AddFiltersDialog.d.ts +3 -3
  110. package/esm/shared/components/AddFiltersDialog.js +29 -22
  111. package/esm/shared/components/LDFilterDialog.d.ts +13 -0
  112. package/esm/shared/components/LDFilterDialog.js +102 -0
  113. package/esm/shared/components/MAFFilterDialog.js +23 -16
  114. package/esm/shared/components/RecombinationTrack.d.ts +21 -0
  115. package/esm/shared/components/RecombinationTrack.js +54 -0
  116. package/esm/shared/components/RecombinationYScaleBar.d.ts +7 -0
  117. package/esm/shared/components/RecombinationYScaleBar.js +34 -0
  118. package/esm/shared/components/SetColorDialogRowPalettizer.d.ts +3 -8
  119. package/esm/shared/components/SetColorDialogRowPalettizer.js +2 -14
  120. package/esm/shared/drawAlleleCount.js +9 -0
  121. package/esm/shared/drawPhased.d.ts +1 -1
  122. package/esm/shared/drawPhased.js +31 -2
  123. package/esm/shared/mafFilterUtils.d.ts +5 -0
  124. package/esm/shared/mafFilterUtils.js +17 -0
  125. package/esm/shared/minorAlleleFrequencyUtils.d.ts +4 -2
  126. package/esm/shared/minorAlleleFrequencyUtils.js +261 -19
  127. package/esm/shared/setupMultiVariantAutoruns.js +2 -0
  128. package/package.json +11 -10
@@ -1,28 +1,263 @@
1
1
  import { checkStopToken2 } from '@jbrowse/core/util/stopToken';
2
+ const GENOTYPE_SPLIT_REGEX = /[/|]/;
3
+ const SLASH = 47;
4
+ const PIPE = 124;
5
+ export function calculateAlleleCountsFast(feature) {
6
+ let count0 = 0;
7
+ let count1 = 0;
8
+ let count2 = 0;
9
+ let count3 = 0;
10
+ let countDot = 0;
11
+ const otherCounts = {};
12
+ feature.processGenotypes((str, start, end) => {
13
+ const len = end - start;
14
+ if (len === 3) {
15
+ const sep = str.charCodeAt(start + 1);
16
+ if (sep === SLASH || sep === PIPE) {
17
+ const c0 = str.charCodeAt(start);
18
+ const c1 = str.charCodeAt(start + 2);
19
+ if (c0 === 48) {
20
+ count0++;
21
+ }
22
+ else if (c0 === 49) {
23
+ count1++;
24
+ }
25
+ else if (c0 === 50) {
26
+ count2++;
27
+ }
28
+ else if (c0 === 51) {
29
+ count3++;
30
+ }
31
+ else if (c0 === 46) {
32
+ countDot++;
33
+ }
34
+ else {
35
+ const a0 = str[start];
36
+ otherCounts[a0] = (otherCounts[a0] || 0) + 1;
37
+ }
38
+ if (c1 === 48) {
39
+ count0++;
40
+ }
41
+ else if (c1 === 49) {
42
+ count1++;
43
+ }
44
+ else if (c1 === 50) {
45
+ count2++;
46
+ }
47
+ else if (c1 === 51) {
48
+ count3++;
49
+ }
50
+ else if (c1 === 46) {
51
+ countDot++;
52
+ }
53
+ else {
54
+ const a1 = str[start + 2];
55
+ otherCounts[a1] = (otherCounts[a1] || 0) + 1;
56
+ }
57
+ return;
58
+ }
59
+ }
60
+ if (len === 1) {
61
+ const c = str.charCodeAt(start);
62
+ if (c === 48) {
63
+ count0++;
64
+ }
65
+ else if (c === 49) {
66
+ count1++;
67
+ }
68
+ else if (c === 50) {
69
+ count2++;
70
+ }
71
+ else if (c === 51) {
72
+ count3++;
73
+ }
74
+ else if (c === 46) {
75
+ countDot++;
76
+ }
77
+ else {
78
+ const a = str[start];
79
+ otherCounts[a] = (otherCounts[a] || 0) + 1;
80
+ }
81
+ return;
82
+ }
83
+ const gt = str.slice(start, end);
84
+ const alleles = gt.split(GENOTYPE_SPLIT_REGEX);
85
+ for (const allele of alleles) {
86
+ if (allele === '0') {
87
+ count0++;
88
+ }
89
+ else if (allele === '1') {
90
+ count1++;
91
+ }
92
+ else if (allele === '2') {
93
+ count2++;
94
+ }
95
+ else if (allele === '3') {
96
+ count3++;
97
+ }
98
+ else if (allele === '.') {
99
+ countDot++;
100
+ }
101
+ else {
102
+ otherCounts[allele] = (otherCounts[allele] || 0) + 1;
103
+ }
104
+ }
105
+ });
106
+ const result = {};
107
+ if (count0 > 0) {
108
+ result['0'] = count0;
109
+ }
110
+ if (count1 > 0) {
111
+ result['1'] = count1;
112
+ }
113
+ if (count2 > 0) {
114
+ result['2'] = count2;
115
+ }
116
+ if (count3 > 0) {
117
+ result['3'] = count3;
118
+ }
119
+ if (countDot > 0) {
120
+ result['.'] = countDot;
121
+ }
122
+ for (const key in otherCounts) {
123
+ result[key] = otherCounts[key];
124
+ }
125
+ return result;
126
+ }
2
127
  export function calculateAlleleCounts(genotypes, cacheSplit) {
3
- const alleleCounts = {};
4
- const vals = Object.values(genotypes);
5
- for (const val of vals) {
6
- const genotype = val;
7
- const alleles = cacheSplit[genotype] ?? (cacheSplit[genotype] = genotype.split(/[/|]/));
128
+ let count0 = 0;
129
+ let count1 = 0;
130
+ let count2 = 0;
131
+ let count3 = 0;
132
+ let countDot = 0;
133
+ const otherCounts = {};
134
+ for (const key in genotypes) {
135
+ const genotype = genotypes[key];
136
+ const len = genotype.length;
137
+ if (len === 3) {
138
+ const sep = genotype[1];
139
+ if (sep === '/' || sep === '|') {
140
+ const a0 = genotype[0];
141
+ const a1 = genotype[2];
142
+ if (a0 === '0') {
143
+ count0++;
144
+ }
145
+ else if (a0 === '1') {
146
+ count1++;
147
+ }
148
+ else if (a0 === '2') {
149
+ count2++;
150
+ }
151
+ else if (a0 === '3') {
152
+ count3++;
153
+ }
154
+ else if (a0 === '.') {
155
+ countDot++;
156
+ }
157
+ else {
158
+ otherCounts[a0] = (otherCounts[a0] || 0) + 1;
159
+ }
160
+ if (a1 === '0') {
161
+ count0++;
162
+ }
163
+ else if (a1 === '1') {
164
+ count1++;
165
+ }
166
+ else if (a1 === '2') {
167
+ count2++;
168
+ }
169
+ else if (a1 === '3') {
170
+ count3++;
171
+ }
172
+ else if (a1 === '.') {
173
+ countDot++;
174
+ }
175
+ else {
176
+ otherCounts[a1] = (otherCounts[a1] || 0) + 1;
177
+ }
178
+ continue;
179
+ }
180
+ }
181
+ if (len === 1) {
182
+ if (genotype === '0') {
183
+ count0++;
184
+ }
185
+ else if (genotype === '1') {
186
+ count1++;
187
+ }
188
+ else if (genotype === '2') {
189
+ count2++;
190
+ }
191
+ else if (genotype === '3') {
192
+ count3++;
193
+ }
194
+ else if (genotype === '.') {
195
+ countDot++;
196
+ }
197
+ else {
198
+ otherCounts[genotype] = (otherCounts[genotype] || 0) + 1;
199
+ }
200
+ continue;
201
+ }
202
+ let alleles = cacheSplit[genotype];
203
+ if (!alleles) {
204
+ alleles = genotype.split(GENOTYPE_SPLIT_REGEX);
205
+ cacheSplit[genotype] = alleles;
206
+ }
8
207
  for (const allele of alleles) {
9
- const a = allele;
10
- alleleCounts[a] = (alleleCounts[a] || 0) + 1;
208
+ if (allele === '0') {
209
+ count0++;
210
+ }
211
+ else if (allele === '1') {
212
+ count1++;
213
+ }
214
+ else if (allele === '2') {
215
+ count2++;
216
+ }
217
+ else if (allele === '3') {
218
+ count3++;
219
+ }
220
+ else if (allele === '.') {
221
+ countDot++;
222
+ }
223
+ else {
224
+ otherCounts[allele] = (otherCounts[allele] || 0) + 1;
225
+ }
11
226
  }
12
227
  }
13
- return alleleCounts;
228
+ const result = {};
229
+ if (count0 > 0) {
230
+ result['0'] = count0;
231
+ }
232
+ if (count1 > 0) {
233
+ result['1'] = count1;
234
+ }
235
+ if (count2 > 0) {
236
+ result['2'] = count2;
237
+ }
238
+ if (count3 > 0) {
239
+ result['3'] = count3;
240
+ }
241
+ if (countDot > 0) {
242
+ result['.'] = countDot;
243
+ }
244
+ for (const key in otherCounts) {
245
+ result[key] = otherCounts[key];
246
+ }
247
+ return result;
14
248
  }
15
249
  export function calculateMinorAlleleFrequency(alleleCounts) {
16
250
  let firstMax = 0;
17
251
  let secondMax = 0;
18
252
  let total = 0;
19
- for (const count of Object.values(alleleCounts)) {
253
+ for (const key in alleleCounts) {
254
+ const count = alleleCounts[key];
20
255
  total += count;
21
256
  if (count > firstMax) {
22
257
  secondMax = firstMax;
23
258
  firstMax = count;
24
259
  }
25
- else if (count > secondMax && count !== firstMax) {
260
+ else if (count > secondMax) {
26
261
  secondMax = count;
27
262
  }
28
263
  }
@@ -31,7 +266,8 @@ export function calculateMinorAlleleFrequency(alleleCounts) {
31
266
  function getMostFrequentAlt(alleleCounts) {
32
267
  let mostFrequentAlt;
33
268
  let max = 0;
34
- for (const [alt, altCount] of Object.entries(alleleCounts)) {
269
+ for (const alt in alleleCounts) {
270
+ const altCount = alleleCounts[alt];
35
271
  if (alt !== '.' && alt !== '0' && altCount > max) {
36
272
  mostFrequentAlt = alt;
37
273
  max = altCount;
@@ -39,17 +275,23 @@ function getMostFrequentAlt(alleleCounts) {
39
275
  }
40
276
  return mostFrequentAlt;
41
277
  }
42
- export function getFeaturesThatPassMinorAlleleFrequencyFilter({ features, minorAlleleFrequencyFilter, lengthCutoffFilter, lastCheck, genotypesCache, splitCache = {}, }) {
278
+ export function getFeaturesThatPassMinorAlleleFrequencyFilter({ features, minorAlleleFrequencyFilter, lengthCutoffFilter, stopTokenCheck, genotypesCache, splitCache = {}, }) {
43
279
  const results = [];
44
280
  for (const feature of features) {
45
281
  if (feature.get('end') - feature.get('start') <= lengthCutoffFilter) {
46
- const featureId = feature.id();
47
- let genotypes = genotypesCache?.get(featureId);
48
- if (!genotypes) {
49
- genotypes = feature.get('genotypes');
50
- genotypesCache?.set(featureId, genotypes);
282
+ let alleleCounts;
283
+ if ('processGenotypes' in feature) {
284
+ alleleCounts = calculateAlleleCountsFast(feature);
285
+ }
286
+ else {
287
+ const featureId = feature.id();
288
+ let genotypes = genotypesCache?.get(featureId);
289
+ if (!genotypes) {
290
+ genotypes = feature.get('genotypes');
291
+ genotypesCache?.set(featureId, genotypes);
292
+ }
293
+ alleleCounts = calculateAlleleCounts(genotypes, splitCache);
51
294
  }
52
- const alleleCounts = calculateAlleleCounts(genotypes, splitCache);
53
295
  if (calculateMinorAlleleFrequency(alleleCounts) >=
54
296
  minorAlleleFrequencyFilter) {
55
297
  results.push({
@@ -59,7 +301,7 @@ export function getFeaturesThatPassMinorAlleleFrequencyFilter({ features, minorA
59
301
  });
60
302
  }
61
303
  }
62
- checkStopToken2(lastCheck);
304
+ checkStopToken2(stopTokenCheck);
63
305
  }
64
306
  return results;
65
307
  }
@@ -1,3 +1,4 @@
1
+ import { setupColorByAutorun } from "./colorByAutorun.js";
1
2
  import { getMultiVariantFeaturesAutorun } from "./getMultiVariantFeaturesAutorun.js";
2
3
  import { getMultiVariantSourcesAutorun } from "./getMultiVariantSourcesAutorun.js";
3
4
  import { setupTreeDrawingAutorun } from "./treeDrawingAutorun.js";
@@ -5,4 +6,5 @@ export function setupMultiVariantAutoruns(self) {
5
6
  getMultiVariantSourcesAutorun(self);
6
7
  getMultiVariantFeaturesAutorun(self);
7
8
  setupTreeDrawingAutorun(self);
9
+ setupColorByAutorun(self);
8
10
  }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@jbrowse/plugin-variants",
3
- "version": "4.0.4",
3
+ "version": "4.1.3",
4
+ "type": "module",
4
5
  "description": "JBrowse 2 variant adapters, tracks, etc.",
5
6
  "keywords": [
6
7
  "jbrowse",
@@ -23,12 +24,12 @@
23
24
  "@flatten-js/interval-tree": "^2.0.3",
24
25
  "@gmod/hclust": "^1.0.7",
25
26
  "@gmod/tabix": "^3.2.2",
26
- "@gmod/vcf": "^6.1.0",
27
+ "@gmod/vcf": "^7.0.0",
27
28
  "@jbrowse/mobx-state-tree": "^5.5.0",
28
- "@mui/icons-material": "^7.3.6",
29
- "@mui/material": "^7.3.6",
30
- "@mui/x-charts-vendor": "^8.25.0",
31
- "@mui/x-data-grid": "^8.25.0",
29
+ "@mui/icons-material": "^7.3.7",
30
+ "@mui/material": "^7.3.7",
31
+ "@mui/x-charts-vendor": "^8.26.0",
32
+ "@mui/x-data-grid": "^8.26.0",
32
33
  "@types/file-saver-es": "^2.0.3",
33
34
  "copy-to-clipboard": "^3.3.3",
34
35
  "escape-html": "^1.0.3",
@@ -37,10 +38,10 @@
37
38
  "mobx": "^6.15.0",
38
39
  "mobx-react": "^9.2.1",
39
40
  "rxjs": "^7.8.2",
40
- "@jbrowse/plugin-circular-view": "^4.0.4",
41
- "@jbrowse/plugin-linear-genome-view": "^4.0.4",
42
- "@jbrowse/sv-core": "^4.0.4",
43
- "@jbrowse/core": "^4.0.4"
41
+ "@jbrowse/plugin-linear-genome-view": "^4.1.3",
42
+ "@jbrowse/core": "^4.1.3",
43
+ "@jbrowse/plugin-circular-view": "^4.1.3",
44
+ "@jbrowse/sv-core": "^4.1.3"
44
45
  },
45
46
  "peerDependencies": {
46
47
  "react": ">=18.0.0"