jbrowse-plugin-tview 2.0.4
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/README.md +59 -0
- package/dist/AddHighlightModel/GenomeMouseoverHighlight.d.ts +6 -0
- package/dist/AddHighlightModel/GenomeMouseoverHighlight.js +23 -0
- package/dist/AddHighlightModel/GenomeMouseoverHighlight.js.map +1 -0
- package/dist/AddHighlightModel/Highlight.d.ts +10 -0
- package/dist/AddHighlightModel/Highlight.js +15 -0
- package/dist/AddHighlightModel/Highlight.js.map +1 -0
- package/dist/AddHighlightModel/HighlightComponents.d.ts +7 -0
- package/dist/AddHighlightModel/HighlightComponents.js +11 -0
- package/dist/AddHighlightModel/HighlightComponents.js.map +1 -0
- package/dist/AddHighlightModel/MsaToGenomeHighlight.d.ts +6 -0
- package/dist/AddHighlightModel/MsaToGenomeHighlight.js +15 -0
- package/dist/AddHighlightModel/MsaToGenomeHighlight.js.map +1 -0
- package/dist/AddHighlightModel/index.d.ts +2 -0
- package/dist/AddHighlightModel/index.js +19 -0
- package/dist/AddHighlightModel/index.js.map +1 -0
- package/dist/AddHighlightModel/util.d.ts +9 -0
- package/dist/AddHighlightModel/util.js +14 -0
- package/dist/AddHighlightModel/util.js.map +1 -0
- package/dist/LaunchTView/align.d.ts +20 -0
- package/dist/LaunchTView/align.js +121 -0
- package/dist/LaunchTView/align.js.map +1 -0
- package/dist/LaunchTView/components/LaunchTViewDialog.d.ts +6 -0
- package/dist/LaunchTView/components/LaunchTViewDialog.js +87 -0
- package/dist/LaunchTView/components/LaunchTViewDialog.js.map +1 -0
- package/dist/LaunchTView/fetchTviewPlan.d.ts +51 -0
- package/dist/LaunchTView/fetchTviewPlan.js +43 -0
- package/dist/LaunchTView/fetchTviewPlan.js.map +1 -0
- package/dist/LaunchTView/index.d.ts +2 -0
- package/dist/LaunchTView/index.js +41 -0
- package/dist/LaunchTView/index.js.map +1 -0
- package/dist/LaunchTView/limits.d.ts +2 -0
- package/dist/LaunchTView/limits.js +8 -0
- package/dist/LaunchTView/limits.js.map +1 -0
- package/dist/LaunchTView/tview.d.ts +95 -0
- package/dist/LaunchTView/tview.js +191 -0
- package/dist/LaunchTView/tview.js.map +1 -0
- package/dist/LaunchTView/useTviewMsa.d.ts +14 -0
- package/dist/LaunchTView/useTviewMsa.js +20 -0
- package/dist/LaunchTView/useTviewMsa.js.map +1 -0
- package/dist/TViewPanel/components/TViewPanel.d.ts +6 -0
- package/dist/TViewPanel/components/TViewPanel.js +11 -0
- package/dist/TViewPanel/components/TViewPanel.js.map +1 -0
- package/dist/TViewPanel/coords.d.ts +17 -0
- package/dist/TViewPanel/coords.js +36 -0
- package/dist/TViewPanel/coords.js.map +1 -0
- package/dist/TViewPanel/index.d.ts +2 -0
- package/dist/TViewPanel/index.js +15 -0
- package/dist/TViewPanel/index.js.map +1 -0
- package/dist/TViewPanel/model.d.ts +1028 -0
- package/dist/TViewPanel/model.js +246 -0
- package/dist/TViewPanel/model.js.map +1 -0
- package/dist/config.json +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/jbrowse-plugin-tview.umd.production.min.js +104 -0
- package/dist/jbrowse-plugin-tview.umd.production.min.js.map +7 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +76 -0
- package/src/AddHighlightModel/GenomeMouseoverHighlight.tsx +46 -0
- package/src/AddHighlightModel/Highlight.tsx +35 -0
- package/src/AddHighlightModel/HighlightComponents.tsx +25 -0
- package/src/AddHighlightModel/MsaToGenomeHighlight.tsx +31 -0
- package/src/AddHighlightModel/index.tsx +28 -0
- package/src/AddHighlightModel/util.ts +14 -0
- package/src/LaunchTView/align.ts +154 -0
- package/src/LaunchTView/components/LaunchTViewDialog.tsx +129 -0
- package/src/LaunchTView/fetchTviewPlan.ts +95 -0
- package/src/LaunchTView/index.ts +53 -0
- package/src/LaunchTView/limits.ts +8 -0
- package/src/LaunchTView/tview.ts +272 -0
- package/src/LaunchTView/useTviewMsa.ts +36 -0
- package/src/TViewPanel/components/TViewPanel.tsx +20 -0
- package/src/TViewPanel/coords.ts +43 -0
- package/src/TViewPanel/index.ts +20 -0
- package/src/TViewPanel/model.ts +289 -0
- package/src/index.ts +21 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "2.0.4";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0.4",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"name": "jbrowse-plugin-tview",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/cmdcolin/jbrowse-plugin-tview.git"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"jbrowse",
|
|
11
|
+
"jbrowse2"
|
|
12
|
+
],
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"typings": "dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "rimraf dist",
|
|
21
|
+
"dev": "pnpm start",
|
|
22
|
+
"start": "node esbuild.mjs --watch",
|
|
23
|
+
"format": "pnpm prettier --write .",
|
|
24
|
+
"prebuild": "pnpm clean",
|
|
25
|
+
"build": "tsc && NODE_ENV=production node esbuild.mjs && cp distconfig.json dist/config.json",
|
|
26
|
+
"lint": "eslint --report-unused-disable-directives --max-warnings 0",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest",
|
|
29
|
+
"pretest:e2e": "test -d .test-jbrowse || pnpm dlx @jbrowse/cli create .test-jbrowse --nightly",
|
|
30
|
+
"test:e2e": "vitest run --config vitest.config.e2e.ts",
|
|
31
|
+
"prefigure": "pnpm pretest:e2e",
|
|
32
|
+
"figure": "node scripts/figure.mjs",
|
|
33
|
+
"prepack": "pnpm build",
|
|
34
|
+
"preversion": "pnpm lint && pnpm build",
|
|
35
|
+
"version": "node scripts/version.mjs",
|
|
36
|
+
"postversion": "git push --follow-tags"
|
|
37
|
+
},
|
|
38
|
+
"jbrowse-plugin": {
|
|
39
|
+
"name": "TView"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"react-msaview": "^5.6.1",
|
|
43
|
+
"swr": "^2.4.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@emotion/react": "^11.14.0",
|
|
47
|
+
"@eslint/js": "^10.0.1",
|
|
48
|
+
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
|
|
49
|
+
"@gmod/bam": "^7.3.4",
|
|
50
|
+
"@jbrowse/core": "^4.3.0",
|
|
51
|
+
"@jbrowse/mobx-state-tree": "^5.13.0",
|
|
52
|
+
"@jbrowse/plugin-linear-genome-view": "^4.3.0",
|
|
53
|
+
"@mui/icons-material": "^9.2.0",
|
|
54
|
+
"@mui/material": "^9.2.0",
|
|
55
|
+
"@mui/system": "^9.2.0",
|
|
56
|
+
"@types/node": "^26.1.1",
|
|
57
|
+
"@types/react": "^19.2.17",
|
|
58
|
+
"esbuild": "^0.28.1",
|
|
59
|
+
"eslint": "^10.7.0",
|
|
60
|
+
"eslint-plugin-import-x": "^4.17.1",
|
|
61
|
+
"eslint-plugin-react": "^7.37.5",
|
|
62
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
63
|
+
"mobx": "^6.16.1",
|
|
64
|
+
"mobx-react": "^9.2.2",
|
|
65
|
+
"prettier": "^3.9.6",
|
|
66
|
+
"pretty-bytes": "^7.1.1",
|
|
67
|
+
"puppeteer": "^25.3.0",
|
|
68
|
+
"react": "^19.2.8",
|
|
69
|
+
"react-dom": "^19.2.8",
|
|
70
|
+
"rimraf": "^6.1.3",
|
|
71
|
+
"tss-react": "^4.9.21",
|
|
72
|
+
"typescript": "^6.0.2",
|
|
73
|
+
"typescript-eslint": "^8.65.0",
|
|
74
|
+
"vitest": "^4.1.10"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { getSession } from '@jbrowse/core/util'
|
|
4
|
+
import { observer } from 'mobx-react'
|
|
5
|
+
|
|
6
|
+
import Highlight from './Highlight'
|
|
7
|
+
|
|
8
|
+
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
|
|
9
|
+
|
|
10
|
+
interface HoverPosition {
|
|
11
|
+
coord: number
|
|
12
|
+
refName: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getHoverPosition(hovered: unknown): HoverPosition | undefined {
|
|
16
|
+
const pos =
|
|
17
|
+
!!hovered && typeof hovered === 'object' && 'hoverPosition' in hovered
|
|
18
|
+
? hovered.hoverPosition
|
|
19
|
+
: undefined
|
|
20
|
+
return !!pos &&
|
|
21
|
+
typeof pos === 'object' &&
|
|
22
|
+
'coord' in pos &&
|
|
23
|
+
typeof pos.coord === 'number' &&
|
|
24
|
+
'refName' in pos &&
|
|
25
|
+
typeof pos.refName === 'string'
|
|
26
|
+
? { coord: pos.coord, refName: pos.refName }
|
|
27
|
+
: undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const GenomeMouseoverHighlight = observer(function GenomeMouseoverHighlight2({
|
|
31
|
+
model,
|
|
32
|
+
}: {
|
|
33
|
+
model: LinearGenomeViewModel
|
|
34
|
+
}) {
|
|
35
|
+
const hoverPosition = getHoverPosition(getSession(model).hovered)
|
|
36
|
+
return hoverPosition ? (
|
|
37
|
+
<Highlight
|
|
38
|
+
model={model}
|
|
39
|
+
refName={hoverPosition.refName}
|
|
40
|
+
start={hoverPosition.coord - 1}
|
|
41
|
+
end={hoverPosition.coord}
|
|
42
|
+
/>
|
|
43
|
+
) : null
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
export default GenomeMouseoverHighlight
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { observer } from 'mobx-react'
|
|
4
|
+
|
|
5
|
+
import { useStyles } from './util'
|
|
6
|
+
|
|
7
|
+
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
|
|
8
|
+
|
|
9
|
+
/** a band over one genome interval, positioned in the tracks container */
|
|
10
|
+
const Highlight = observer(function Highlight2({
|
|
11
|
+
model,
|
|
12
|
+
refName,
|
|
13
|
+
start,
|
|
14
|
+
end,
|
|
15
|
+
}: {
|
|
16
|
+
model: LinearGenomeViewModel
|
|
17
|
+
refName: string
|
|
18
|
+
start: number
|
|
19
|
+
end: number
|
|
20
|
+
}) {
|
|
21
|
+
const { classes } = useStyles()
|
|
22
|
+
const s = model.bpToPx({ refName, coord: start })
|
|
23
|
+
const e = model.bpToPx({ refName, coord: end })
|
|
24
|
+
return s && e ? (
|
|
25
|
+
<div
|
|
26
|
+
className={classes.highlight}
|
|
27
|
+
style={{
|
|
28
|
+
left: Math.min(s.offsetPx, e.offsetPx) - model.offsetPx,
|
|
29
|
+
width: Math.max(Math.abs(e.offsetPx - s.offsetPx), 4),
|
|
30
|
+
}}
|
|
31
|
+
/>
|
|
32
|
+
) : null
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
export default Highlight
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { observer } from 'mobx-react'
|
|
4
|
+
|
|
5
|
+
import GenomeMouseoverHighlight from './GenomeMouseoverHighlight'
|
|
6
|
+
import MsaToGenomeHighlight from './MsaToGenomeHighlight'
|
|
7
|
+
|
|
8
|
+
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
|
|
9
|
+
|
|
10
|
+
type LGV = LinearGenomeViewModel
|
|
11
|
+
|
|
12
|
+
const HighlightComponents = observer(function HighlightComponents2({
|
|
13
|
+
model,
|
|
14
|
+
}: {
|
|
15
|
+
model: LGV
|
|
16
|
+
}) {
|
|
17
|
+
return (
|
|
18
|
+
<>
|
|
19
|
+
<MsaToGenomeHighlight model={model} />
|
|
20
|
+
<GenomeMouseoverHighlight model={model} />
|
|
21
|
+
</>
|
|
22
|
+
)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
export default HighlightComponents
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { getSession } from '@jbrowse/core/util'
|
|
4
|
+
import { observer } from 'mobx-react'
|
|
5
|
+
|
|
6
|
+
import Highlight from './Highlight'
|
|
7
|
+
import { isTView } from '../TViewPanel/model'
|
|
8
|
+
|
|
9
|
+
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
|
|
10
|
+
|
|
11
|
+
const MsaToGenomeHighlight = observer(function MsaToGenomeHighlight2({
|
|
12
|
+
model,
|
|
13
|
+
}: {
|
|
14
|
+
model: LinearGenomeViewModel
|
|
15
|
+
}) {
|
|
16
|
+
const { views } = getSession(model)
|
|
17
|
+
const highlights = views
|
|
18
|
+
.filter(isTView)
|
|
19
|
+
.filter(v => v.connectedViewId === model.id)
|
|
20
|
+
.flatMap(v => v.connectedHighlights)
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
{highlights.map(r => (
|
|
25
|
+
<Highlight key={`${r.refName}:${r.start}`} model={model} {...r} />
|
|
26
|
+
))}
|
|
27
|
+
</>
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
export default MsaToGenomeHighlight
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { getSession } from '@jbrowse/core/util'
|
|
4
|
+
|
|
5
|
+
import HighlightComponents from './HighlightComponents'
|
|
6
|
+
import { isTView } from '../TViewPanel/model'
|
|
7
|
+
|
|
8
|
+
import type PluginManager from '@jbrowse/core/PluginManager'
|
|
9
|
+
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
|
|
10
|
+
|
|
11
|
+
export default function AddHighlightComponentsModelF(
|
|
12
|
+
pluginManager: PluginManager,
|
|
13
|
+
) {
|
|
14
|
+
pluginManager.addToExtensionPoint(
|
|
15
|
+
'LinearGenomeView-TracksContainerComponent',
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
(rest: React.ReactNode[], { model }: { model: LinearGenomeViewModel }) => {
|
|
18
|
+
// skip entirely unless a TView is connected to this genome view
|
|
19
|
+
const { views } = getSession(model)
|
|
20
|
+
return views.some(v => isTView(v) && v.connectedViewId === model.id)
|
|
21
|
+
? [
|
|
22
|
+
...rest,
|
|
23
|
+
<HighlightComponents key="tview_highlights" model={model} />,
|
|
24
|
+
]
|
|
25
|
+
: rest
|
|
26
|
+
},
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { makeStyles } from 'tss-react/mui'
|
|
2
|
+
|
|
3
|
+
export const useStyles = makeStyles()({
|
|
4
|
+
highlight: {
|
|
5
|
+
height: '100%',
|
|
6
|
+
background: 'rgba(255,255,0,0.2)',
|
|
7
|
+
border: '1px solid rgba(50,50,0,0.2)',
|
|
8
|
+
position: 'absolute',
|
|
9
|
+
zIndex: 99,
|
|
10
|
+
textAlign: 'center',
|
|
11
|
+
pointerEvents: 'none',
|
|
12
|
+
overflow: 'hidden',
|
|
13
|
+
},
|
|
14
|
+
})
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads carrying the same insertion event usually differ slightly inside it
|
|
3
|
+
* (sequencing error, or a real indel within the inserted allele). Laying each
|
|
4
|
+
* one out left-justified puts those differences in different columns and the
|
|
5
|
+
* shared event stops being readable. Aligning the inserted sequences against
|
|
6
|
+
* each other fixes that.
|
|
7
|
+
*
|
|
8
|
+
* This is deliberately local to one reference position: the insertion still
|
|
9
|
+
* occupies "as many columns as the widest gapped sequence", which is the only
|
|
10
|
+
* thing buildColumnToRefPos knows about, so the column <-> reference mapping is
|
|
11
|
+
* untouched.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const MATCH = 2
|
|
15
|
+
const MISMATCH = -2
|
|
16
|
+
const GAP = -3
|
|
17
|
+
|
|
18
|
+
// each sequence costs an O(n*m) pairwise alignment against the center, so fall
|
|
19
|
+
// back to left-justified layout rather than stall on a pathological site
|
|
20
|
+
const MAX_LEN = 200
|
|
21
|
+
const MAX_DISTINCT = 30
|
|
22
|
+
|
|
23
|
+
function subst(a: string | undefined, b: string | undefined) {
|
|
24
|
+
return a === b ? MATCH : MISMATCH
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** global alignment, returns both sequences with '-' inserted */
|
|
28
|
+
function needlemanWunsch(a: string, b: string) {
|
|
29
|
+
const n = a.length
|
|
30
|
+
const m = b.length
|
|
31
|
+
const stride = m + 1
|
|
32
|
+
const score = new Int32Array((n + 1) * stride)
|
|
33
|
+
for (let i = 1; i <= n; i++) {
|
|
34
|
+
score[i * stride] = i * GAP
|
|
35
|
+
}
|
|
36
|
+
for (let j = 1; j <= m; j++) {
|
|
37
|
+
score[j] = j * GAP
|
|
38
|
+
}
|
|
39
|
+
for (let i = 1; i <= n; i++) {
|
|
40
|
+
for (let j = 1; j <= m; j++) {
|
|
41
|
+
score[i * stride + j] = Math.max(
|
|
42
|
+
score[(i - 1) * stride + j - 1]! + subst(a[i - 1], b[j - 1]),
|
|
43
|
+
score[(i - 1) * stride + j]! + GAP,
|
|
44
|
+
score[i * stride + j - 1]! + GAP,
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const outA: string[] = []
|
|
50
|
+
const outB: string[] = []
|
|
51
|
+
let i = n
|
|
52
|
+
let j = m
|
|
53
|
+
while (i > 0 || j > 0) {
|
|
54
|
+
const cur = score[i * stride + j]!
|
|
55
|
+
const diagonal =
|
|
56
|
+
i > 0 &&
|
|
57
|
+
j > 0 &&
|
|
58
|
+
cur === score[(i - 1) * stride + j - 1]! + subst(a[i - 1], b[j - 1])
|
|
59
|
+
if (diagonal) {
|
|
60
|
+
outA.push(a[i - 1]!)
|
|
61
|
+
outB.push(b[j - 1]!)
|
|
62
|
+
i--
|
|
63
|
+
j--
|
|
64
|
+
} else if (i > 0 && cur === score[(i - 1) * stride + j]! + GAP) {
|
|
65
|
+
outA.push(a[i - 1]!)
|
|
66
|
+
outB.push('-')
|
|
67
|
+
i--
|
|
68
|
+
} else {
|
|
69
|
+
outA.push('-')
|
|
70
|
+
outB.push(b[j - 1]!)
|
|
71
|
+
j--
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
center: outA.reverse().join(''),
|
|
76
|
+
other: outB.reverse().join(''),
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A pairwise alignment against the center, re-expressed in center coordinates:
|
|
82
|
+
* what the other sequence contributes at each center position, and what it
|
|
83
|
+
* inserts in the gap slot before it. Slot `centerLen` is the trailing overhang.
|
|
84
|
+
*/
|
|
85
|
+
interface CenterSplit {
|
|
86
|
+
slots: string[]
|
|
87
|
+
/** one char per center position, '-' where the other sequence has nothing */
|
|
88
|
+
atCenter: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function splitAgainstCenter(
|
|
92
|
+
{ center, other }: { center: string; other: string },
|
|
93
|
+
centerLen: number,
|
|
94
|
+
): CenterSplit {
|
|
95
|
+
const slots = Array.from({ length: centerLen + 1 }, () => '')
|
|
96
|
+
let atCenter = ''
|
|
97
|
+
for (let k = 0; k < center.length; k++) {
|
|
98
|
+
if (center[k] === '-') {
|
|
99
|
+
slots[atCenter.length] = slots[atCenter.length]! + other[k]!
|
|
100
|
+
} else {
|
|
101
|
+
atCenter += other[k]!
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { slots, atCenter }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function emit({ slots, atCenter }: CenterSplit, slotWidths: number[]) {
|
|
108
|
+
let ret = ''
|
|
109
|
+
for (let j = 0; j < atCenter.length; j++) {
|
|
110
|
+
const slot = slots[j]!
|
|
111
|
+
ret += slot + '-'.repeat(slotWidths[j]! - slot.length) + atCenter[j]
|
|
112
|
+
}
|
|
113
|
+
const last = slots[atCenter.length]!
|
|
114
|
+
return ret + last + '-'.repeat(slotWidths[atCenter.length]! - last.length)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Center-star multiple alignment of the sequences inserted at one reference
|
|
119
|
+
* position. Returns each distinct input mapped to a gapped version, all of the
|
|
120
|
+
* same length. Returns an empty map when there is nothing to gain (a single
|
|
121
|
+
* distinct sequence) or when the site is too large to be worth aligning; the
|
|
122
|
+
* caller then keeps the sequences as-is and left-justifies them.
|
|
123
|
+
*/
|
|
124
|
+
export function alignInsertions(seqs: string[]) {
|
|
125
|
+
const distinct = [...new Set(seqs)]
|
|
126
|
+
const longest = distinct.reduce((a, b) => (b.length > a.length ? b : a), '')
|
|
127
|
+
if (
|
|
128
|
+
distinct.length < 2 ||
|
|
129
|
+
distinct.length > MAX_DISTINCT ||
|
|
130
|
+
longest.length > MAX_LEN
|
|
131
|
+
) {
|
|
132
|
+
return new Map<string, string>()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const centerLen = longest.length
|
|
136
|
+
const others = distinct.filter(s => s !== longest)
|
|
137
|
+
const splits = others.map(s =>
|
|
138
|
+
splitAgainstCenter(needlemanWunsch(longest, s), centerLen),
|
|
139
|
+
)
|
|
140
|
+
const centerSplit: CenterSplit = {
|
|
141
|
+
slots: Array.from({ length: centerLen + 1 }, () => ''),
|
|
142
|
+
atCenter: longest,
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const slotWidths = Array.from({ length: centerLen + 1 }, (_, j) =>
|
|
146
|
+
splits.reduce((max, s) => Math.max(max, s.slots[j]!.length), 0),
|
|
147
|
+
)
|
|
148
|
+
return new Map([
|
|
149
|
+
[longest, emit(centerSplit, slotWidths)],
|
|
150
|
+
...others.map(
|
|
151
|
+
(seq, i): [string, string] => [seq, emit(splits[i]!, slotWidths)],
|
|
152
|
+
),
|
|
153
|
+
])
|
|
154
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { getConf } from '@jbrowse/core/configuration'
|
|
4
|
+
import { Dialog, ErrorMessage } from '@jbrowse/core/ui'
|
|
5
|
+
import {
|
|
6
|
+
assembleLocString,
|
|
7
|
+
getContainingView,
|
|
8
|
+
getSession,
|
|
9
|
+
} from '@jbrowse/core/util'
|
|
10
|
+
import { Button, DialogActions, DialogContent } from '@mui/material'
|
|
11
|
+
|
|
12
|
+
import { MAX_BP, MAX_CELLS } from '../limits'
|
|
13
|
+
import { renderTviewMsa } from '../tview'
|
|
14
|
+
import { useTviewMsa } from '../useTviewMsa'
|
|
15
|
+
|
|
16
|
+
import type { AbstractTrackModel } from '@jbrowse/core/util'
|
|
17
|
+
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
|
|
18
|
+
|
|
19
|
+
export default function LaunchTViewDialog({
|
|
20
|
+
handleClose,
|
|
21
|
+
model,
|
|
22
|
+
}: {
|
|
23
|
+
handleClose: () => void
|
|
24
|
+
model: AbstractTrackModel
|
|
25
|
+
}) {
|
|
26
|
+
const view = getContainingView(model) as LinearGenomeViewModel
|
|
27
|
+
const session = getSession(model)
|
|
28
|
+
const block = view.dynamicBlocks.contentBlocks[0]
|
|
29
|
+
// assemblyName is required: the RPC uses it to map the view's refName onto
|
|
30
|
+
// whatever the file calls that sequence (refNameAliases)
|
|
31
|
+
const region = block
|
|
32
|
+
? {
|
|
33
|
+
assemblyName: block.assemblyName,
|
|
34
|
+
refName: block.refName,
|
|
35
|
+
start: Math.floor(block.start),
|
|
36
|
+
end: Math.ceil(block.end),
|
|
37
|
+
}
|
|
38
|
+
: undefined
|
|
39
|
+
const width = region ? region.end - region.start : 0
|
|
40
|
+
const tooWide = width > MAX_BP
|
|
41
|
+
|
|
42
|
+
const { data, error, isLoading } = useTviewMsa({
|
|
43
|
+
model,
|
|
44
|
+
region: tooWide ? undefined : region,
|
|
45
|
+
})
|
|
46
|
+
const displayName = region ? assembleLocString(region) : 'Unknown'
|
|
47
|
+
const tooLarge = !!data && data.plan.cellCount > MAX_CELLS
|
|
48
|
+
// lets the view rebuild itself after a session reload
|
|
49
|
+
const msaSource = region
|
|
50
|
+
? { trackId: getConf(model, 'trackId'), assemblyName: region.assemblyName }
|
|
51
|
+
: undefined
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<Dialog
|
|
55
|
+
maxWidth="xl"
|
|
56
|
+
title="Launch tview"
|
|
57
|
+
onClose={() => {
|
|
58
|
+
handleClose()
|
|
59
|
+
}}
|
|
60
|
+
open
|
|
61
|
+
>
|
|
62
|
+
<DialogContent>
|
|
63
|
+
<div>
|
|
64
|
+
Create a view similar to "samtools tview" for the reads in the current
|
|
65
|
+
region: {displayName}
|
|
66
|
+
</div>
|
|
67
|
+
{tooWide ? (
|
|
68
|
+
<div>
|
|
69
|
+
Region is {width.toLocaleString('en-US')}bp, wider than the{' '}
|
|
70
|
+
{MAX_BP.toLocaleString('en-US')}bp limit. Zoom in and try again.
|
|
71
|
+
</div>
|
|
72
|
+
) : error ? (
|
|
73
|
+
<ErrorMessage error={error} />
|
|
74
|
+
) : isLoading ? (
|
|
75
|
+
<div>Loading...</div>
|
|
76
|
+
) : tooLarge ? (
|
|
77
|
+
<div>
|
|
78
|
+
{data.rowCount.toLocaleString('en-US')} reads over{' '}
|
|
79
|
+
{data.plan.layout.totalColumns.toLocaleString('en-US')} columns is{' '}
|
|
80
|
+
{data.plan.cellCount.toLocaleString('en-US')} cells, above the{' '}
|
|
81
|
+
{MAX_CELLS.toLocaleString('en-US')} limit. Zoom in and try again.
|
|
82
|
+
</div>
|
|
83
|
+
) : data ? (
|
|
84
|
+
<div>{data.rowCount} reads with sequence data found</div>
|
|
85
|
+
) : (
|
|
86
|
+
<div>No region is currently visible.</div>
|
|
87
|
+
)}
|
|
88
|
+
</DialogContent>
|
|
89
|
+
<DialogActions>
|
|
90
|
+
<Button
|
|
91
|
+
variant="contained"
|
|
92
|
+
color="primary"
|
|
93
|
+
disabled={!data?.rowCount || tooLarge}
|
|
94
|
+
onClick={() => {
|
|
95
|
+
if (data && !tooLarge) {
|
|
96
|
+
session.addView('TView', {
|
|
97
|
+
type: 'TView',
|
|
98
|
+
displayName,
|
|
99
|
+
colWidth: 10,
|
|
100
|
+
rowHeight: 12,
|
|
101
|
+
labelsAlignRight: true,
|
|
102
|
+
colorSchemeName: 'jbrowse_dna',
|
|
103
|
+
connectedViewId: view.id,
|
|
104
|
+
msaRegion: data.plan.region,
|
|
105
|
+
insertionWidths: data.plan.insertionWidths,
|
|
106
|
+
msaSource,
|
|
107
|
+
data: {
|
|
108
|
+
msa: renderTviewMsa(data.plan),
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
handleClose()
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
Submit
|
|
116
|
+
</Button>
|
|
117
|
+
<Button
|
|
118
|
+
variant="contained"
|
|
119
|
+
color="secondary"
|
|
120
|
+
onClick={() => {
|
|
121
|
+
handleClose()
|
|
122
|
+
}}
|
|
123
|
+
>
|
|
124
|
+
Cancel
|
|
125
|
+
</Button>
|
|
126
|
+
</DialogActions>
|
|
127
|
+
</Dialog>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { getConf, readConfObject } from '@jbrowse/core/configuration'
|
|
2
|
+
import { getRpcSessionId } from '@jbrowse/core/util/tracks'
|
|
3
|
+
|
|
4
|
+
import { planTviewMsa } from './tview'
|
|
5
|
+
|
|
6
|
+
import type { AnyConfigurationModel } from '@jbrowse/core/configuration'
|
|
7
|
+
import type {
|
|
8
|
+
AbstractSessionModel,
|
|
9
|
+
AbstractTrackModel,
|
|
10
|
+
Feature,
|
|
11
|
+
} from '@jbrowse/core/util'
|
|
12
|
+
|
|
13
|
+
/** the RPC needs assemblyName to resolve refNameAliases for the file */
|
|
14
|
+
export interface FetchRegion {
|
|
15
|
+
assemblyName: string
|
|
16
|
+
refName: string
|
|
17
|
+
start: number
|
|
18
|
+
end: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** what CoreGetFeatures needs, reachable from a live track or from its config */
|
|
22
|
+
export interface TviewSource {
|
|
23
|
+
adapterConfig: unknown
|
|
24
|
+
rpcSessionId: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function sourceFromTrack(track: AbstractTrackModel): TviewSource {
|
|
28
|
+
return {
|
|
29
|
+
adapterConfig: getConf(track, 'adapter'),
|
|
30
|
+
rpcSessionId: getRpcSessionId(track),
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The trackId -> config index, whose shape has changed across hosts still in
|
|
36
|
+
* the wild: v4.0.0 exposes a `tracksById` getter, v4.1-v4.3 a `getTracksById()`
|
|
37
|
+
* method, and newer cores a per-id reactive `getTrackById(id)` (with
|
|
38
|
+
* `getTracksById()` kept but deprecated). All three resolve connection and
|
|
39
|
+
* assembly-sequence tracks; the `tracks` scan is a last resort because it does
|
|
40
|
+
* not, and it subscribes the caller to every track.
|
|
41
|
+
*/
|
|
42
|
+
export interface SessionTrackLookup {
|
|
43
|
+
tracks: AnyConfigurationModel[]
|
|
44
|
+
getTrackById?: (id: string) => AnyConfigurationModel | undefined
|
|
45
|
+
getTracksById?: () => Record<string, AnyConfigurationModel>
|
|
46
|
+
tracksById?: Record<string, AnyConfigurationModel>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function findTrackConf(session: SessionTrackLookup, trackId: string) {
|
|
50
|
+
return session.getTrackById
|
|
51
|
+
? session.getTrackById(trackId)
|
|
52
|
+
: session.getTracksById
|
|
53
|
+
? session.getTracksById()[trackId]
|
|
54
|
+
: session.tracksById
|
|
55
|
+
? session.tracksById[trackId]
|
|
56
|
+
: session.tracks.find(t => readConfObject(t, 'trackId') === trackId)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A rebuild runs from the track's config rather than a track model, so it works
|
|
61
|
+
* whether or not the track is still open anywhere in the session.
|
|
62
|
+
*/
|
|
63
|
+
export function sourceFromConfig(conf: AnyConfigurationModel): TviewSource {
|
|
64
|
+
return {
|
|
65
|
+
adapterConfig: readConfObject(conf, 'adapter'),
|
|
66
|
+
rpcSessionId: `tview-${readConfObject(conf, 'trackId')}`,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function fetchTviewPlan({
|
|
71
|
+
session,
|
|
72
|
+
source,
|
|
73
|
+
region,
|
|
74
|
+
}: {
|
|
75
|
+
session: AbstractSessionModel
|
|
76
|
+
source: TviewSource
|
|
77
|
+
region: FetchRegion
|
|
78
|
+
}) {
|
|
79
|
+
const { adapterConfig, rpcSessionId } = source
|
|
80
|
+
const feats = (await session.rpcManager.call(
|
|
81
|
+
rpcSessionId,
|
|
82
|
+
'CoreGetFeatures',
|
|
83
|
+
{
|
|
84
|
+
adapterConfig,
|
|
85
|
+
sessionId: rpcSessionId,
|
|
86
|
+
regions: [region],
|
|
87
|
+
},
|
|
88
|
+
)) as Feature[]
|
|
89
|
+
const features = feats.filter(f => !!f.get('seq'))
|
|
90
|
+
// only planned, not rendered: a caller may cancel, or find it too large
|
|
91
|
+
return {
|
|
92
|
+
plan: planTviewMsa({ features, ...region }),
|
|
93
|
+
rowCount: features.length,
|
|
94
|
+
}
|
|
95
|
+
}
|