jbrowse-plugin-graphgenomeviewer 7.1.12 → 7.2.0
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/chunks/GbzBaseSyntenyAdapter-NB6WBBZH.js +2 -0
- package/dist/chunks/GbzBaseSyntenyAdapter-NB6WBBZH.js.map +7 -0
- package/dist/chunks/WalkTabixSyntenyAdapter-WBHOZLAN.js +2 -0
- package/dist/chunks/WalkTabixSyntenyAdapter-WBHOZLAN.js.map +7 -0
- package/dist/chunks/chunk-JLGPQO5L.js +4 -0
- package/dist/chunks/{chunk-IJJZC7A4.js.map → chunk-JLGPQO5L.js.map} +4 -4
- package/dist/chunks/{chunk-OBQFV4NL.js → chunk-LXCMWL7B.js} +2 -2
- package/dist/chunks/chunk-M2D7NUOY.js +2 -0
- package/dist/chunks/{chunk-T4HOC6O3.js.map → chunk-M2D7NUOY.js.map} +4 -4
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +3 -3
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +2 -2
- package/package.json +1 -1
- package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.test.ts +2 -4
- package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.ts +9 -8
- package/src/GraphGenomeView/pane/renderingActions.ts +5 -3
- package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +15 -0
- package/src/LinearGraphDisplay/configSchema.ts +5 -0
- package/src/RgfaTabixAdapter/test_data/walks3_lanepairs.GRCh38.walks.bed.gz +0 -0
- package/src/RgfaTabixAdapter/test_data/walks3_lanepairs.GRCh38.walks.bed.gz.tbi +0 -0
- package/src/WalkTabixSyntenyAdapter/WalkTabixSyntenyAdapter.test.ts +128 -3
- package/src/WalkTabixSyntenyAdapter/WalkTabixSyntenyAdapter.ts +4 -10
- package/src/WalkTabixSyntenyAdapter/walkLanes.ts +60 -0
- package/src/synteny/laneZoomNotice.test.ts +55 -0
- package/src/synteny/laneZoomNotice.ts +34 -0
- package/src/version.ts +1 -1
- package/dist/chunks/GbzBaseSyntenyAdapter-RYGR6L75.js +0 -2
- package/dist/chunks/GbzBaseSyntenyAdapter-RYGR6L75.js.map +0 -7
- package/dist/chunks/WalkTabixSyntenyAdapter-PQ4LGBPO.js +0 -2
- package/dist/chunks/WalkTabixSyntenyAdapter-PQ4LGBPO.js.map +0 -7
- package/dist/chunks/chunk-IJJZC7A4.js +0 -4
- package/dist/chunks/chunk-PJ43KEV6.js +0 -2
- package/dist/chunks/chunk-PJ43KEV6.js.map +0 -7
- package/dist/chunks/chunk-T4HOC6O3.js +0 -2
- /package/dist/chunks/{chunk-OBQFV4NL.js.map → chunk-LXCMWL7B.js.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jbrowse-plugin-graphgenomeviewer",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "JBrowse 2 graph genome (pangenome) view: rGFA reference-anchored layouts, the Bandage force-directed engine, and haplotype lanes read from a gbz-base database",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -366,15 +366,13 @@ test('the graph lists its haplotypes with their contigs, and a fetch can be narr
|
|
|
366
366
|
)
|
|
367
367
|
})
|
|
368
368
|
|
|
369
|
-
test('the node limit fails lanes
|
|
369
|
+
test('the node limit fails lanes as a zoom-in notice naming how far to zoom, and a graph cut naming a span that fits', async () => {
|
|
370
370
|
const adapter = makeAdapter({ nodeLimit: 2 })
|
|
371
371
|
const lanes: unknown = await feats(adapter, window).catch((e: unknown) => e)
|
|
372
372
|
expect(lanes).toMatchObject({
|
|
373
373
|
name: 'NodeLimitError',
|
|
374
374
|
regionTooLarge: true,
|
|
375
|
-
message: expect.stringMatching(
|
|
376
|
-
/^Zoom in to about [\d.]+[KM]?bp to see lanes$/,
|
|
377
|
-
),
|
|
375
|
+
message: expect.stringMatching(/^Zoom in about [\d.]+× to see lanes$/),
|
|
378
376
|
})
|
|
379
377
|
const graph: unknown = await adapter
|
|
380
378
|
.getSubgraph(window)
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
lanePairsStatus,
|
|
32
32
|
requestedPairs,
|
|
33
33
|
} from '../synteny/lanePairs.ts'
|
|
34
|
+
import { laneZoomNotice } from '../synteny/laneZoomNotice.ts'
|
|
34
35
|
import { matchFeature } from '../synteny/matchFeature.ts'
|
|
35
36
|
|
|
36
37
|
import type { GbzBaseSyntenyAdapterConfig } from './configSchema.ts'
|
|
@@ -223,6 +224,12 @@ function zoomInNotice(error: unknown, what: string) {
|
|
|
223
224
|
return error
|
|
224
225
|
}
|
|
225
226
|
|
|
227
|
+
const laneLimitNotice = (error: unknown, nodeLimit: number, windowBp: number) =>
|
|
228
|
+
laneZoomNotice(
|
|
229
|
+
zoomInNotice(nodeLimitError(error, nodeLimit, windowBp) ?? error, 'lanes'),
|
|
230
|
+
windowBp,
|
|
231
|
+
)
|
|
232
|
+
|
|
226
233
|
// gbz-base reads whole bp; a view asks at fractional ones
|
|
227
234
|
const wholeBp = (region: Region) => ({
|
|
228
235
|
...region,
|
|
@@ -489,10 +496,7 @@ export default class GbzBaseSyntenyAdapter extends ComparativeAdapterBase<GbzBas
|
|
|
489
496
|
keep,
|
|
490
497
|
})
|
|
491
498
|
.catch((error: unknown) => {
|
|
492
|
-
throw
|
|
493
|
-
nodeLimitError(error, nodeLimit, end - start) ?? error,
|
|
494
|
-
'lanes',
|
|
495
|
-
)
|
|
499
|
+
throw laneLimitNotice(error, nodeLimit, end - start)
|
|
496
500
|
}),
|
|
497
501
|
)
|
|
498
502
|
: []
|
|
@@ -562,10 +566,7 @@ export default class GbzBaseSyntenyAdapter extends ComparativeAdapterBase<GbzBas
|
|
|
562
566
|
// a cut past the node limit for the wider context keeps the first one
|
|
563
567
|
const bridged = async (path: PathQuery) => {
|
|
564
568
|
const subgraphs = await cut(path, baseContext).catch((error: unknown) => {
|
|
565
|
-
throw
|
|
566
|
-
nodeLimitError(error, nodeLimit, end - start) ?? error,
|
|
567
|
-
'lanes',
|
|
568
|
-
)
|
|
569
|
+
throw laneLimitNotice(error, nodeLimit, end - start)
|
|
569
570
|
})
|
|
570
571
|
const gap = widestWalkGap(subgraphs, kept)
|
|
571
572
|
const context = Math.ceil(gap / 2) + 2000
|
|
@@ -107,12 +107,14 @@ export const withRenderingActions = withLoadActions
|
|
|
107
107
|
{ fireImmediately: true },
|
|
108
108
|
),
|
|
109
109
|
)
|
|
110
|
-
// A host fits the rows
|
|
111
|
-
//
|
|
110
|
+
// A host fits the rows when it takes the pane over, which is before
|
|
111
|
+
// the legend measures the room it needs above them and before a split
|
|
112
|
+
// into panels changes how tall the drawing is
|
|
112
113
|
addDisposer(
|
|
113
114
|
self,
|
|
114
115
|
reaction(
|
|
115
|
-
() =>
|
|
116
|
+
() =>
|
|
117
|
+
`${self.fitPadTop} ${self.layoutBounds?.h} ${self.usableHeight}`,
|
|
116
118
|
() => {
|
|
117
119
|
if (self.viewportOwner === 'host') {
|
|
118
120
|
self.zoomToFit()
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fittedTranslateY } from '@jbrowse/bandage-core/pipeline'
|
|
1
2
|
import PluginManager from '@jbrowse/core/PluginManager'
|
|
2
3
|
import {
|
|
3
4
|
ConfigurationReference,
|
|
@@ -770,6 +771,20 @@ test('a tube map on its own axis ties each reference box to its bp in the linear
|
|
|
770
771
|
expect(pane.tubeMapConnectors).toEqual([])
|
|
771
772
|
})
|
|
772
773
|
|
|
774
|
+
test('a hosted drawing whose height changes after the host took the pane is placed again', async () => {
|
|
775
|
+
const { pane } = await shownGraph({ paths: true })
|
|
776
|
+
await pane.switchLayout('tubemapref')
|
|
777
|
+
await wait(SETTLE_MS)
|
|
778
|
+
const expected = fittedTranslateY(
|
|
779
|
+
pane.layoutBounds!,
|
|
780
|
+
pane.usableHeight,
|
|
781
|
+
pane.scaleY,
|
|
782
|
+
pane.fitPads.top,
|
|
783
|
+
)
|
|
784
|
+
expect(pane.viewportOwner).toBe('host')
|
|
785
|
+
expect(pane.translateY).toBeCloseTo(expected, 6)
|
|
786
|
+
})
|
|
787
|
+
|
|
773
788
|
test("a folded tube map draws the cut's reference as merged nodes, and the rest as ticks or routes", async () => {
|
|
774
789
|
const { pane } = await shownGraph({ paths: true })
|
|
775
790
|
const labels = () =>
|
|
@@ -38,6 +38,7 @@ export function configSchemaFactory() {
|
|
|
38
38
|
color: {
|
|
39
39
|
type: 'frozen',
|
|
40
40
|
defaultValue: {},
|
|
41
|
+
plot: true,
|
|
41
42
|
},
|
|
42
43
|
/**
|
|
43
44
|
* #slot
|
|
@@ -48,6 +49,7 @@ export function configSchemaFactory() {
|
|
|
48
49
|
size: {
|
|
49
50
|
type: 'frozen',
|
|
50
51
|
defaultValue: { field: 'depth', value: 6 },
|
|
52
|
+
plot: true,
|
|
51
53
|
},
|
|
52
54
|
/**
|
|
53
55
|
* #slot
|
|
@@ -61,6 +63,7 @@ export function configSchemaFactory() {
|
|
|
61
63
|
layers: {
|
|
62
64
|
type: 'frozen',
|
|
63
65
|
defaultValue: {},
|
|
66
|
+
plot: true,
|
|
64
67
|
},
|
|
65
68
|
/**
|
|
66
69
|
* #slot
|
|
@@ -71,6 +74,7 @@ export function configSchemaFactory() {
|
|
|
71
74
|
facet: {
|
|
72
75
|
type: 'frozen',
|
|
73
76
|
defaultValue: {},
|
|
77
|
+
plot: true,
|
|
74
78
|
},
|
|
75
79
|
/**
|
|
76
80
|
* #slot
|
|
@@ -79,6 +83,7 @@ export function configSchemaFactory() {
|
|
|
79
83
|
rows: {
|
|
80
84
|
type: 'frozen',
|
|
81
85
|
defaultValue: {},
|
|
86
|
+
plot: true,
|
|
82
87
|
},
|
|
83
88
|
/**
|
|
84
89
|
* #slot
|
|
@@ -9,10 +9,15 @@ import { toArray } from 'rxjs/operators'
|
|
|
9
9
|
import Adapter from './WalkTabixSyntenyAdapter.ts'
|
|
10
10
|
import configSchema from './configSchema.ts'
|
|
11
11
|
import WalkTabixSyntenyAdapterF from './index.ts'
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
bubblesAsMismatches,
|
|
14
|
+
referenceAligner,
|
|
15
|
+
walkAligner,
|
|
16
|
+
} from './walkLanes.ts'
|
|
13
17
|
import { walkRowsOf } from '../RgfaTabixAdapter/walkRowRuns.ts'
|
|
14
18
|
import { PairTargetError } from '../synteny/lanePairs.ts'
|
|
15
19
|
|
|
20
|
+
import type { PairChain } from '@gmod/gbz-base/pairAlignment'
|
|
16
21
|
import type { SyntenyMate } from '@jbrowse/synteny-core'
|
|
17
22
|
|
|
18
23
|
// Four walks over a 3.6 kb reference of six 600 bp nodes, in 1 kb chunks
|
|
@@ -166,6 +171,66 @@ test('a batch of lane pairs answers each pair what it answers alone', async () =
|
|
|
166
171
|
expect(batch).toHaveLength(2)
|
|
167
172
|
})
|
|
168
173
|
|
|
174
|
+
// walks3_lanepairs, a 5.5 kb reference of 2 kb flanks around three 500 bp
|
|
175
|
+
// nodes, in 1 kb chunks:
|
|
176
|
+
// W GRCh38 0 chr1 >1>2>3>4>5
|
|
177
|
+
// W HG002 1 chr1 >1>2>3>4>5
|
|
178
|
+
// W HG002 2 chr1 >1<4<3<2>5 the middle three inverted
|
|
179
|
+
// W HG00097 1 chr1 >1>2>6>2>6>2>3>4>5 2 three times, 6 a 30 bp spacer
|
|
180
|
+
test('a lane pair matches through a copy-number array, and draws an inversion between the lanes as a reverse-strand record', async () => {
|
|
181
|
+
const found = await firstValueFrom(
|
|
182
|
+
makeAdapter({}, 'walks3_lanepairs')
|
|
183
|
+
.getFeatures(
|
|
184
|
+
{ ...window, end: 5500 },
|
|
185
|
+
{
|
|
186
|
+
lanePairs: [
|
|
187
|
+
{ queryAssemblyName: 'HG002#1', targetAssemblyName: 'HG002#2' },
|
|
188
|
+
{ queryAssemblyName: 'HG002#1', targetAssemblyName: 'HG00097#1' },
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
)
|
|
192
|
+
.pipe(toArray()),
|
|
193
|
+
)
|
|
194
|
+
expect(
|
|
195
|
+
found.map(f => ({
|
|
196
|
+
...summary(f),
|
|
197
|
+
strand: f.get('strand'),
|
|
198
|
+
matches: f.get('numMatches'),
|
|
199
|
+
})),
|
|
200
|
+
).toEqual([
|
|
201
|
+
{
|
|
202
|
+
lane: 'HG002#2',
|
|
203
|
+
refName: 'chr1',
|
|
204
|
+
start: 0,
|
|
205
|
+
end: 5500,
|
|
206
|
+
mate: 'chr1:0-5500',
|
|
207
|
+
cigar: '2000=1500I1500D2000=',
|
|
208
|
+
strand: 1,
|
|
209
|
+
matches: 4000,
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
lane: 'HG002#2',
|
|
213
|
+
refName: 'chr1',
|
|
214
|
+
start: 2000,
|
|
215
|
+
end: 3500,
|
|
216
|
+
mate: 'chr1:2000-3500',
|
|
217
|
+
cigar: '1500=',
|
|
218
|
+
strand: -1,
|
|
219
|
+
matches: 1500,
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
lane: 'HG00097#1',
|
|
223
|
+
refName: 'chr1',
|
|
224
|
+
start: 0,
|
|
225
|
+
end: 5500,
|
|
226
|
+
mate: 'chr1:0-6560',
|
|
227
|
+
cigar: '2500=1060I3000=',
|
|
228
|
+
strand: 1,
|
|
229
|
+
matches: 5500,
|
|
230
|
+
},
|
|
231
|
+
])
|
|
232
|
+
})
|
|
233
|
+
|
|
169
234
|
test('a lane pair without its target lane is refused', async () => {
|
|
170
235
|
await expect(
|
|
171
236
|
feats(makeAdapter(), { queryAssemblyName: 'HG002#1' }),
|
|
@@ -228,12 +293,12 @@ test('getSubgraph cuts the window with the reference walk first', async () => {
|
|
|
228
293
|
expect(walks).toEqual(['GRCh38#0#chr1', 'HG002#1#chr1'])
|
|
229
294
|
})
|
|
230
295
|
|
|
231
|
-
test('a window past the step budget fails as a zoom-in notice for lanes', async () => {
|
|
296
|
+
test('a window past the step budget fails as a zoom-in notice for lanes naming how far to zoom', async () => {
|
|
232
297
|
await expect(
|
|
233
298
|
feats(makeAdapter({ walkStepBudget: 20 })),
|
|
234
299
|
).rejects.toMatchObject({
|
|
235
300
|
name: 'NodeLimitError',
|
|
236
|
-
message: expect.stringMatching(
|
|
301
|
+
message: expect.stringMatching(/^Zoom in about [\d.]+×.* to see lanes$/),
|
|
237
302
|
})
|
|
238
303
|
})
|
|
239
304
|
|
|
@@ -387,6 +452,66 @@ test('a haplotype running against the reference is a reverse-strand record', ()
|
|
|
387
452
|
expect(cigar(chain!.edits)).toBe('1000=30I500=')
|
|
388
453
|
})
|
|
389
454
|
|
|
455
|
+
// Two lanes over 2 kb flanks and three 500 bp nodes, the second lane running
|
|
456
|
+
// the middle three backwards: >1>2>3>4>5 against >1<4<3<2>5
|
|
457
|
+
const inversionNodes = new Map(
|
|
458
|
+
[1, 2, 3, 4, 5].map(id => [
|
|
459
|
+
id,
|
|
460
|
+
{
|
|
461
|
+
refName: 'ref',
|
|
462
|
+
start: id * 10_000,
|
|
463
|
+
end: id * 10_000 + (id === 1 || id === 5 ? 2000 : 500),
|
|
464
|
+
rank: 0,
|
|
465
|
+
onWindow: true,
|
|
466
|
+
},
|
|
467
|
+
]),
|
|
468
|
+
)
|
|
469
|
+
const upperLane = fragment('HG002#1#chr1', [
|
|
470
|
+
[1, 0],
|
|
471
|
+
[2, 0],
|
|
472
|
+
[3, 0],
|
|
473
|
+
[4, 0],
|
|
474
|
+
[5, 0],
|
|
475
|
+
])
|
|
476
|
+
const invertedLane = fragment('HG002#2#chr1', [
|
|
477
|
+
[1, 0],
|
|
478
|
+
[4, 1],
|
|
479
|
+
[3, 1],
|
|
480
|
+
[2, 1],
|
|
481
|
+
[5, 0],
|
|
482
|
+
])
|
|
483
|
+
const drawn = (chains: PairChain[]) =>
|
|
484
|
+
chains.map(
|
|
485
|
+
({ queryStart, queryEnd, targetStart, targetEnd, strand, edits }) => ({
|
|
486
|
+
query: `${queryStart}-${queryEnd}`,
|
|
487
|
+
target: `${targetStart}-${targetEnd}`,
|
|
488
|
+
strand,
|
|
489
|
+
cigar: cigar(edits),
|
|
490
|
+
}),
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
test('an inversion between two lanes is a reverse-strand record of its own when chained, and an insertion beside a deletion in the subsequence', () => {
|
|
494
|
+
expect(drawn(walkAligner(inversionNodes)(invertedLane, upperLane))).toEqual([
|
|
495
|
+
{
|
|
496
|
+
query: '0-5500',
|
|
497
|
+
target: '0-5500',
|
|
498
|
+
strand: '+',
|
|
499
|
+
cigar: '2000=1500I1500D2000=',
|
|
500
|
+
},
|
|
501
|
+
{ query: '2000-3500', target: '2000-3500', strand: '-', cigar: '1500=' },
|
|
502
|
+
])
|
|
503
|
+
expect(
|
|
504
|
+
drawn(referenceAligner(inversionNodes)(invertedLane, upperLane)),
|
|
505
|
+
).toEqual([
|
|
506
|
+
{
|
|
507
|
+
query: '0-5500',
|
|
508
|
+
target: '0-5500',
|
|
509
|
+
strand: '+',
|
|
510
|
+
cigar: '2000=1500I1500D2000=',
|
|
511
|
+
},
|
|
512
|
+
])
|
|
513
|
+
})
|
|
514
|
+
|
|
390
515
|
test.each([
|
|
391
516
|
['the whole reference', window],
|
|
392
517
|
['a window inside it', { ...window, start: 1300, end: 2300 }],
|
|
@@ -10,9 +10,8 @@ import { updateStatus } from '@jbrowse/core/util'
|
|
|
10
10
|
import { ObservableCreate } from '@jbrowse/core/util/rxjs'
|
|
11
11
|
import { walksKept } from '@jbrowse/graph-walks'
|
|
12
12
|
|
|
13
|
-
import { chainFeature,
|
|
13
|
+
import { chainFeature, lanePairAligner, referenceAligner } from './walkLanes.ts'
|
|
14
14
|
import { WalkIndex } from '../RgfaTabixAdapter/walkReader.ts'
|
|
15
|
-
import { isNodeLimitError } from '../nodeLimitError.ts'
|
|
16
15
|
import { PanSNRefNames, openTabixSlot } from '../panSNTabix.ts'
|
|
17
16
|
import { ComparativeAdapterBase } from '../synteny/ComparativeAdapterBase.ts'
|
|
18
17
|
import {
|
|
@@ -20,6 +19,7 @@ import {
|
|
|
20
19
|
lanePairsStatus,
|
|
21
20
|
requestedPairs,
|
|
22
21
|
} from '../synteny/lanePairs.ts'
|
|
22
|
+
import { laneZoomNotice } from '../synteny/laneZoomNotice.ts'
|
|
23
23
|
|
|
24
24
|
import type { WalkTabixSyntenyAdapterConfig } from './configSchema.ts'
|
|
25
25
|
import type { SubgraphAdapterOptions } from '../GetSubgraph.ts'
|
|
@@ -128,13 +128,7 @@ export default class WalkTabixSyntenyAdapter extends ComparativeAdapterBase<Walk
|
|
|
128
128
|
links: false,
|
|
129
129
|
})
|
|
130
130
|
.catch((error: unknown) => {
|
|
131
|
-
|
|
132
|
-
error.message = error.message.replace(
|
|
133
|
-
'to see the graph',
|
|
134
|
-
'to see lanes',
|
|
135
|
-
)
|
|
136
|
-
}
|
|
137
|
-
throw error
|
|
131
|
+
throw laneZoomNotice(error, region.end - region.start)
|
|
138
132
|
}),
|
|
139
133
|
)
|
|
140
134
|
}
|
|
@@ -228,7 +222,7 @@ export default class WalkTabixSyntenyAdapter extends ComparativeAdapterBase<Walk
|
|
|
228
222
|
opts,
|
|
229
223
|
lanePairsStatus(pairs),
|
|
230
224
|
)
|
|
231
|
-
const align =
|
|
225
|
+
const align = lanePairAligner(graph.nodes)
|
|
232
226
|
const walksOf = (prefix: string) =>
|
|
233
227
|
fragments.filter(f => panSNMatchesPrefix(f.name, prefix))
|
|
234
228
|
return sides.flatMap(({ pair, featurePrefix, matePrefix }) =>
|
|
@@ -156,6 +156,66 @@ export function referenceAligner(nodes: Map<number, WalkNode>) {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
// Each node a walk visits once, with the direction it passes it
|
|
160
|
+
function singleVisits(fragment: WalkFragment) {
|
|
161
|
+
const rev = new Map<number, number>()
|
|
162
|
+
const twice = new Set<number>()
|
|
163
|
+
fragment.ids.forEach((id, i) => {
|
|
164
|
+
if (rev.has(id)) {
|
|
165
|
+
twice.add(id)
|
|
166
|
+
} else {
|
|
167
|
+
rev.set(id, fragment.rev[i]!)
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
for (const id of twice) {
|
|
171
|
+
rev.delete(id)
|
|
172
|
+
}
|
|
173
|
+
return rev
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Aligns one lane's walk fragment to another's. The weighted subsequence
|
|
178
|
+
* (`referenceAligner`) is the fast route and matches through copy-number
|
|
179
|
+
* arrays, but it reads one direction per pair, so an inversion between the
|
|
180
|
+
* lanes comes out as an insertion beside a deletion. A pair sharing 100 bp
|
|
181
|
+
* (MIN_MATCH_BP) or more of singly visited nodes in each direction goes to
|
|
182
|
+
* pair chaining (`walkAligner`) instead, which answers the inverted stretch as
|
|
183
|
+
* a reverse-strand record of its own. Chaining leaves out every node a walk
|
|
184
|
+
* passes twice, so counting singly visited nodes misses no inversion it could
|
|
185
|
+
* draw.
|
|
186
|
+
*/
|
|
187
|
+
export function lanePairAligner(nodes: Map<number, WalkNode>) {
|
|
188
|
+
const subsequence = referenceAligner(nodes)
|
|
189
|
+
const chained = walkAligner(nodes)
|
|
190
|
+
const visits = new Map<WalkFragment, Map<number, number>>()
|
|
191
|
+
const visitsOf = (fragment: WalkFragment) => {
|
|
192
|
+
let found = visits.get(fragment)
|
|
193
|
+
if (found === undefined) {
|
|
194
|
+
found = singleVisits(fragment)
|
|
195
|
+
visits.set(fragment, found)
|
|
196
|
+
}
|
|
197
|
+
return found
|
|
198
|
+
}
|
|
199
|
+
const inverted = (query: WalkFragment, target: WalkFragment) => {
|
|
200
|
+
const theirs = visitsOf(target)
|
|
201
|
+
let same = 0
|
|
202
|
+
let opposite = 0
|
|
203
|
+
for (const [id, rev] of visitsOf(query)) {
|
|
204
|
+
const other = theirs.get(id)
|
|
205
|
+
if (other === rev) {
|
|
206
|
+
same += nodeLength(nodes, id)
|
|
207
|
+
} else if (other !== undefined) {
|
|
208
|
+
opposite += nodeLength(nodes, id)
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return same >= MIN_MATCH_BP && opposite >= MIN_MATCH_BP
|
|
212
|
+
}
|
|
213
|
+
return (query: WalkFragment, target: WalkFragment) =>
|
|
214
|
+
inverted(query, target)
|
|
215
|
+
? chained(query, target)
|
|
216
|
+
: subsequence(query, target)
|
|
217
|
+
}
|
|
218
|
+
|
|
159
219
|
/**
|
|
160
220
|
* One record of a walk aligned to another, with its short balanced bubbles as
|
|
161
221
|
* mismatches
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { keptStepsError } from '@jbrowse/graph-walks'
|
|
2
|
+
|
|
3
|
+
import { laneZoomFold, laneZoomNotice } from './laneZoomNotice.ts'
|
|
4
|
+
|
|
5
|
+
const BUDGET = 4_000_000
|
|
6
|
+
|
|
7
|
+
// A lane fetch over `fetchBp` keeping steps at a density whose fitting span
|
|
8
|
+
// is `fitsBp`, refused as @jbrowse/graph-walks refuses it
|
|
9
|
+
function refusal(fetchBp: number, fitsBp: number) {
|
|
10
|
+
const kept = Math.round((BUDGET * fetchBp) / fitsBp)
|
|
11
|
+
const fragment = { ids: new Int32Array(kept) }
|
|
12
|
+
return keptStepsError(
|
|
13
|
+
[fragment] as never,
|
|
14
|
+
BUDGET,
|
|
15
|
+
{ start: 0, end: fetchBp },
|
|
16
|
+
false,
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// On a 1,000 px canvas the display fetches the 800 px blocks the view touches:
|
|
21
|
+
// a 5 Mb view three 4 Mb blocks, a 500 kb view three 400 kb ones
|
|
22
|
+
test.each([
|
|
23
|
+
['5 Mb', 12_000_000, 7_290_000, '7.29Mbp', '1.7'],
|
|
24
|
+
['500 kb', 1_200_000, 762_000, '762Kbp', '1.6'],
|
|
25
|
+
])(
|
|
26
|
+
'a %s view over the step budget is told how far to zoom in, not a span wider than it',
|
|
27
|
+
(_, fetchBp, fitsBp, span, fold) => {
|
|
28
|
+
const error = refusal(fetchBp, fitsBp)!
|
|
29
|
+
expect(error.message).toBe(
|
|
30
|
+
`Zoom in to about ${span}, or choose fewer haplotypes, to see the graph`,
|
|
31
|
+
)
|
|
32
|
+
expect(laneZoomNotice(error, fetchBp)).toMatchObject({
|
|
33
|
+
name: 'NodeLimitError',
|
|
34
|
+
message: `Zoom in about ${fold}×, or choose fewer haplotypes, to see lanes`,
|
|
35
|
+
})
|
|
36
|
+
},
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
test('the fold rounds up, to a tenth below 10 and a whole number above, and asks for at least 1.1', () => {
|
|
40
|
+
expect(laneZoomFold(1_010, 1_000)).toBe(1.1)
|
|
41
|
+
expect(laneZoomFold(1_100, 1_000)).toBe(1.1)
|
|
42
|
+
expect(laneZoomFold(9_910, 1_000)).toBe(10)
|
|
43
|
+
expect(laneZoomFold(32_100, 1_000)).toBe(33)
|
|
44
|
+
expect(laneZoomFold(1_000, 1_200)).toBe(1.1)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('a refusal naming no span keeps its message', () => {
|
|
48
|
+
const error = Object.assign(new Error('Too many haplotype steps here'), {
|
|
49
|
+
name: 'NodeLimitError',
|
|
50
|
+
fitsBp: 1,
|
|
51
|
+
})
|
|
52
|
+
expect(laneZoomNotice(error, 1000)).toMatchObject({
|
|
53
|
+
message: 'Too many haplotype steps here',
|
|
54
|
+
})
|
|
55
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isNodeLimitError } from '../nodeLimitError.ts'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* How many times over the view must zoom in for a lane fetch of `windowBp`
|
|
5
|
+
* to fit, where `fitsBp` is the widest fetch that would: rounded up to a
|
|
6
|
+
* tenth, to a whole number past 10, and never under 1.1.
|
|
7
|
+
*/
|
|
8
|
+
export function laneZoomFold(windowBp: number, fitsBp: number) {
|
|
9
|
+
const fits = Math.max(1, fitsBp)
|
|
10
|
+
return windowBp >= 10 * fits
|
|
11
|
+
? Math.ceil(windowBp / fits)
|
|
12
|
+
: Math.max(11, Math.ceil((10 * windowBp) / fits)) / 10
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A budget refusal for lanes, naming how far to zoom rather than a span. The
|
|
17
|
+
* display fetches lanes over the 800 px static blocks its view touches, up to
|
|
18
|
+
* a block past each edge, and never tells the adapter the view, so a span that
|
|
19
|
+
* fits the fetch can be wider than the view. The fetch narrows with the view,
|
|
20
|
+
* so a fold holds for both.
|
|
21
|
+
*/
|
|
22
|
+
export function laneZoomNotice(error: unknown, windowBp: number) {
|
|
23
|
+
if (isNodeLimitError(error) && error instanceof Error) {
|
|
24
|
+
const { fitsBp } = error as { fitsBp?: unknown }
|
|
25
|
+
error.message = error.message.replace('to see the graph', 'to see lanes')
|
|
26
|
+
if (typeof fitsBp === 'number') {
|
|
27
|
+
error.message = error.message.replace(
|
|
28
|
+
/^Zoom in to about [\d.,]*\d[KM]?bp/,
|
|
29
|
+
`Zoom in about ${laneZoomFold(windowBp, fitsBp)}×`,
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return error
|
|
34
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '7.
|
|
1
|
+
export const version = '7.2.0'
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as ae,b as re,c as de,d as oe,e as ie,f as H,g as se}from"./chunk-IJJZC7A4.js";import{a as te}from"./chunk-KOB7YIMR.js";import{a as j,b as W,c as Z,d as u,e as M,f as $,g as U,h as k,i as z,k as X}from"./chunk-OBQFV4NL.js";import"./chunk-O7Y7LYN6.js";import{b as E,c as O}from"./chunk-N4WBX2OS.js";import"./chunk-BWP3XYKD.js";import"./chunk-T4HOC6O3.js";import{a as ne}from"./chunk-PFAHNHMM.js";import"./chunk-VDHDEEMF.js";import{a as V,c as L,m as ee}from"./chunk-EDSIYH4H.js";import"./chunk-YBLNN5FU.js";import"./chunk-MVVXRZXV.js";import{g as F,h as P,i as C}from"./chunk-GUXZESDR.js";import"./chunk-T4R3ZVEM.js";import{d as G,g as Y,h as J,i as K}from"./chunk-IKJZPPOA.js";import"./chunk-7WIBGKBU.js";import{a as N}from"./chunk-OGQ6OQDN.js";import"./chunk-NDRLCGPC.js";import{e as D,o as I}from"./chunk-TENPGIPX.js";function A(n){let i=/\.gbz\.db$/i;return i.test(n)?n.replace(i,".haplotype-index.db"):void 0}function he(n){return J(n)&&A(Y(n))?K(n,i=>A(i)):void 0}function ue(n){return n instanceof Error&&(/\bHTTP 40[34]\b/.test(n.message)||n.code==="ENOENT")}async function ce(n,i){let t=he(n);if(!t)return{};try{return await N(t,i).stat(),{location:t}}catch(e){return ue(e)?{}:{unreadable:String(e)}}}var ge=5e3,ye=50*2**20,q=class extends Error{constructor(t){super(`this GAF is ${(t/2**20).toFixed(0)} MB without an index; bgzip it and index it with tabix -p gaf`);this.name="UnindexedGafTooLargeError"}};function be(n,i){if(n.length<=i)return n;let t=n.length/i;return Array.from({length:i},(e,a)=>n[Math.floor(a*t)])}var pe=(n,i)=>n.path.some(t=>i.has(t.name)),v=class{constructor(i,t){this.file=i;this.tabix=t;this.whole=L({setup:async({signal:i})=>{let{size:t}=await this.file.stat();if(t>ye)throw new q(t);let e=await this.file.readFile({signal:i}),a=new TextDecoder().decode(e[0]===31&&e[1]===139?await V(e):e);return O(a)}})}async readIndexed(i,t,e){let a=1/0,r=-1/0;for(let s of t){let c=Number(s);Number.isInteger(c)&&(a=Math.min(a,c),r=Math.max(r,c))}let o=[];return a<=r&&await i.getLines("{node}",a,r+1,{signal:e,lineCallback:s=>{let c=E(s);c&&pe(c,t)&&o.push(c)}}),o}async readsOver(i,{signal:t}={}){let e=this.tabix?await this.readIndexed(this.tabix,i,t):(await this.whole({signal:t})).filter(a=>pe(a,i));return{records:be(e,ge),total:e.length}}};var B=class extends Error{constructor(t){super(t===void 0?"no haplotype index is set, so the walks cannot be named; build one with gbz-haplotype-index (cargo install gbz-haplotype-index) and set it as haplotypeIndexLocation":`the haplotype index beside the graph database could not be checked (${t}), so the walks cannot be named; if it is there, reload to try again, or set haplotypeIndexLocation`);this.name="NoHaplotypeIndexError"}},_=class extends Error{constructor(t,e){super(`the graph is cut on its reference, ${e}; a window on ${t} has no reference coordinates to cut at. Open the graph from a ${e} view, and find this haplotype's lane there`);this.name="HaplotypeWindowError"}};function we(n,i){return`${u(n)}#${n.contig}@${i.start.node}.${i.start.offset}`}function xe({alignment:n,assemblyName:i,refName:t,lane:e}){let{refStart:a,refEnd:r,strand:o,cigar:s}=n;if(!(r<=a)){let{name:c,hapStart:p,hapEnd:l}=n,d=we(c,n),g={uniqueId:d,assemblyName:i,refName:t,start:a,end:r,type:"match",strand:o==="-"?-1:1,CIGAR:s,syntenyId:d,mate:{refName:c.contig,start:p,end:l,assemblyName:e}};return new ae(g)}}function Se({pair:n,lane:i,mateLane:t}){return se({target:{name:`${u(n.target)}#${n.target.contig}`,assemblyName:i,refName:n.target.contig,start:n.targetStart,end:n.targetEnd},query:{name:`${u(n.query)}#${n.query.contig}`,assemblyName:t,refName:n.query.contig,start:n.queryStart,end:n.queryEnd},strand:n.strand,cigar:n.cigar,matches:n.matches,columns:n.columns})}var Pe=12e4;function Ne(n,i){let t=new Map;for(let a of n)for(let{name:r,start:o,end:s}of a.walkSpans()){let c=u(r);if(i.has(c)){let p=`${c}#${r.contig}`,l=t.get(p);l?l.push([o,s]):t.set(p,[[o,s]])}}let e=0;for(let a of t.values()){a.sort((r,o)=>r[0]-o[0]);for(let r=1;r<a.length;r++){let o=a[r][0]-a[r-1][1];o>0&&o<=Pe&&(e=Math.max(e,o))}}return e}function T(n,i){return n instanceof Z&&(n.message=`Zoom in to about ${D(n.fitsBp)} to see ${i}`),n}var le=n=>({...n,start:Math.floor(n.start),end:Math.ceil(n.end)}),Q=class extends re{constructor(){super(...arguments);this.graph=L({label:"Opening pangenome database",setup:async()=>{let t=this.getConf("gbzDbLocation"),e=this.getConf("haplotypeIndexLocation"),a=G(e)?{location:e}:await ce(t,this.pluginManager),r=a.location,o=await W.open({source:N(t,this.pluginManager),haplotypeIndex:r?N(r,this.pluginManager):void 0}),s=this.getConf("assemblyNames")[0];if(s===void 0)throw new Error("GbzBaseSyntenyAdapter needs assemblyNames: its first entry is the assembly the reference sample is loaded as");let c=await $(o),p=U({configured:this.getConf("referenceSample"),anchorPrefix:P(this,s),referenceSamples:c});return{db:o,anchor:s,referenceSample:p,referenceSamples:c,unreadableIndex:a.unreadable}}});this.gaf=L({label:"Opening reads",setup:async()=>{let t=this.getConf("readsLocation"),e=this.getConf(["readsIndex","location"]);return G(t)?new v(N(t,this.pluginManager),G(e)?ee(this,["readsLocation"],["readsIndex"]):void 0):void 0}})}async referenceQuery(t,e){let{db:a,referenceSample:r}=await this.graph(e);return k(a,r,t)}async getHaplotypes(t={}){let{db:e,referenceSamples:a}=await this.graph(t),r=new Map;for(let o of await e.paths()){let s=u(o.name),c=r.get(s);c?c.contigs.includes(o.name.contig)||c.contigs.push(o.name.contig):r.set(s,{prefix:s,sample:o.name.sample,haplotype:o.name.haplotype,contigs:[o.name.contig],isReference:a.includes(o.name.sample)})}return[...r.values()]}async getHeader(t={}){let{anchor:e,referenceSample:a}=await this.graph(t),r=C(this),o=[];for(let s of await this.getHaplotypes(t))s.sample!==a&&o.push({name:H(r,s.prefix),label:s.prefix,group:s.sample});return{hasCoarseTier:!1,anchorAssemblyName:e,lanes:o}}async getRefNames(t={}){let{db:e,anchor:a,referenceSample:r}=await this.graph(t),{assemblyName:o}=t,s=o===a?void 0:P(this,o),c=(await e.paths()).filter(p=>o===a?p.isIndexed&&p.name.sample===r:F(u(p.name),s)).map(p=>p.name.contig);return[...new Set(c)]}keepPredicate(t,e){let a=t===void 0||t.length===0?void 0:t.map(r=>P(this,r));return a===void 0&&e===void 0?void 0:r=>M(r,a)&&(e===void 0||F(u(r),e))}async getSubgraph(t,e={}){let{signal:a}=e,{db:r,anchor:o,referenceSample:s,unreadableIndex:c}=await this.graph({signal:a}),{assemblyName:p,refName:l,start:d,end:g}=le(t);if(p!==o)throw new _(p,o);let y=await this.referenceQuery(l,{signal:a});if(!y)throw new Error(`${s} has no indexed path ${l} in this graph`);let w=this.keepPredicate(e.haplotypes);if(w!==void 0&&!r.hasHaplotypeIndex)throw new B(c);let f=await X(r,y,d,g,{context:this.getConf("context"),snarls:e.snarls??this.getConf("subgraphSnarls"),limit:this.getConf("nodeLimit"),signal:e.signal,keep:w}).catch(x=>{throw T(x,"the graph")});return typeof f=="string"?f:ne(f,{start:d,end:g},e.walkRows)}async getReads(t,e={}){let a=await this.gaf(e);return a?a.readsOver(new Set(t),e):{records:[],total:0}}async laneHaplotypes(t,e){let a=P(this,t);return(await this.getHaplotypes(e)).filter(r=>F(r.prefix,a))}async anchorFeatures(t,e){let{db:a}=await this.graph(e),{assemblyName:r,refName:o,start:s,end:c}=t,p=P(this,e.targetAssemblyName),l=C(this),d=this.keepPredicate(e.haplotypes,p),g=await this.referenceQuery(o,e),y=this.getConf("nodeLimit");return(g?await I(`Reading graph ${o}:${s.toLocaleString()}-${c.toLocaleString()}`,e.statusCallback,()=>a.getAlignments({path:g,start:s,end:c,context:this.getConf("context"),haplotypes:"all",limit:y,signal:e.signal,keep:d}).catch(f=>{throw T(z(f,y,c-s)??f,"lanes")})):[]).flatMap(f=>{let x=f.resolved?xe({alignment:f,assemblyName:r,refName:o,lane:H(l,u(f.name))}):void 0;return x===void 0?[]:[x]})}async pairFeatures(t,e,a){let{db:r}=await this.graph(a),{refName:o,start:s,end:c}=t,l=(await Promise.all(e.map(async m=>({pair:m,featureSide:await this.laneHaplotypes(m.queryAssemblyName,a),mateSide:await this.laneHaplotypes(m.targetAssemblyName,a)})))).filter(({featureSide:m,mateSide:h})=>m.length>0&&h.length>0),d=new Set(l.flatMap(({featureSide:m,mateSide:h})=>[...m,...h].map(u))),g=await this.referenceQuery(o,a),y=this.getConf("nodeLimit"),w=this.getConf("context"),f=(m,h)=>r.getSubgraphs({path:m,start:s,end:c,context:h,snarls:this.getConf("subgraphSnarls"),haplotypes:"all",limit:y,signal:a.signal,keep:S=>d.has(u(S))}),x=async m=>{let h=await f(m,w).catch(b=>{throw T(z(b,y,c-s)??b,"lanes")}),S=Ne(h,d),R=Math.ceil(S/2)+2e3;return S>0&&R>w?f(m,R).catch(b=>{if(b instanceof j)return h;throw b}):h};return(g&&l.length>0?await I(ie(e),a.statusCallback,()=>x(g)):[]).flatMap(m=>l.flatMap(({pair:h,featureSide:S,mateSide:R})=>S.flatMap(b=>R.flatMap(me=>m.pairAlignments({target:b,query:me,bases:!1}).map(fe=>Se({pair:fe,lane:h.queryAssemblyName,mateLane:h.targetAssemblyName}))))))}getFeatures(t,e={}){let a=le(t);return te(async r=>{let{db:o,anchor:s,unreadableIndex:c}=await this.graph(e);if(!o.hasHaplotypeIndex)throw new B(c);if(a.assemblyName===s){let p=oe(e),l=p.length>0?await this.pairFeatures(a,p,e):await this.anchorFeatures(a,e);for(let d of l)r.next(d)}r.complete()},e.signal)}};export{B as NoHaplotypeIndexError,de as PairTargetError,Q as default,Ne as widestWalkGap};
|
|
2
|
-
//# sourceMappingURL=GbzBaseSyntenyAdapter-RYGR6L75.js.map
|