Skip to content

Commit 031d804

Browse files
authored
Change View subsequence to open MSA sidebar (#41)
1 parent e5284a7 commit 031d804

51 files changed

Lines changed: 79613 additions & 1905 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

esbuild.mjs

Lines changed: 60 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import * as esbuild from 'esbuild'
1+
import fs from 'node:fs'
22
import http from 'node:http'
3+
import * as esbuild from 'esbuild'
34
import { globalExternals } from '@fal-works/esbuild-plugin-global-externals'
4-
import JbrowseGlobals from '@jbrowse/core/ReExports/list.js'
5+
import JBrowseReExports from '@jbrowse/core/ReExports/list'
56
import prettyBytes from 'pretty-bytes'
67

8+
const isWatch = process.argv.includes('--watch')
9+
const PORT = process.env.PORT ? +process.env.PORT : 9000
10+
711
function createGlobalMap(jbrowseGlobals) {
812
const globalMap = {}
913
for (const global of jbrowseGlobals) {
@@ -12,115 +16,84 @@ function createGlobalMap(jbrowseGlobals) {
1216
type: 'cjs',
1317
}
1418
}
19+
// Map @jbrowse/mobx-state-tree to mobx-state-tree for backwards compatibility
20+
// In v4.0.0+, JBrowse uses @jbrowse/mobx-state-tree but exports it as 'mobx-state-tree'
21+
// In v3.x, JBrowse used mobx-state-tree directly
22+
globalMap['@jbrowse/mobx-state-tree'] = {
23+
varName: `JBrowseExports["mobx-state-tree"]`,
24+
type: 'cjs',
25+
}
1526
return globalMap
1627
}
1728

18-
if (process.env.NODE_ENV === 'production') {
19-
await esbuild.build({
20-
entryPoints: ['src/index.ts'],
21-
bundle: true,
22-
globalName: 'JBrowsePluginMafViewer',
23-
sourcemap: true,
24-
outfile: 'dist/jbrowse-plugin-mafviewer.umd.production.min.js',
25-
metafile: true,
26-
minify: true,
27-
plugins: [
28-
globalExternals(createGlobalMap(JbrowseGlobals.default)),
29-
{
30-
name: 'rebuild-log',
31-
setup({ onStart, onEnd }) {
32-
let time
33-
onStart(() => {
34-
time = Date.now()
35-
})
36-
onEnd(({ metafile, errors, warnings }) => {
37-
console.log(
38-
`Built in ${Date.now() - time} ms with ${
39-
errors.length
40-
} error(s) and ${warnings.length} warning(s)`,
41-
)
42-
if (!metafile) {
43-
return
44-
}
45-
const { outputs } = metafile
46-
for (const [file, metadata] of Object.entries(outputs)) {
47-
const size = prettyBytes(metadata.bytes)
48-
console.log(`Wrote ${size} to ${file}`)
49-
}
50-
})
51-
},
52-
},
53-
],
54-
})
55-
} else {
56-
let ctx = await esbuild.context({
57-
entryPoints: ['src/index.ts'],
58-
bundle: true,
59-
globalName: 'JBrowsePluginMafViewer',
60-
sourcemap: true,
61-
outfile: 'dist/out.js',
62-
metafile: true,
63-
plugins: [
64-
globalExternals(createGlobalMap(JbrowseGlobals.default)),
65-
{
66-
name: 'rebuild-log',
67-
setup({ onStart, onEnd }) {
68-
let time
69-
onStart(() => {
70-
time = Date.now()
71-
})
72-
onEnd(({ metafile, errors, warnings }) => {
73-
console.log(
74-
`Built in ${Date.now() - time} ms with ${
75-
errors.length
76-
} error(s) and ${warnings.length} warning(s)`,
77-
)
78-
if (!metafile) {
79-
return
80-
}
81-
const { outputs } = metafile
82-
for (const [file, metadata] of Object.entries(outputs)) {
83-
const size = prettyBytes(metadata.bytes)
84-
console.log(`Wrote ${size} to ${file}`)
85-
}
86-
})
87-
},
88-
},
89-
],
90-
})
91-
let { hosts, port } = await ctx.serve({
92-
servedir: '.',
93-
port: 9001,
94-
})
29+
const rebuildLogPlugin = {
30+
name: 'rebuild-log',
31+
setup({ onStart, onEnd }) {
32+
let time
33+
onStart(() => {
34+
time = Date.now()
35+
})
36+
onEnd(({ metafile, errors, warnings }) => {
37+
console.log(
38+
`Built in ${Date.now() - time} ms with ${errors.length} error(s) and ${warnings.length} warning(s)`,
39+
)
40+
if (metafile) {
41+
for (const [file, metadata] of Object.entries(metafile.outputs)) {
42+
console.log(`Wrote ${prettyBytes(metadata.bytes)} to ${file}`)
43+
}
44+
}
45+
})
46+
},
47+
}
48+
49+
const globals = JBrowseReExports
50+
const config = {
51+
entryPoints: ['src/index.ts'],
52+
bundle: true,
53+
globalName: 'JBrowsePluginMafViewer',
54+
metafile: true,
55+
plugins: [globalExternals(createGlobalMap(globals)), rebuildLogPlugin],
56+
...(isWatch
57+
? { outfile: 'dist/out.js' }
58+
: {
59+
outfile: 'dist/jbrowse-plugin-mafviewer.umd.production.min.js',
60+
sourcemap: true,
61+
minify: true,
62+
}),
63+
}
64+
65+
if (isWatch) {
66+
const ctx = await esbuild.context(config)
67+
const internalPort = PORT + 400
68+
const { hosts } = await ctx.serve({ servedir: '.', port: internalPort })
9569

9670
http
9771
.createServer((req, res) => {
9872
const proxyReq = http.request(
9973
{
10074
hostname: hosts[0],
101-
port: 9001,
75+
port: internalPort,
10276
path: req.url,
10377
method: req.method,
10478
headers: req.headers,
10579
},
10680
proxyRes => {
107-
//restore the CORS after
108-
//https://github.com/evanw/esbuild/releases/tag/v0.25.0 disabled it
109-
//as a potential vuln
81+
// restore CORS after https://github.com/evanw/esbuild/releases/tag/v0.25.0 disabled it
11082
res.writeHead(proxyRes.statusCode, {
11183
...proxyRes.headers,
11284
'Access-Control-Allow-Origin': '*',
11385
})
11486
proxyRes.pipe(res, { end: true })
11587
},
11688
)
117-
118-
// Forward the body of the request to esbuild
11989
req.pipe(proxyReq, { end: true })
12090
})
121-
.listen(9000)
122-
console.log(`Serving at http://${hosts[0]}:9000`)
91+
.listen(PORT)
12392

93+
console.log(`Serving at http://${hosts[0]}:${PORT}`)
12494
await ctx.watch()
12595
console.log('Watching files...')
96+
} else {
97+
const result = await esbuild.build(config)
98+
fs.writeFileSync('meta.json', JSON.stringify(result.metafile))
12699
}

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default tseslint.config(
99
'webpack.config.js',
1010
'dist/*',
1111
'esm/*',
12+
'test/*.min.js',
1213
'example/*',
1314
'eslint.config.mjs',
1415
'esbuild.mjs',

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"scripts": {
1717
"clean": "rimraf dist",
18-
"start": "node esbuild.mjs",
18+
"start": "node esbuild.mjs --watch",
1919
"test": "vitest",
2020
"format": "prettier --write .",
2121
"prebuild": "yarn clean",
@@ -29,9 +29,10 @@
2929
"@babel/preset-react": "^7.10.4",
3030
"@emotion/react": "^11.10.4",
3131
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
32-
"@jbrowse/core": "^3.0.1",
33-
"@jbrowse/plugin-data-management": "^3.0.1",
34-
"@jbrowse/plugin-linear-genome-view": "^3.0.1",
32+
"@jbrowse/core": "^4.1.1",
33+
"@jbrowse/mobx-state-tree": "^5.4.1",
34+
"@jbrowse/plugin-data-management": "^4.1.1",
35+
"@jbrowse/plugin-linear-genome-view": "^4.1.1",
3536
"@mui/material": "^7.0.1",
3637
"@mui/system": "^7.0.1",
3738
"@mui/x-data-grid": "^8.2.0",
@@ -48,7 +49,6 @@
4849
"eslint-plugin-unicorn": "^62.0.0",
4950
"mobx": "^6.0.0",
5051
"mobx-react": "^9.0.1",
51-
"mobx-state-tree": "^5.4.1",
5252
"prettier": "^3.4.2",
5353
"pretty-bytes": "^7.0.0",
5454
"react": "^19.0.0",
@@ -62,7 +62,7 @@
6262
"vitest": "^4.0.5"
6363
},
6464
"dependencies": {
65-
"@gmod/bgzf-filehandle": "^5.0.2",
65+
"@gmod/bgzf-filehandle": "^6.0.12",
6666
"abortable-promise-cache": "^1.5.0",
6767
"buffer": "^6.0.3",
6868
"d3-array": "^3.2.4",

src/BigMafAdapter/BigMafAdapter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter'
22
import { SimpleFeature, updateStatus } from '@jbrowse/core/util'
33
import { openLocation } from '@jbrowse/core/util/io'
44
import { ObservableCreate } from '@jbrowse/core/util/rxjs'
5-
import { getSnapshot } from 'mobx-state-tree'
5+
import { getSnapshot } from '@jbrowse/mobx-state-tree'
66
import { firstValueFrom, toArray } from 'rxjs'
77

88
import parseNewick from '../parseNewick'
99
import { normalize } from '../util'
10+
import { parseAssemblyAndChrSimple } from '../util/parseAssemblyName'
1011

1112
import type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter'
1213
import type { Feature, Region } from '@jbrowse/core/util'
@@ -103,10 +104,9 @@ export default class BigMafAdapter extends BaseFeatureDataAdapter {
103104
referenceSeq = sequence
104105
}
105106

106-
// Parse organism and chromosome once
107-
const dotIndex = organismChr.indexOf('.')
108-
const org = organismChr.slice(0, Math.max(0, dotIndex))
109-
const chr = organismChr.slice(Math.max(0, dotIndex + 1))
107+
// Parse organism and chromosome
108+
const { assemblyName: org, chr } =
109+
parseAssemblyAndChrSimple(organismChr)
110110

111111
// Create alignment record directly
112112
alignments[org] = {

0 commit comments

Comments
 (0)