@jbrowse/plugin-wiggle 1.4.4 → 1.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/plugin-wiggle",
3
- "version": "1.4.4",
3
+ "version": "1.5.3",
4
4
  "description": "JBrowse 2 wiggle adapters, tracks, etc.",
5
5
  "keywords": [
6
6
  "jbrowse",
@@ -35,7 +35,7 @@
35
35
  "useSrc": "node ../../scripts/useSrc.js"
36
36
  },
37
37
  "dependencies": {
38
- "@gmod/bbi": "^1.0.30",
38
+ "@gmod/bbi": "^1.0.31",
39
39
  "@material-ui/icons": "^4.11.2",
40
40
  "@popperjs/core": "^2.9.3",
41
41
  "abortable-promise-cache": "^1.1.3",
@@ -60,5 +60,5 @@
60
60
  "publishConfig": {
61
61
  "access": "public"
62
62
  },
63
- "gitHead": "c12a2b1cef07dbc5ea40be5c76e03b655b7f3636"
63
+ "gitHead": "cea9023ebce8bbe5c08ae9e00c4e74fe3f02a7f1"
64
64
  }
@@ -7,7 +7,10 @@ describe('adapter can fetch features from volvox.bw', () => {
7
7
  beforeEach(() => {
8
8
  adapter = new BigWigAdapter(
9
9
  configSchema.create({
10
- bigWigLocation: { localPath: require.resolve('./test_data/volvox.bw') },
10
+ bigWigLocation: {
11
+ localPath: require.resolve('./test_data/volvox.bw'),
12
+ locationType: 'LocalPathLocation',
13
+ },
11
14
  }),
12
15
  )
13
16
  })
@@ -16,6 +19,7 @@ describe('adapter can fetch features from volvox.bw', () => {
16
19
  refName: 'ctgA',
17
20
  start: 0,
18
21
  end: 20000,
22
+ assemblyName: 'volvox',
19
23
  })
20
24
  expect(await adapter.refIdToName(0)).toBe('ctgA')
21
25
  expect(await adapter.refIdToName(1)).toBe(undefined)
@@ -1,9 +1,9 @@
1
- import { BigWig, Feature as BBIFeature } from '@gmod/bbi'
1
+ import { BigWig } from '@gmod/bbi'
2
2
  import {
3
3
  BaseFeatureDataAdapter,
4
4
  BaseOptions,
5
5
  } from '@jbrowse/core/data_adapters/BaseAdapter'
6
- import { NoAssemblyRegion } from '@jbrowse/core/util/types'
6
+ import { AugmentedRegion as Region } from '@jbrowse/core/util/types'
7
7
  import { openLocation } from '@jbrowse/core/util/io'
8
8
  import { ObservableCreate } from '@jbrowse/core/util/rxjs'
9
9
  import SimpleFeature, { Feature } from '@jbrowse/core/util/simpleFeature'
@@ -11,8 +11,10 @@ import { map, mergeAll } from 'rxjs/operators'
11
11
  import { readConfObject } from '@jbrowse/core/configuration'
12
12
  import { Instance } from 'mobx-state-tree'
13
13
  import { rectifyStats, UnrectifiedFeatureStats } from '@jbrowse/core/util/stats'
14
+ import PluginManager from '@jbrowse/core/PluginManager'
14
15
 
15
16
  import configSchema from './configSchema'
17
+ import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'
16
18
 
17
19
  interface WiggleOptions extends BaseOptions {
18
20
  resolution?: number
@@ -27,10 +29,17 @@ export default class BigWigAdapter extends BaseFeatureDataAdapter {
27
29
  'hasGlobalStats',
28
30
  ]
29
31
 
30
- public constructor(config: Instance<typeof configSchema>) {
31
- super(config)
32
+ public constructor(
33
+ config: Instance<typeof configSchema>,
34
+ getSubAdapter?: getSubAdapterType,
35
+ pluginManager?: PluginManager,
36
+ ) {
37
+ super(config, getSubAdapter, pluginManager)
32
38
  this.bigwig = new BigWig({
33
- filehandle: openLocation(readConfObject(config, 'bigWigLocation')),
39
+ filehandle: openLocation(
40
+ readConfObject(config, 'bigWigLocation'),
41
+ this.pluginManager,
42
+ ),
34
43
  })
35
44
  }
36
45
 
@@ -57,7 +66,7 @@ export default class BigWigAdapter extends BaseFeatureDataAdapter {
57
66
  return rectifyStats(header.totalSummary as UnrectifiedFeatureStats)
58
67
  }
59
68
 
60
- public getFeatures(region: NoAssemblyRegion, opts: WiggleOptions = {}) {
69
+ public getFeatures(region: Region, opts: WiggleOptions = {}) {
61
70
  const { refName, start, end } = region
62
71
  const {
63
72
  bpPerPx = 0,
@@ -73,7 +82,7 @@ export default class BigWigAdapter extends BaseFeatureDataAdapter {
73
82
  })
74
83
  ob.pipe(
75
84
  mergeAll(),
76
- map((record: BBIFeature) => {
85
+ map(record => {
77
86
  return new SimpleFeature({
78
87
  id: `${refName}:${record.start}-${record.end}`,
79
88
  data: { ...record, refName },
@@ -85,5 +94,3 @@ export default class BigWigAdapter extends BaseFeatureDataAdapter {
85
94
 
86
95
  public freeResources(): void {}
87
96
  }
88
- const adapterCapabilities = BigWigAdapter.capabilities
89
- export { adapterCapabilities }
@@ -5,7 +5,10 @@ export default ConfigurationSchema(
5
5
  {
6
6
  bigWigLocation: {
7
7
  type: 'fileLocation',
8
- defaultValue: { uri: '/path/to/my.bw' },
8
+ defaultValue: {
9
+ uri: '/path/to/my.bw',
10
+ locationType: 'UriLocation',
11
+ },
9
12
  },
10
13
  },
11
14
  { explicitlyTyped: true },
@@ -1,2 +1 @@
1
1
  export { default as configSchema } from './configSchema'
2
- export { adapterCapabilities } from './BigWigAdapter'
@@ -1,8 +1,9 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
  import React, { useMemo, useState } from 'react'
3
2
  import { observer } from 'mobx-react'
4
3
  import { makeStyles, alpha, Portal } from '@material-ui/core'
5
4
  import { Feature } from '@jbrowse/core/util/simpleFeature'
5
+
6
+ // locals
6
7
  import { YSCALEBAR_LABEL_OFFSET } from '../models/model'
7
8
  import { usePopper } from 'react-popper'
8
9
 
@@ -86,18 +87,19 @@ const Tooltip = observer(
86
87
  clientRect,
87
88
  TooltipContents,
88
89
  }: {
89
- model: any
90
+ model: { featureUnderMouse: Feature }
90
91
  height: number
91
92
  clientMouseCoord: Coord
92
93
  offsetMouseCoord: Coord
93
94
  clientRect?: ClientRect
95
+
96
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
97
  TooltipContents: React.FC<any>
95
98
  }) => {
96
99
  const { featureUnderMouse } = model
97
- const classes = useStyles()
98
100
  const [width, setWidth] = useState(0)
99
-
100
- const [popperElement, setPopperElement] = useState<any>(null)
101
+ const [anchorEl, setAnchorEl] = useState<HTMLDivElement | null>(null)
102
+ const classes = useStyles()
101
103
 
102
104
  // must be memoized a la https://github.com/popperjs/react-popper/issues/391
103
105
  const virtElement = useMemo(
@@ -112,18 +114,21 @@ const Tooltip = observer(
112
114
  right: x,
113
115
  width: 0,
114
116
  height: 0,
117
+ x,
118
+ y,
119
+ toJSON() {},
115
120
  }
116
121
  },
117
122
  }),
118
123
  [clientRect?.top, clientMouseCoord, width],
119
124
  )
120
- const { styles, attributes } = usePopper(virtElement, popperElement)
125
+ const { styles, attributes } = usePopper(virtElement, anchorEl)
121
126
 
122
127
  return featureUnderMouse ? (
123
128
  <>
124
129
  <Portal>
125
130
  <div
126
- ref={setPopperElement}
131
+ ref={setAnchorEl}
127
132
  className={classes.tooltip}
128
133
  // zIndex needed to go over widget drawer
129
134
  style={{ ...styles.popper, zIndex: 100000 }}
@@ -152,7 +157,7 @@ const Tooltip = observer(
152
157
 
153
158
  const WiggleTooltip = observer(
154
159
  (props: {
155
- model: any
160
+ model: { featureUnderMouse: Feature }
156
161
  height: number
157
162
  offsetMouseCoord: Coord
158
163
  clientMouseCoord: Coord
@@ -4,15 +4,12 @@ import { types } from 'mobx-state-tree'
4
4
  import PluginManager from '@jbrowse/core/PluginManager'
5
5
 
6
6
  export default function WiggleConfigFactory(pluginManager: PluginManager) {
7
- const XYPlotRendererConfigSchema = pluginManager.getRendererType(
8
- 'XYPlotRenderer',
9
- ).configSchema
10
- const DensityRendererConfigSchema = pluginManager.getRendererType(
11
- 'DensityRenderer',
12
- ).configSchema
13
- const LinePlotRendererConfigSchema = pluginManager.getRendererType(
14
- 'LinePlotRenderer',
15
- ).configSchema
7
+ const XYPlotRendererConfigSchema =
8
+ pluginManager.getRendererType('XYPlotRenderer').configSchema
9
+ const DensityRendererConfigSchema =
10
+ pluginManager.getRendererType('DensityRenderer').configSchema
11
+ const LinePlotRendererConfigSchema =
12
+ pluginManager.getRendererType('LinePlotRenderer').configSchema
16
13
 
17
14
  return ConfigurationSchema(
18
15
  'LinearWiggleDisplay',
@@ -162,7 +162,7 @@ const stateModelFactory = (
162
162
  }))
163
163
  .views(self => ({
164
164
  get TooltipComponent(): React.FC {
165
- return (Tooltip as unknown) as React.FC
165
+ return Tooltip as unknown as React.FC
166
166
  },
167
167
 
168
168
  get adapterTypeName() {
@@ -438,17 +438,19 @@ const stateModelFactory = (
438
438
  {
439
439
  label: 'Set min/max score',
440
440
  onClick: () => {
441
- getSession(self).setDialogComponent(SetMinMaxDlg, {
442
- model: self,
443
- })
441
+ getSession(self).queueDialog((doneCallback: Function) => [
442
+ SetMinMaxDlg,
443
+ { model: self, handleClose: doneCallback },
444
+ ])
444
445
  },
445
446
  },
446
447
  {
447
448
  label: 'Set color',
448
449
  onClick: () => {
449
- getSession(self).setDialogComponent(SetColorDlg, {
450
- model: self,
451
- })
450
+ getSession(self).queueDialog((doneCallback: Function) => [
451
+ SetColorDlg,
452
+ { model: self, handleClose: doneCallback },
453
+ ])
452
454
  },
453
455
  },
454
456
  ]
@@ -507,7 +509,7 @@ const stateModelFactory = (
507
509
  regions: dynamicBlocks.contentBlocks.map(region => {
508
510
  const { start, end } = region
509
511
  return {
510
- ...region,
512
+ ...JSON.parse(JSON.stringify(region)),
511
513
  start: Math.floor(start),
512
514
  end: Math.ceil(end),
513
515
  }
@@ -542,13 +544,18 @@ const stateModelFactory = (
542
544
  async reload() {
543
545
  self.setError()
544
546
  const aborter = new AbortController()
545
- const stats = await getStats({
546
- signal: aborter.signal,
547
- filters: self.filters,
548
- })
549
- if (isAlive(self)) {
550
- self.updateStats(stats)
551
- superReload()
547
+ let stats
548
+ try {
549
+ stats = await getStats({
550
+ signal: aborter.signal,
551
+ filters: self.filters,
552
+ })
553
+ if (isAlive(self)) {
554
+ self.updateStats(stats)
555
+ superReload()
556
+ }
557
+ } catch (e) {
558
+ self.setError(e)
552
559
  }
553
560
  },
554
561
  afterAttach() {
@@ -579,6 +586,7 @@ const stateModelFactory = (
579
586
  }
580
587
  } catch (e) {
581
588
  if (!isAbortException(e) && isAlive(self)) {
589
+ console.error(e)
582
590
  self.setError(e)
583
591
  }
584
592
  }
@@ -74,17 +74,20 @@ export class WiggleGetMultiRegionStats extends RpcMethodType {
74
74
 
75
75
  async serializeArguments(
76
76
  args: RenderArgs & { signal?: AbortSignal; statusCallback?: Function },
77
+ rpcDriverClassName: string,
77
78
  ) {
78
- const assemblyManager = this.pluginManager.rootModel?.session
79
- ?.assemblyManager
79
+ const assemblyManager =
80
+ this.pluginManager.rootModel?.session?.assemblyManager
80
81
  if (!assemblyManager) {
81
82
  return args
82
83
  }
83
84
 
84
- return renameRegionsIfNeeded(assemblyManager, {
85
+ const renamedArgs = await renameRegionsIfNeeded(assemblyManager, {
85
86
  ...args,
86
87
  filters: args.filters && args.filters.toJSON().filters,
87
88
  })
89
+
90
+ return super.serializeArguments(renamedArgs, rpcDriverClassName)
88
91
  }
89
92
 
90
93
  async execute(
@@ -14,6 +14,7 @@ function WiggleRendering(props: {
14
14
  onMouseLeave: Function
15
15
  onMouseMove: Function
16
16
  onFeatureClick: Function
17
+ blockKey: string
17
18
  }) {
18
19
  const {
19
20
  regions,
@@ -43,7 +43,7 @@ export default class XYPlotRenderer extends WiggleBaseRenderer {
43
43
  const originY = getOrigin(scaleOpts.scaleType)
44
44
  const [niceMin, niceMax] = scale.domain()
45
45
 
46
- const toY = (n: number) => height - scale(n) + offset
46
+ const toY = (n: number) => height - (scale(n) || 0) + offset
47
47
  const toHeight = (n: number) => toY(originY) - toY(n)
48
48
 
49
49
  const colorCallback =
package/src/index.ts CHANGED
@@ -9,12 +9,10 @@ import {
9
9
  createBaseTrackModel,
10
10
  } from '@jbrowse/core/pluggableElementTypes/models'
11
11
  import DisplayType from '@jbrowse/core/pluggableElementTypes/DisplayType'
12
+ import { FileLocation } from '@jbrowse/core/util/types'
12
13
  import WiggleBaseRenderer from './WiggleBaseRenderer'
13
14
  import WiggleRendering from './WiggleRendering'
14
- import {
15
- configSchema as bigWigAdapterConfigSchema,
16
- adapterCapabilities,
17
- } from './BigWigAdapter'
15
+ import { configSchema as bigWigAdapterConfigSchema } from './BigWigAdapter'
18
16
  import DensityRenderer, {
19
17
  configSchema as densityRendererConfigSchema,
20
18
  ReactComponent as DensityRendererReactComponent,
@@ -38,6 +36,11 @@ import {
38
36
  WiggleGetGlobalStats,
39
37
  WiggleGetMultiRegionStats,
40
38
  } from './WiggleRPC/rpcMethods'
39
+ import {
40
+ AdapterGuesser,
41
+ getFileName,
42
+ TrackTypeGuesser,
43
+ } from '@jbrowse/core/util/tracks'
41
44
 
42
45
  export default class WigglePlugin extends Plugin {
43
46
  name = 'WigglePlugin'
@@ -80,11 +83,47 @@ export default class WigglePlugin extends Plugin {
80
83
  new AdapterType({
81
84
  name: 'BigWigAdapter',
82
85
  configSchema: bigWigAdapterConfigSchema,
83
- adapterCapabilities,
86
+ adapterCapabilities: [
87
+ 'hasResolution',
88
+ 'hasLocalStats',
89
+ 'hasGlobalStats',
90
+ ],
84
91
  getAdapterClass: () =>
85
92
  import('./BigWigAdapter/BigWigAdapter').then(r => r.default),
86
93
  }),
87
94
  )
95
+ pluginManager.addToExtensionPoint(
96
+ 'Core-guessAdapterForLocation',
97
+ (adapterGuesser: AdapterGuesser) => {
98
+ return (
99
+ file: FileLocation,
100
+ index?: FileLocation,
101
+ adapterHint?: string,
102
+ ) => {
103
+ const regexGuess = /\.(bw|bigwig)$/i
104
+ const adapterName = 'BigWigAdapter'
105
+ const fileName = getFileName(file)
106
+ if (regexGuess.test(fileName) || adapterHint === adapterName) {
107
+ return {
108
+ type: adapterName,
109
+ bigWigLocation: file,
110
+ }
111
+ }
112
+ return adapterGuesser(file, index, adapterHint)
113
+ }
114
+ },
115
+ )
116
+ pluginManager.addToExtensionPoint(
117
+ 'Core-guessTrackTypeForLocation',
118
+ (trackTypeGuesser: TrackTypeGuesser) => {
119
+ return (adapterName: string) => {
120
+ if (adapterName === 'BigWigAdapter') {
121
+ return 'QuantitativeTrack'
122
+ }
123
+ return trackTypeGuesser(adapterName)
124
+ }
125
+ },
126
+ )
88
127
 
89
128
  pluginManager.addRendererType(
90
129
  () =>