@jbrowse/plugin-variants 2.3.1 → 2.3.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.
- package/dist/VcfAdapter/VcfAdapter.d.ts +1 -2
- package/dist/VcfAdapter/VcfAdapter.js +2 -2
- package/dist/VcfAdapter/VcfAdapter.js.map +1 -1
- package/dist/{VcfTabixAdapter/VcfFeature.d.ts → VcfFeature/index.d.ts} +3 -15
- package/dist/VcfFeature/index.js +59 -0
- package/dist/VcfFeature/index.js.map +1 -0
- package/dist/VcfFeature/util.d.ts +7 -0
- package/dist/VcfFeature/util.js +129 -0
- package/dist/VcfFeature/util.js.map +1 -0
- package/dist/VcfTabixAdapter/VcfTabixAdapter.d.ts +2 -19
- package/dist/VcfTabixAdapter/VcfTabixAdapter.js +1 -35
- package/dist/VcfTabixAdapter/VcfTabixAdapter.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/esm/VcfAdapter/VcfAdapter.d.ts +1 -2
- package/esm/VcfAdapter/VcfAdapter.js +2 -2
- package/esm/VcfAdapter/VcfAdapter.js.map +1 -1
- package/esm/{VcfTabixAdapter/VcfFeature.d.ts → VcfFeature/index.d.ts} +3 -15
- package/esm/VcfFeature/index.js +56 -0
- package/esm/VcfFeature/index.js.map +1 -0
- package/esm/VcfFeature/util.d.ts +7 -0
- package/esm/VcfFeature/util.js +123 -0
- package/esm/VcfFeature/util.js.map +1 -0
- package/esm/VcfTabixAdapter/VcfTabixAdapter.d.ts +2 -19
- package/esm/VcfTabixAdapter/VcfTabixAdapter.js +1 -35
- package/esm/VcfTabixAdapter/VcfTabixAdapter.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/package.json +3 -3
- package/src/VariantFeatureWidget/VariantFeatureWidget.test.tsx +42 -0
- package/src/VariantFeatureWidget/__snapshots__/{VariantFeatureWidget.test.js.snap → VariantFeatureWidget.test.tsx.snap} +1 -1
- package/src/VcfAdapter/VcfAdapter.test.ts +4 -5
- package/src/VcfAdapter/VcfAdapter.ts +3 -4
- package/src/VcfFeature/index.test.ts +132 -0
- package/src/VcfFeature/index.ts +104 -0
- package/src/VcfFeature/util.ts +140 -0
- package/src/VcfTabixAdapter/VcfTabixAdapter.test.ts +9 -10
- package/src/VcfTabixAdapter/VcfTabixAdapter.ts +3 -51
- package/src/__snapshots__/{index.test.js.snap → index.test.ts.snap} +0 -0
- package/src/{index.test.js → index.test.ts} +0 -1
- package/src/index.ts +1 -1
- package/dist/VcfTabixAdapter/VcfFeature.js +0 -187
- package/dist/VcfTabixAdapter/VcfFeature.js.map +0 -1
- package/esm/VcfTabixAdapter/VcfFeature.js +0 -184
- package/esm/VcfTabixAdapter/VcfFeature.js.map +0 -1
- package/src/LinearVariantDisplay/configSchema.test.js +0 -55
- package/src/VariantFeatureWidget/VariantFeatureWidget.test.js +0 -41
- package/src/VcfTabixAdapter/VcfFeature.test.ts +0 -118
- package/src/VcfTabixAdapter/VcfFeature.ts +0 -250
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { parseBreakend } from '@gmod/vcf';
|
|
2
|
+
const altTypeToSO = {
|
|
3
|
+
DEL: 'deletion',
|
|
4
|
+
INS: 'insertion',
|
|
5
|
+
DUP: 'duplication',
|
|
6
|
+
INV: 'inversion',
|
|
7
|
+
INVDUP: 'inverted duplication',
|
|
8
|
+
CNV: 'copy_number_variation',
|
|
9
|
+
TRA: 'translocation',
|
|
10
|
+
'DUP:TANDEM': 'tandem_duplication',
|
|
11
|
+
NON_REF: 'sequence_variant',
|
|
12
|
+
'*': 'sequence_variant',
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Get a sequence ontology (SO) term that describes the variant type
|
|
16
|
+
*/
|
|
17
|
+
export function getSOTermAndDescription(ref, alt, parser) {
|
|
18
|
+
// it's just a remark if there are no alternate alleles
|
|
19
|
+
if (!alt || alt.length === 0) {
|
|
20
|
+
return ['remark', 'no alternative alleles'];
|
|
21
|
+
}
|
|
22
|
+
const soTerms = new Set();
|
|
23
|
+
let descriptions = new Set();
|
|
24
|
+
alt.forEach(a => {
|
|
25
|
+
let [soTerm, description] = getSOAndDescFromAltDefs(ref, a, parser);
|
|
26
|
+
if (!soTerm) {
|
|
27
|
+
;
|
|
28
|
+
[soTerm, description] = getSOAndDescByExamination(ref, a);
|
|
29
|
+
}
|
|
30
|
+
if (soTerm && description) {
|
|
31
|
+
soTerms.add(soTerm);
|
|
32
|
+
descriptions.add(description);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
// Combine descriptions like ["SNV G -> A", "SNV G -> T"] to ["SNV G -> A,T"]
|
|
36
|
+
if (descriptions.size > 1) {
|
|
37
|
+
const descs = [...descriptions];
|
|
38
|
+
const prefixes = new Set(descs.map(desc => {
|
|
39
|
+
const prefix = desc.split('->');
|
|
40
|
+
return prefix[1] ? prefix[0] : desc;
|
|
41
|
+
}));
|
|
42
|
+
descriptions = new Set([...prefixes].map(prefix => {
|
|
43
|
+
const suffixes = descs
|
|
44
|
+
.map(desc => {
|
|
45
|
+
const pref = desc.split('-> ');
|
|
46
|
+
return pref[1] && pref[0] === prefix ? pref[1] : '';
|
|
47
|
+
})
|
|
48
|
+
.filter(f => !!f);
|
|
49
|
+
return suffixes.length ? prefix + '-> ' + suffixes.join(',') : prefix;
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
if (soTerms.size) {
|
|
53
|
+
return [[...soTerms].join(','), [...descriptions].join(',')];
|
|
54
|
+
}
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
export function getSOAndDescFromAltDefs(ref, alt, parser) {
|
|
58
|
+
if (typeof alt === 'string' && !alt.startsWith('<')) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
// look for a definition with an SO type for this
|
|
62
|
+
let soTerm = altTypeToSO[alt];
|
|
63
|
+
// if no SO term but ALT is in metadata, assume sequence_variant
|
|
64
|
+
if (!soTerm && parser.getMetadata('ALT', alt)) {
|
|
65
|
+
soTerm = 'sequence_variant';
|
|
66
|
+
}
|
|
67
|
+
if (soTerm) {
|
|
68
|
+
return [soTerm, alt];
|
|
69
|
+
}
|
|
70
|
+
// try to look for a definition for a parent term if we can
|
|
71
|
+
const modAlt = alt.split(':');
|
|
72
|
+
if (modAlt.length > 1) {
|
|
73
|
+
return getSOAndDescFromAltDefs(ref, `<${modAlt.slice(0, modAlt.length - 1).join(':')}>`, parser);
|
|
74
|
+
}
|
|
75
|
+
// no parent
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
// note: term SNV is used instead of SNP because SO definition of SNP says
|
|
79
|
+
// abundance must be at least 1% in population, and can't be sure we meet
|
|
80
|
+
// that
|
|
81
|
+
export function getSOAndDescByExamination(ref, alt) {
|
|
82
|
+
const bnd = parseBreakend(alt);
|
|
83
|
+
if (bnd) {
|
|
84
|
+
return ['breakend', alt];
|
|
85
|
+
}
|
|
86
|
+
else if (ref.length === 1 && alt.length === 1) {
|
|
87
|
+
return ['SNV', makeDescriptionString('SNV', ref, alt)];
|
|
88
|
+
}
|
|
89
|
+
else if (alt === '<INS>') {
|
|
90
|
+
return ['insertion', alt];
|
|
91
|
+
}
|
|
92
|
+
else if (alt === '<DEL>') {
|
|
93
|
+
return ['deletion', alt];
|
|
94
|
+
}
|
|
95
|
+
else if (alt === '<INV>') {
|
|
96
|
+
return ['deletion', alt];
|
|
97
|
+
}
|
|
98
|
+
else if (alt === '<TRA>') {
|
|
99
|
+
return ['translocation', alt];
|
|
100
|
+
}
|
|
101
|
+
else if (alt.includes('<')) {
|
|
102
|
+
return ['sv', alt];
|
|
103
|
+
}
|
|
104
|
+
else if (ref.length === alt.length) {
|
|
105
|
+
if (ref.split('').reverse().join('') === alt) {
|
|
106
|
+
return ['inversion', makeDescriptionString('inversion', ref, alt)];
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return ['substitution', makeDescriptionString('substitution', ref, alt)];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (ref.length <= alt.length) {
|
|
113
|
+
return ['insertion', makeDescriptionString('insertion', ref, alt)];
|
|
114
|
+
}
|
|
115
|
+
else if (ref.length > alt.length) {
|
|
116
|
+
return ['deletion', makeDescriptionString('deletion', ref, alt)];
|
|
117
|
+
}
|
|
118
|
+
return ['indel', makeDescriptionString('indel', ref, alt)];
|
|
119
|
+
}
|
|
120
|
+
function makeDescriptionString(soTerm, ref, alt) {
|
|
121
|
+
return `${soTerm} ${ref} -> ${alt}`;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/VcfFeature/util.ts"],"names":[],"mappings":"AAAA,OAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE9C,MAAM,WAAW,GAA0C;IACzD,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,WAAW;IAChB,MAAM,EAAE,sBAAsB;IAC9B,GAAG,EAAE,uBAAuB;IAC5B,GAAG,EAAE,eAAe;IACpB,YAAY,EAAE,oBAAoB;IAClC,OAAO,EAAE,kBAAkB;IAC3B,GAAG,EAAE,kBAAkB;CACxB,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,GAAW,EACX,GAAa,EACb,MAAW;IAEX,uDAAuD;IACvD,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5B,OAAO,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAA;KAC5C;IAED,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IACjC,IAAI,YAAY,GAAG,IAAI,GAAG,EAAU,CAAA;IACpC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QACd,IAAI,C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Ac,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;SACzE;KACF;SAAM,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE;QACnC,OAAO,CAAC,WAAW,EAAE,qBAAqB,CAAC,WAAW,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;KACnE;SAAM,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE;QAClC,OAAO,CAAC,UAAU,EAAE,qBAAqB,CAAC,UAAU,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;KACjE;IAED,OAAO,CAAC,OAAO,EAAE,qBAAqB,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AAC5D,CAAC;AAED,SAAS,qBAAqB,CAAC,MAAc,EAAE,GAAW,EAAE,GAAW;IACrE,OAAO,GAAG,MAAM,IAAI,GAAG,OAAO,GAAG,EAAE,CAAA;AACrC,CAAC"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { BaseFeatureDataAdapter, BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter';
|
|
2
|
-
import { NoAssemblyRegion
|
|
3
|
-
import { Feature } from '@jbrowse/core/util
|
|
2
|
+
import { NoAssemblyRegion } from '@jbrowse/core/util/types';
|
|
3
|
+
import { Feature } from '@jbrowse/core/util';
|
|
4
4
|
import { TabixIndexedFile } from '@gmod/tabix';
|
|
5
5
|
import VcfParser from '@gmod/vcf';
|
|
6
|
-
import { GenericFilehandle } from 'generic-filehandle';
|
|
7
6
|
export default class extends BaseFeatureDataAdapter {
|
|
8
7
|
private configured?;
|
|
9
8
|
private configurePre;
|
|
10
9
|
protected configure(): Promise<{
|
|
11
|
-
filehandle: GenericFilehandle;
|
|
12
10
|
vcf: TabixIndexedFile;
|
|
13
11
|
parser: VcfParser;
|
|
14
12
|
}>;
|
|
@@ -16,20 +14,5 @@ export default class extends BaseFeatureDataAdapter {
|
|
|
16
14
|
getHeader(): Promise<string>;
|
|
17
15
|
getMetadata(): Promise<any>;
|
|
18
16
|
getFeatures(query: NoAssemblyRegion, opts?: BaseOptions): import("rxjs").Observable<Feature>;
|
|
19
|
-
/**
|
|
20
|
-
* Checks if the data source has data for the given reference sequence,
|
|
21
|
-
* and then gets the features in the region if it does
|
|
22
|
-
*
|
|
23
|
-
* Currently this just calls getFeatureInRegion for each region. Adapters that
|
|
24
|
-
* are frequently called on multiple regions simultaneously may want to
|
|
25
|
-
* implement a more efficient custom version of this method.
|
|
26
|
-
*
|
|
27
|
-
* Also includes a bit of extra logging to warn when fetching a large portion
|
|
28
|
-
* of a VCF
|
|
29
|
-
* @param regions - Regions
|
|
30
|
-
* @param opts - Feature adapter options
|
|
31
|
-
* @returns Observable of Feature objects in the regions
|
|
32
|
-
*/
|
|
33
|
-
getFeaturesInMultipleRegions(regions: Region[], opts?: BaseOptions): import("rxjs").Observable<Feature>;
|
|
34
17
|
freeResources(): void;
|
|
35
18
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { BaseFeatureDataAdapter, } from '@jbrowse/core/data_adapters/BaseAdapter';
|
|
2
2
|
import { openLocation } from '@jbrowse/core/util/io';
|
|
3
|
-
import { bytesForRegions } from '@jbrowse/core/util';
|
|
4
3
|
import { ObservableCreate } from '@jbrowse/core/util/rxjs';
|
|
5
4
|
import { TabixIndexedFile } from '@gmod/tabix';
|
|
6
5
|
import VcfParser from '@gmod/vcf';
|
|
7
6
|
// local
|
|
8
|
-
import VcfFeature from '
|
|
7
|
+
import VcfFeature from '../VcfFeature';
|
|
9
8
|
export default class extends BaseFeatureDataAdapter {
|
|
10
9
|
async configurePre() {
|
|
11
10
|
const pm = this.pluginManager;
|
|
@@ -23,7 +22,6 @@ export default class extends BaseFeatureDataAdapter {
|
|
|
23
22
|
});
|
|
24
23
|
const header = await vcf.getHeader();
|
|
25
24
|
return {
|
|
26
|
-
filehandle,
|
|
27
25
|
vcf,
|
|
28
26
|
parser: new VcfParser({ header }),
|
|
29
27
|
};
|
|
@@ -66,38 +64,6 @@ export default class extends BaseFeatureDataAdapter {
|
|
|
66
64
|
observer.complete();
|
|
67
65
|
}, opts.signal);
|
|
68
66
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Checks if the data source has data for the given reference sequence,
|
|
71
|
-
* and then gets the features in the region if it does
|
|
72
|
-
*
|
|
73
|
-
* Currently this just calls getFeatureInRegion for each region. Adapters that
|
|
74
|
-
* are frequently called on multiple regions simultaneously may want to
|
|
75
|
-
* implement a more efficient custom version of this method.
|
|
76
|
-
*
|
|
77
|
-
* Also includes a bit of extra logging to warn when fetching a large portion
|
|
78
|
-
* of a VCF
|
|
79
|
-
* @param regions - Regions
|
|
80
|
-
* @param opts - Feature adapter options
|
|
81
|
-
* @returns Observable of Feature objects in the regions
|
|
82
|
-
*/
|
|
83
|
-
getFeaturesInMultipleRegions(regions, opts = {}) {
|
|
84
|
-
return ObservableCreate(async (observer) => {
|
|
85
|
-
const { vcf } = await this.configure();
|
|
86
|
-
// @ts-ignore
|
|
87
|
-
const bytes = await bytesForRegions(regions, vcf.index);
|
|
88
|
-
const { filehandle } = await this.configure();
|
|
89
|
-
const stat = await filehandle.stat();
|
|
90
|
-
let pct = Math.round((bytes / stat.size) * 100);
|
|
91
|
-
if (pct > 100) {
|
|
92
|
-
// this is just a bad estimate, make 100% if it goes over
|
|
93
|
-
pct = 100;
|
|
94
|
-
}
|
|
95
|
-
if (pct > 60) {
|
|
96
|
-
console.warn(`getFeaturesInMultipleRegions fetching ${pct}% of VCF file, but whole-file streaming not yet implemented`);
|
|
97
|
-
}
|
|
98
|
-
super.getFeaturesInMultipleRegions(regions, opts).subscribe(observer);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
67
|
freeResources( /* { region } */) { }
|
|
102
68
|
}
|
|
103
69
|
//# sourceMappingURL=VcfTabixAdapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VcfTabixAdapter.js","sourceRoot":"","sources":["../../src/VcfTabixAdapter/VcfTabixAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,GAEvB,MAAM,yCAAyC,CAAA;
|
|
1
|
+
{"version":3,"file":"VcfTabixAdapter.js","sourceRoot":"","sources":["../../src/VcfTabixAdapter/VcfTabixAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,GAEvB,MAAM,yCAAyC,CAAA;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,SAAS,MAAM,WAAW,CAAA;AAEjC,QAAQ;AACR,OAAO,UAAU,MAAM,eAAe,CAAA;AAEtC,MAAM,CAAC,OAAO,MAAO,SAAQ,sBAAsB;IAMzC,KAAK,CAAC,YAAY;QACxB,MAAM,EAAE,GAAG,IAAI,CAAC,aAAa,CAAA;QAC7B,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;QACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAA;QACpD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAA;QAEtD,MAAM,UAAU,GAAG,YAAY,CAAC,aAA6B,EAAE,EAAE,CAAC,CAAA;QAClE,MAAM,KAAK,GAAG,SAAS,KAAK,KAAK,CAAA;QACjC,MAAM,GAAG,GAAG,IAAI,gBAAgB,CAAC;YAC/B,UAAU;YACV,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;YAC7D,aAAa,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,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AE,GAAG,KAAK,CAAA;YACrC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAA;YAC9C,MAAM,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE;gBACtC,YAAY,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE;oBACjC,QAAQ,CAAC,IAAI,CACX,IAAI,UAAU,CAAC;wBACb,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;wBAC/B,MAAM;wBACN,EAAE,EAAE,GAAG,IAAI,CAAC,EAAE,QAAQ,UAAU,EAAE;qBACnC,CAAC,CACH,CAAA;gBACH,CAAC;gBACD,GAAG,IAAI;aACR,CAAC,CAAA;YACF,QAAQ,CAAC,QAAQ,EAAE,CAAA;QACrB,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IACjB,CAAC;IAEM,aAAa,EAAC,gBAAgB,IAAS,CAAC;CAChD"}
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
|
@@ -23,5 +23,5 @@ export default class VariantsPlugin extends Plugin {
|
|
|
23
23
|
ChordVariantDisplayF(pluginManager);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
export { default as VcfFeature } from './
|
|
26
|
+
export { default as VcfFeature } from './VcfFeature';
|
|
27
27
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,gBAAgB,MAAM,mBAAmB,CAAA;AAChD,OAAO,gBAAgB,MAAM,mBAAmB,CAAA;AAChD,OAAO,aAAa,MAAM,gBAAgB,CAAA;AAC1C,OAAO,MAAM,MAAM,sBAAsB,CAAA;AAEzC,OAAO,oBAAoB,MAAM,uBAAuB,CAAA;A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BAAgB,CAAC,aAAa,CAAC,CAAA;QAC/B,qBAAqB,CAAC,aAAa,CAAC,CAAA;QACpC,aAAa,CAAC,aAAa,CAAC,CAAA;QAC5B,gBAAgB,CAAC,aAAa,CAAC,CAAA;QAC/B,qBAAqB,CAAC,aAAa,CAAC,CAAA;QACpC,+BAA+B,CAAC,aAAa,CAAC,CAAA;QAC9C,oBAAoB,CAAC,aAAa,CAAC,CAAA;IACrC,CAAC;CACF;AAED,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jbrowse/plugin-variants",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.3",
|
|
4
4
|
"description": "JBrowse 2 variant adapters, tracks, etc.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jbrowse",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"mobx-react": "^7.0.0",
|
|
56
56
|
"mobx-state-tree": "^5.0.0",
|
|
57
57
|
"react": ">=16.8.0",
|
|
58
|
-
"rxjs": "^
|
|
58
|
+
"rxjs": "^7.0.0",
|
|
59
59
|
"tss-react": "^4.0.0"
|
|
60
60
|
},
|
|
61
61
|
"publishConfig": {
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"distModule": "esm/index.js",
|
|
65
65
|
"srcModule": "src/index.ts",
|
|
66
66
|
"module": "esm/index.js",
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "283e0387ccd5acc9f092cf00804d1fcac212e68d"
|
|
68
68
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { render } from '@testing-library/react'
|
|
3
|
+
import { types } from 'mobx-state-tree'
|
|
4
|
+
import { ConfigurationSchema } from '@jbrowse/core/configuration'
|
|
5
|
+
import PluginManager from '@jbrowse/core/PluginManager'
|
|
6
|
+
|
|
7
|
+
// locals
|
|
8
|
+
import { stateModelFactory } from '.'
|
|
9
|
+
import VariantFeatureDetails from './VariantFeatureWidget'
|
|
10
|
+
|
|
11
|
+
test('renders with just the required model elements', () => {
|
|
12
|
+
const pluginManager = new PluginManager([])
|
|
13
|
+
const Session = types.model({
|
|
14
|
+
rpcManager: types.optional(types.frozen(), {}),
|
|
15
|
+
configuration: ConfigurationSchema('test', {}),
|
|
16
|
+
widget: stateModelFactory(pluginManager),
|
|
17
|
+
})
|
|
18
|
+
const model = Session.create(
|
|
19
|
+
{
|
|
20
|
+
widget: {
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
type: 'VariantFeatureWidget',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{ pluginManager },
|
|
26
|
+
)
|
|
27
|
+
model.widget.setFeatureData({
|
|
28
|
+
refName: 'ctgA',
|
|
29
|
+
start: 176,
|
|
30
|
+
end: 177,
|
|
31
|
+
name: 'rs123',
|
|
32
|
+
REF: 'A',
|
|
33
|
+
ALT: ['<TRA>'],
|
|
34
|
+
QUAL: 10.4,
|
|
35
|
+
INFO: {
|
|
36
|
+
MQ: 5,
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const { container } = render(<VariantFeatureDetails model={model.widget} />)
|
|
41
|
+
expect(container.firstChild).toMatchSnapshot()
|
|
42
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`
|
|
3
|
+
exports[`renders with just the required model elements 1`] = `
|
|
4
4
|
<div
|
|
5
5
|
class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation1 css-1ps6pg7-MuiPaper-root"
|
|
6
6
|
data-testid="variant-side-drawer"
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { toArray } from 'rxjs/operators'
|
|
2
|
+
import { firstValueFrom } from 'rxjs'
|
|
2
3
|
import Adapter from './VcfAdapter'
|
|
3
4
|
import configSchema from './configSchema'
|
|
4
|
-
import { TextDecoder } from 'web-encoding'
|
|
5
|
-
window.TextDecoder = TextDecoder
|
|
6
5
|
|
|
7
6
|
test('adapter can fetch variants from volvox.vcf', async () => {
|
|
8
7
|
const adapter = new Adapter(
|
|
@@ -14,7 +13,7 @@ test('adapter can fetch variants from volvox.vcf', async () => {
|
|
|
14
13
|
}),
|
|
15
14
|
)
|
|
16
15
|
|
|
17
|
-
const
|
|
16
|
+
const feat = adapter.getFeatures({
|
|
18
17
|
assemblyName: 'volvox',
|
|
19
18
|
refName: 'ctgA',
|
|
20
19
|
start: 0,
|
|
@@ -24,6 +23,6 @@ test('adapter can fetch variants from volvox.vcf', async () => {
|
|
|
24
23
|
const names = await adapter.getRefNames()
|
|
25
24
|
expect(names).toMatchSnapshot()
|
|
26
25
|
|
|
27
|
-
const
|
|
28
|
-
expect(
|
|
26
|
+
const featArray = await firstValueFrom(feat.pipe(toArray()))
|
|
27
|
+
expect(featArray.slice(0, 5)).toMatchSnapshot()
|
|
29
28
|
})
|
|
@@ -2,16 +2,15 @@ import {
|
|
|
2
2
|
BaseFeatureDataAdapter,
|
|
3
3
|
BaseOptions,
|
|
4
4
|
} from '@jbrowse/core/data_adapters/BaseAdapter'
|
|
5
|
-
import { Region } from '@jbrowse/core/util
|
|
5
|
+
import { Region, Feature } from '@jbrowse/core/util'
|
|
6
6
|
import { openLocation } from '@jbrowse/core/util/io'
|
|
7
7
|
import { ObservableCreate } from '@jbrowse/core/util/rxjs'
|
|
8
|
-
import { Feature } from '@jbrowse/core/util/simpleFeature'
|
|
9
8
|
import IntervalTree from '@flatten-js/interval-tree'
|
|
10
9
|
import { unzip } from '@gmod/bgzf-filehandle'
|
|
11
10
|
import VCF from '@gmod/vcf'
|
|
12
11
|
|
|
13
12
|
// local
|
|
14
|
-
import VcfFeature from '../
|
|
13
|
+
import VcfFeature from '../VcfFeature'
|
|
15
14
|
|
|
16
15
|
const readVcf = (f: string) => {
|
|
17
16
|
const header: string[] = []
|
|
@@ -106,7 +105,7 @@ export default class VcfAdapter extends BaseFeatureDataAdapter {
|
|
|
106
105
|
try {
|
|
107
106
|
const { start, end, refName } = region
|
|
108
107
|
const { header, intervalTree } = await this.setup()
|
|
109
|
-
const parser = new VCF({ header
|
|
108
|
+
const parser = new VCF({ header })
|
|
110
109
|
intervalTree[refName]?.search([start, end]).forEach(f =>
|
|
111
110
|
observer.next(
|
|
112
111
|
new VcfFeature({
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import VcfParser from '@gmod/vcf'
|
|
2
|
+
import VcfFeature from './index'
|
|
3
|
+
|
|
4
|
+
test('test usage of the VcfFeature', () => {
|
|
5
|
+
const parser = new VcfParser({
|
|
6
|
+
header: `#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tBAMs/caudaus.sorted.sam`,
|
|
7
|
+
})
|
|
8
|
+
const line = `lcl|Scaffald_1\t80465\trs118266897\tR\tA\t29\tPASS\tNS=3;0,14;AF=0.5;DB;112;PG2.1`
|
|
9
|
+
|
|
10
|
+
const variant = parser.parseLine(line)
|
|
11
|
+
|
|
12
|
+
const f = new VcfFeature({
|
|
13
|
+
parser,
|
|
14
|
+
variant,
|
|
15
|
+
id: 'myuniqueid',
|
|
16
|
+
})
|
|
17
|
+
expect(f.id()).toEqual('myuniqueid')
|
|
18
|
+
expect(f.get('name')).toEqual('rs118266897')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test('try INS feature with END less than start', () => {
|
|
22
|
+
const parser = new VcfParser({
|
|
23
|
+
header: `#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tBAMs/caudaus.sorted.sam`,
|
|
24
|
+
})
|
|
25
|
+
const line = `chr1\t100\trs123\tR\tA\t29\tPASS\tEND=1;SVTYPE=INS`
|
|
26
|
+
|
|
27
|
+
const variant = parser.parseLine(line)
|
|
28
|
+
|
|
29
|
+
const f = new VcfFeature({
|
|
30
|
+
parser,
|
|
31
|
+
variant,
|
|
32
|
+
id: 'myuniqueid',
|
|
33
|
+
})
|
|
34
|
+
expect(f.id()).toEqual('myuniqueid')
|
|
35
|
+
expect(f.get('start')).toEqual(99)
|
|
36
|
+
expect(f.get('end')).toEqual(100)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('try DEL feature with END info field valid', () => {
|
|
40
|
+
const parser = new VcfParser({
|
|
41
|
+
header: `#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tBAMs/caudaus.sorted.sam`,
|
|
42
|
+
})
|
|
43
|
+
const line = `chr1\t100\trs123\tR\t<DEL>\t29\tPASS\tEND=1000;SVTYPE=DEL`
|
|
44
|
+
|
|
45
|
+
const variant = parser.parseLine(line)
|
|
46
|
+
|
|
47
|
+
const f = new VcfFeature({
|
|
48
|
+
parser,
|
|
49
|
+
variant,
|
|
50
|
+
id: 'myuniqueid',
|
|
51
|
+
})
|
|
52
|
+
expect(f.id()).toEqual('myuniqueid')
|
|
53
|
+
expect(f.get('start')).toEqual(99)
|
|
54
|
+
expect(f.get('end')).toEqual(1000)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('multiple SVs', () => {
|
|
58
|
+
const parser = new VcfParser({
|
|
59
|
+
header: `#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tBAMs/caudaus.sorted.sam`,
|
|
60
|
+
})
|
|
61
|
+
const line = `chr1\t100\trs123\tR\t<INVDUP>,<INV>\t29\tPASS\tEND=1000;SVTYPE=DEL`
|
|
62
|
+
|
|
63
|
+
const variant = parser.parseLine(line)
|
|
64
|
+
|
|
65
|
+
const f = new VcfFeature({
|
|
66
|
+
parser,
|
|
67
|
+
variant,
|
|
68
|
+
id: 'myuniqueid',
|
|
69
|
+
})
|
|
70
|
+
expect(f.get('description')).toEqual('<INVDUP>,<INV>')
|
|
71
|
+
})
|
|
72
|
+
test('BND', () => {
|
|
73
|
+
const parser = new VcfParser({
|
|
74
|
+
header: `#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tBAMs/caudaus.sorted.sam`,
|
|
75
|
+
})
|
|
76
|
+
const line = `chr1\t100\trs123\tR\tG[ctgA:34200[\t29\tPASS\tEND=1000;SVTYPE=BND`
|
|
77
|
+
|
|
78
|
+
const variant = parser.parseLine(line)
|
|
79
|
+
|
|
80
|
+
const f = new VcfFeature({
|
|
81
|
+
parser,
|
|
82
|
+
variant,
|
|
83
|
+
id: 'myuniqueid',
|
|
84
|
+
})
|
|
85
|
+
expect(f.get('description')).toEqual('G[ctgA:34200[')
|
|
86
|
+
})
|
|
87
|
+
test('multiple BND', () => {
|
|
88
|
+
const parser = new VcfParser({
|
|
89
|
+
header: `#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tBAMs/caudaus.sorted.sam`,
|
|
90
|
+
})
|
|
91
|
+
const line = `chr1\t100\trs123\tR\tG[ctgA:34200[,G[ctgA:44200[\t29\tPASS\tEND=1000;SVTYPE=BND`
|
|
92
|
+
|
|
93
|
+
const variant = parser.parseLine(line)
|
|
94
|
+
|
|
95
|
+
const f = new VcfFeature({
|
|
96
|
+
parser,
|
|
97
|
+
variant,
|
|
98
|
+
id: 'myuniqueid',
|
|
99
|
+
})
|
|
100
|
+
expect(f.get('description')).toEqual('G[ctgA:34200[,G[ctgA:44200[')
|
|
101
|
+
})
|
|
102
|
+
test('multiple SNV', () => {
|
|
103
|
+
const parser = new VcfParser({
|
|
104
|
+
header: `#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tBAMs/caudaus.sorted.sam`,
|
|
105
|
+
})
|
|
106
|
+
const line = `chr1\t100\trs123\tG\tA,C\t29\tPASS\tHELLO=world`
|
|
107
|
+
|
|
108
|
+
const variant = parser.parseLine(line)
|
|
109
|
+
|
|
110
|
+
const f = new VcfFeature({
|
|
111
|
+
parser,
|
|
112
|
+
variant,
|
|
113
|
+
id: 'myuniqueid',
|
|
114
|
+
})
|
|
115
|
+
expect(f.get('description')).toEqual('SNV G -> A,C')
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test('multiple SNV2', () => {
|
|
119
|
+
const parser = new VcfParser({
|
|
120
|
+
header: `#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tBAMs/caudaus.sorted.sam`,
|
|
121
|
+
})
|
|
122
|
+
const line = `chr1\t100\trs123\tG\tAT,<*>\t29\tPASS\tHELLO=world`
|
|
123
|
+
|
|
124
|
+
const variant = parser.parseLine(line)
|
|
125
|
+
|
|
126
|
+
const f = new VcfFeature({
|
|
127
|
+
parser,
|
|
128
|
+
variant,
|
|
129
|
+
id: 'myuniqueid',
|
|
130
|
+
})
|
|
131
|
+
expect(f.get('description')).toEqual('insertion G -> AT,<*>')
|
|
132
|
+
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Feature } from '@jbrowse/core/util'
|
|
2
|
+
import VCF from '@gmod/vcf'
|
|
3
|
+
|
|
4
|
+
// locals
|
|
5
|
+
import { getSOTermAndDescription } from './util'
|
|
6
|
+
|
|
7
|
+
/* eslint-disable no-underscore-dangle */
|
|
8
|
+
|
|
9
|
+
interface Samples {
|
|
10
|
+
[key: string]: {
|
|
11
|
+
[key: string]: { values: string[] | number[] | null }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface FeatureData {
|
|
16
|
+
[key: string]: unknown
|
|
17
|
+
refName: string
|
|
18
|
+
start: number
|
|
19
|
+
end: number
|
|
20
|
+
description?: string
|
|
21
|
+
type?: string
|
|
22
|
+
name?: string
|
|
23
|
+
aliases?: string[]
|
|
24
|
+
samples?: Samples
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default class VCFFeature implements Feature {
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
private variant: any
|
|
30
|
+
|
|
31
|
+
private parser: VCF
|
|
32
|
+
|
|
33
|
+
private data: FeatureData
|
|
34
|
+
|
|
35
|
+
private _id: string
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
constructor(args: { variant: any; parser: VCF; id: string }) {
|
|
39
|
+
this.variant = args.variant
|
|
40
|
+
this.parser = args.parser
|
|
41
|
+
this.data = this.dataFromVariant(this.variant)
|
|
42
|
+
this._id = args.id
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
get(field: string): any {
|
|
47
|
+
return field === 'samples'
|
|
48
|
+
? this.variant.SAMPLES
|
|
49
|
+
: this.data[field] || this.variant[field]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
set() {}
|
|
53
|
+
|
|
54
|
+
parent() {
|
|
55
|
+
return undefined
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
children() {
|
|
59
|
+
return undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
tags() {
|
|
63
|
+
return [...Object.keys(this.data), ...Object.keys(this.variant), 'samples']
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
id() {
|
|
67
|
+
return this._id
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
dataFromVariant(variant: {
|
|
71
|
+
REF: string
|
|
72
|
+
POS: number
|
|
73
|
+
ALT: string[]
|
|
74
|
+
CHROM: string
|
|
75
|
+
INFO: any // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
76
|
+
ID: string[]
|
|
77
|
+
}): FeatureData {
|
|
78
|
+
const { REF, ALT, POS, CHROM, INFO, ID } = variant
|
|
79
|
+
const start = POS - 1
|
|
80
|
+
const [type, description] = getSOTermAndDescription(REF, ALT, this.parser)
|
|
81
|
+
const isTRA = ALT?.some(f => f === '<TRA>')
|
|
82
|
+
const isSymbolic = ALT?.some(f => f.indexOf('<') !== -1)
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
refName: CHROM,
|
|
86
|
+
start,
|
|
87
|
+
end: isSymbolic && INFO.END && !isTRA ? +INFO.END[0] : start + REF.length,
|
|
88
|
+
description,
|
|
89
|
+
type,
|
|
90
|
+
name: ID?.join(','),
|
|
91
|
+
aliases: ID && ID.length > 1 ? variant.ID.slice(1) : undefined,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
+
toJSON(): any {
|
|
97
|
+
return {
|
|
98
|
+
uniqueId: this._id,
|
|
99
|
+
...this.variant,
|
|
100
|
+
...this.data,
|
|
101
|
+
samples: this.variant.SAMPLES,
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|