@jbrowse/plugin-variants 1.5.7 → 1.6.1
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/LinearVariantDisplay/model.d.ts +28 -5
- package/dist/VcfTabixAdapter/VcfTabixAdapter.d.ts +4 -13
- package/dist/plugin-variants.cjs.development.js +131 -166
- package/dist/plugin-variants.cjs.development.js.map +1 -1
- package/dist/plugin-variants.cjs.production.min.js +1 -1
- package/dist/plugin-variants.cjs.production.min.js.map +1 -1
- package/dist/plugin-variants.esm.js +132 -167
- package/dist/plugin-variants.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/VcfTabixAdapter/VcfTabixAdapter.ts +41 -82
- package/src/index.ts +12 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jbrowse/plugin-variants",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "JBrowse 2 variant adapters, tracks, etc.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jbrowse",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@flatten-js/interval-tree": "^1.0.15",
|
|
39
39
|
"@gmod/bgzf-filehandle": "^1.4.2",
|
|
40
40
|
"@gmod/tabix": "^1.5.2",
|
|
41
|
-
"@gmod/vcf": "^5.0.
|
|
41
|
+
"@gmod/vcf": "^5.0.5",
|
|
42
42
|
"@material-ui/icons": "^4.11.2",
|
|
43
43
|
"@mui/x-data-grid": "^4.0.1",
|
|
44
44
|
"generic-filehandle": "^2.2.2"
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "d6ad1b8e7fbb00000f2ac87f463c82e9db12ea01"
|
|
62
62
|
}
|
|
@@ -8,56 +8,59 @@ import {
|
|
|
8
8
|
Region,
|
|
9
9
|
} from '@jbrowse/core/util/types'
|
|
10
10
|
import { openLocation } from '@jbrowse/core/util/io'
|
|
11
|
+
import { bytesForRegions } from '@jbrowse/core/util'
|
|
11
12
|
import { ObservableCreate } from '@jbrowse/core/util/rxjs'
|
|
12
13
|
import { Feature } from '@jbrowse/core/util/simpleFeature'
|
|
13
14
|
import { TabixIndexedFile } from '@gmod/tabix'
|
|
14
|
-
import { GenericFilehandle } from 'generic-filehandle'
|
|
15
15
|
import VcfParser from '@gmod/vcf'
|
|
16
16
|
import { Observer } from 'rxjs'
|
|
17
17
|
import { readConfObject } from '@jbrowse/core/configuration'
|
|
18
18
|
import VcfFeature from './VcfFeature'
|
|
19
|
+
import { GenericFilehandle } from 'generic-filehandle'
|
|
19
20
|
|
|
20
21
|
export default class extends BaseFeatureDataAdapter {
|
|
21
|
-
|
|
22
|
+
private configured?: Promise<{
|
|
23
|
+
filehandle: GenericFilehandle
|
|
22
24
|
vcf: TabixIndexedFile
|
|
23
25
|
parser: VcfParser
|
|
24
|
-
filehandle: GenericFilehandle
|
|
25
26
|
}>
|
|
26
27
|
|
|
28
|
+
private async configurePre() {
|
|
29
|
+
const vcfGzLocation = readConfObject(this.config, 'vcfGzLocation')
|
|
30
|
+
const location = readConfObject(this.config, ['index', 'location'])
|
|
31
|
+
const indexType = readConfObject(this.config, ['index', 'indexType'])
|
|
32
|
+
|
|
33
|
+
const filehandle = openLocation(
|
|
34
|
+
vcfGzLocation as FileLocation,
|
|
35
|
+
this.pluginManager,
|
|
36
|
+
)
|
|
37
|
+
const isCSI = indexType === 'CSI'
|
|
38
|
+
const vcf = new TabixIndexedFile({
|
|
39
|
+
filehandle,
|
|
40
|
+
csiFilehandle: isCSI
|
|
41
|
+
? openLocation(location, this.pluginManager)
|
|
42
|
+
: undefined,
|
|
43
|
+
tbiFilehandle: !isCSI
|
|
44
|
+
? openLocation(location, this.pluginManager)
|
|
45
|
+
: undefined,
|
|
46
|
+
chunkCacheSize: 50 * 2 ** 20,
|
|
47
|
+
chunkSizeLimit: 1000000000,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const header = await vcf.getHeader()
|
|
51
|
+
return {
|
|
52
|
+
filehandle,
|
|
53
|
+
vcf,
|
|
54
|
+
parser: new VcfParser({ header }),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
27
58
|
protected async configure() {
|
|
28
59
|
if (!this.configured) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const filehandle = openLocation(
|
|
34
|
-
vcfGzLocation as FileLocation,
|
|
35
|
-
this.pluginManager,
|
|
36
|
-
)
|
|
37
|
-
const isCSI = indexType === 'CSI'
|
|
38
|
-
const vcf = new TabixIndexedFile({
|
|
39
|
-
filehandle,
|
|
40
|
-
csiFilehandle: isCSI
|
|
41
|
-
? openLocation(location, this.pluginManager)
|
|
42
|
-
: undefined,
|
|
43
|
-
tbiFilehandle: !isCSI
|
|
44
|
-
? openLocation(location, this.pluginManager)
|
|
45
|
-
: undefined,
|
|
46
|
-
chunkCacheSize: 50 * 2 ** 20,
|
|
47
|
-
chunkSizeLimit: 1000000000,
|
|
60
|
+
this.configured = this.configurePre().catch(e => {
|
|
61
|
+
this.configured = undefined
|
|
62
|
+
throw e
|
|
48
63
|
})
|
|
49
|
-
|
|
50
|
-
this.configured = vcf
|
|
51
|
-
.getHeader()
|
|
52
|
-
.then(header => ({
|
|
53
|
-
filehandle,
|
|
54
|
-
vcf,
|
|
55
|
-
parser: new VcfParser({ header }),
|
|
56
|
-
}))
|
|
57
|
-
.catch(e => {
|
|
58
|
-
this.configured = undefined
|
|
59
|
-
throw e
|
|
60
|
-
})
|
|
61
64
|
}
|
|
62
65
|
return this.configured
|
|
63
66
|
}
|
|
@@ -119,7 +122,10 @@ export default class extends BaseFeatureDataAdapter {
|
|
|
119
122
|
// xref: https://github.com/rollup/rollup/blob/master/CHANGELOG.md#bug-fixes-45
|
|
120
123
|
const superGetFeaturesInMultipleRegions = super.getFeaturesInMultipleRegions
|
|
121
124
|
return ObservableCreate<Feature>(async (observer: Observer<Feature>) => {
|
|
122
|
-
const
|
|
125
|
+
const { vcf } = await this.configure()
|
|
126
|
+
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
const bytes = await bytesForRegions(regions, vcf.index)
|
|
123
129
|
const { filehandle } = await this.configure()
|
|
124
130
|
const stat = await filehandle.stat()
|
|
125
131
|
let pct = Math.round((bytes / stat.size) * 100)
|
|
@@ -139,52 +145,5 @@ export default class extends BaseFeatureDataAdapter {
|
|
|
139
145
|
})
|
|
140
146
|
}
|
|
141
147
|
|
|
142
|
-
/**
|
|
143
|
-
* get the approximate number of bytes queried from the file for the given
|
|
144
|
-
* query regions
|
|
145
|
-
* @param regions - list of query regions
|
|
146
|
-
*/
|
|
147
|
-
private async bytesForRegions(regions: Region[]) {
|
|
148
|
-
const { vcf } = await this.configure()
|
|
149
|
-
const blockResults = await Promise.all(
|
|
150
|
-
regions.map(region =>
|
|
151
|
-
// @ts-ignore
|
|
152
|
-
vcf.index.blocksForRange(region.refName, region.start, region.end),
|
|
153
|
-
),
|
|
154
|
-
)
|
|
155
|
-
interface ByteRange {
|
|
156
|
-
start: number
|
|
157
|
-
end: number
|
|
158
|
-
}
|
|
159
|
-
interface VirtualOffset {
|
|
160
|
-
blockPosition: number
|
|
161
|
-
}
|
|
162
|
-
interface Block {
|
|
163
|
-
minv: VirtualOffset
|
|
164
|
-
maxv: VirtualOffset
|
|
165
|
-
}
|
|
166
|
-
const byteRanges: ByteRange[] = []
|
|
167
|
-
blockResults.forEach((blocks: Block[]) => {
|
|
168
|
-
blocks.forEach(block => {
|
|
169
|
-
const start = block.minv.blockPosition
|
|
170
|
-
const end = block.maxv.blockPosition + 64000
|
|
171
|
-
if (
|
|
172
|
-
!byteRanges.find(range => {
|
|
173
|
-
if (range.start <= end && range.end >= start) {
|
|
174
|
-
range.start = Math.min(range.start, start)
|
|
175
|
-
range.end = Math.max(range.end, end)
|
|
176
|
-
return true
|
|
177
|
-
}
|
|
178
|
-
return false
|
|
179
|
-
})
|
|
180
|
-
) {
|
|
181
|
-
byteRanges.push({ start, end })
|
|
182
|
-
}
|
|
183
|
-
})
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
return byteRanges.reduce((a, b) => a + b.end - b.start + 1, 0)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
148
|
public freeResources(/* { region } */): void {}
|
|
190
149
|
}
|
package/src/index.ts
CHANGED
|
@@ -57,15 +57,18 @@ export default class VariantsPlugin extends Plugin {
|
|
|
57
57
|
const adapterName = 'VcfTabixAdapter'
|
|
58
58
|
const fileName = getFileName(file)
|
|
59
59
|
const indexName = index && getFileName(index)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
const obj = {
|
|
61
|
+
type: adapterName,
|
|
62
|
+
vcfGzLocation: file,
|
|
63
|
+
index: {
|
|
64
|
+
location: index || makeIndex(file, '.tbi'),
|
|
65
|
+
indexType: makeIndexType(indexName, 'CSI', 'TBI'),
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
if (regexGuess.test(fileName) && !adapterHint) {
|
|
69
|
+
return obj
|
|
70
|
+
} else if (adapterHint === adapterName) {
|
|
71
|
+
return obj
|
|
69
72
|
}
|
|
70
73
|
return adapterGuesser(file, index, adapterHint)
|
|
71
74
|
}
|