@jbrowse/plugin-sequence 1.4.1 → 1.5.2

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-sequence",
3
- "version": "1.4.1",
3
+ "version": "1.5.2",
4
4
  "description": "JBrowse 2 sequence adapters, tracks, etc.",
5
5
  "keywords": [
6
6
  "jbrowse",
@@ -35,11 +35,11 @@
35
35
  "useSrc": "node ../../scripts/useSrc.js"
36
36
  },
37
37
  "dependencies": {
38
- "@gmod/indexedfasta": "^2.0.1",
39
- "@gmod/twobit": "^1.1.10",
38
+ "@gmod/indexedfasta": "^2.0.2",
39
+ "@gmod/twobit": "^1.1.12",
40
40
  "abortable-promise-cache": "^1.3.0",
41
41
  "clsx": "^1.1.0",
42
- "generic-filehandle": "^2.0.1"
42
+ "generic-filehandle": "^2.2.2"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@jbrowse/core": "^1.0.0",
@@ -55,5 +55,5 @@
55
55
  "publishConfig": {
56
56
  "access": "public"
57
57
  },
58
- "gitHead": "42c7e1b98bb0d16fa440a8a8f500a1030607f16c"
58
+ "gitHead": "94fdfbc34787ab8f12a87e00038da74b247b42fa"
59
59
  }
@@ -7,12 +7,15 @@ test('can use a indexed fasta with gzi', async () => {
7
7
  configSchema.create({
8
8
  fastaLocation: {
9
9
  localPath: require.resolve('../../test_data/volvox.fa.gz'),
10
+ locationType: 'LocalPathLocation',
10
11
  },
11
12
  faiLocation: {
12
13
  localPath: require.resolve('../../test_data/volvox.fa.gz.fai'),
14
+ locationType: 'LocalPathLocation',
13
15
  },
14
16
  gziLocation: {
15
17
  localPath: require.resolve('../../test_data/volvox.fa.gz.gzi'),
18
+ locationType: 'LocalPathLocation',
16
19
  },
17
20
  }),
18
21
  )
@@ -4,10 +4,16 @@ import { openLocation } from '@jbrowse/core/util/io'
4
4
  import { readConfObject } from '@jbrowse/core/configuration'
5
5
  import { AnyConfigurationModel } from '@jbrowse/core/configuration/configurationSchema'
6
6
  import IndexedFasta from '../IndexedFastaAdapter/IndexedFastaAdapter'
7
+ import PluginManager from '@jbrowse/core/PluginManager'
8
+ import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'
7
9
 
8
10
  export default class extends IndexedFasta {
9
- public constructor(config: AnyConfigurationModel) {
10
- super(config)
11
+ public constructor(
12
+ config: AnyConfigurationModel,
13
+ getSubAdapter?: getSubAdapterType,
14
+ pluginManager?: PluginManager,
15
+ ) {
16
+ super(config, getSubAdapter, pluginManager)
11
17
  const fastaLocation = readConfObject(config, 'fastaLocation')
12
18
  const faiLocation = readConfObject(config, 'faiLocation')
13
19
  const gziLocation = readConfObject(config, 'gziLocation')
@@ -21,9 +27,9 @@ export default class extends IndexedFasta {
21
27
  throw new Error('must provide gziLocation')
22
28
  }
23
29
  const fastaOpts = {
24
- fasta: openLocation(fastaLocation as FileLocation),
25
- fai: openLocation(faiLocation as FileLocation),
26
- gzi: openLocation(gziLocation as FileLocation),
30
+ fasta: openLocation(fastaLocation as FileLocation, this.pluginManager),
31
+ fai: openLocation(faiLocation as FileLocation, this.pluginManager),
32
+ gzi: openLocation(gziLocation as FileLocation, this.pluginManager),
27
33
  }
28
34
 
29
35
  this.fasta = new BgzipIndexedFasta(fastaOpts)
@@ -5,15 +5,21 @@ export default ConfigurationSchema(
5
5
  {
6
6
  fastaLocation: {
7
7
  type: 'fileLocation',
8
- defaultValue: { uri: '/path/to/seq.fa.gz' },
8
+ defaultValue: { uri: '/path/to/seq.fa.gz', locationType: 'UriLocation' },
9
9
  },
10
10
  faiLocation: {
11
11
  type: 'fileLocation',
12
- defaultValue: { uri: '/path/to/seq.fa.gz.fai' },
12
+ defaultValue: {
13
+ uri: '/path/to/seq.fa.gz.fai',
14
+ locationType: 'UriLocation',
15
+ },
13
16
  },
14
17
  gziLocation: {
15
18
  type: 'fileLocation',
16
- defaultValue: { uri: '/path/to/seq.fa.gz.gzi' },
19
+ defaultValue: {
20
+ uri: '/path/to/seq.fa.gz.gzi',
21
+ locationType: 'UriLocation',
22
+ },
17
23
  },
18
24
  },
19
25
  { explicitlyTyped: true },
@@ -6,6 +6,7 @@ test('adapter can fetch sequence from volvox.chrom.sizes', async () => {
6
6
  configSchema.create({
7
7
  chromSizesLocation: {
8
8
  localPath: require.resolve('./test_data/volvox.chrom.sizes'),
9
+ locationType: 'LocalPathLocation',
9
10
  },
10
11
  }),
11
12
  )
@@ -8,6 +8,8 @@ import { GenericFilehandle } from 'generic-filehandle'
8
8
  import { readConfObject } from '@jbrowse/core/configuration'
9
9
  import { Instance } from 'mobx-state-tree'
10
10
  import MyConfigSchema from './configSchema'
11
+ import PluginManager from '@jbrowse/core/PluginManager'
12
+ import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'
11
13
 
12
14
  export default class extends BaseAdapter implements RegionsAdapter {
13
15
  // the map of refSeq to length
@@ -15,13 +17,20 @@ export default class extends BaseAdapter implements RegionsAdapter {
15
17
 
16
18
  protected source: string
17
19
 
18
- public constructor(config: Instance<typeof MyConfigSchema>) {
19
- super(config)
20
+ public constructor(
21
+ config: Instance<typeof MyConfigSchema>,
22
+ getSubAdapter?: getSubAdapterType,
23
+ pluginManager?: PluginManager,
24
+ ) {
25
+ super(config, getSubAdapter, pluginManager)
20
26
  const chromSizesLocation = readConfObject(config, 'chromSizesLocation')
21
27
  if (!chromSizesLocation) {
22
28
  throw new Error('must provide chromSizesLocation')
23
29
  }
24
- const file = openLocation(chromSizesLocation as FileLocation)
30
+ const file = openLocation(
31
+ chromSizesLocation as FileLocation,
32
+ this.pluginManager,
33
+ )
25
34
  this.source = file.toString()
26
35
  this.refSeqs = this.init(file)
27
36
  }
@@ -5,7 +5,10 @@ export default ConfigurationSchema(
5
5
  {
6
6
  chromSizesLocation: {
7
7
  type: 'fileLocation',
8
- defaultValue: { uri: '/path/to/species.chrom.sizes' },
8
+ defaultValue: {
9
+ uri: '/path/to/species.chrom.sizes',
10
+ locationType: 'UriLocation',
11
+ },
9
12
  },
10
13
  },
11
14
  { explicitlyTyped: true },
@@ -7,9 +7,11 @@ test('adapter can fetch sequence from volvox.fa', async () => {
7
7
  configSchema.create({
8
8
  fastaLocation: {
9
9
  localPath: require.resolve('../../test_data/volvox.fa'),
10
+ locationType: 'LocalPathLocation',
10
11
  },
11
12
  faiLocation: {
12
13
  localPath: require.resolve('../../test_data/volvox.fa.fai'),
14
+ locationType: 'LocalPathLocation',
13
15
  },
14
16
  }),
15
17
  )
@@ -12,6 +12,8 @@ import { readConfObject } from '@jbrowse/core/configuration'
12
12
  import { AnyConfigurationModel } from '@jbrowse/core/configuration/configurationSchema'
13
13
  import AbortablePromiseCache from 'abortable-promise-cache'
14
14
  import LRU from '@jbrowse/core/util/QuickLRU'
15
+ import PluginManager from '@jbrowse/core/PluginManager'
16
+ import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'
15
17
 
16
18
  export default class extends BaseFeatureDataAdapter implements SequenceAdapter {
17
19
  protected fasta: typeof IndexedFasta
@@ -27,13 +29,17 @@ export default class extends BaseFeatureDataAdapter implements SequenceAdapter {
27
29
  },
28
30
  })
29
31
 
30
- public constructor(config: AnyConfigurationModel) {
31
- super(config)
32
+ public constructor(
33
+ config: AnyConfigurationModel,
34
+ getSubAdapter?: getSubAdapterType,
35
+ pluginManager?: PluginManager,
36
+ ) {
37
+ super(config, getSubAdapter, pluginManager)
32
38
  const fastaLocation = readConfObject(config, 'fastaLocation')
33
39
  const faiLocation = readConfObject(config, 'faiLocation')
34
40
  const fastaOpts = {
35
- fasta: openLocation(fastaLocation as FileLocation),
36
- fai: openLocation(faiLocation as FileLocation),
41
+ fasta: openLocation(fastaLocation as FileLocation, this.pluginManager),
42
+ fai: openLocation(faiLocation as FileLocation, this.pluginManager),
37
43
  }
38
44
 
39
45
  this.fasta = new IndexedFasta(fastaOpts)
@@ -5,11 +5,11 @@ export default ConfigurationSchema(
5
5
  {
6
6
  fastaLocation: {
7
7
  type: 'fileLocation',
8
- defaultValue: { uri: '/path/to/seq.fa' },
8
+ defaultValue: { uri: '/path/to/seq.fa', locationType: 'UriLocation' },
9
9
  },
10
10
  faiLocation: {
11
11
  type: 'fileLocation',
12
- defaultValue: { uri: '/path/to/seq.fa.fai' },
12
+ defaultValue: { uri: '/path/to/seq.fa.fai', locationType: 'UriLocation' },
13
13
  },
14
14
  },
15
15
  { explicitlyTyped: true },
@@ -7,6 +7,7 @@ test('adapter can fetch features from volvox.2bit', async () => {
7
7
  configSchema.create({
8
8
  twoBitLocation: {
9
9
  localPath: require.resolve('../../test_data/volvox.2bit'),
10
+ locationType: 'LocalPathLocation',
10
11
  },
11
12
  }),
12
13
  )
@@ -44,6 +45,7 @@ test('adapter can fetch regions from with chrom.sizes', async () => {
44
45
  configSchema.create({
45
46
  chromSizesLocation: {
46
47
  localPath: require.resolve('../../test_data/volvox.chrom.sizes'),
48
+ locationType: 'LocalPathLocation',
47
49
  },
48
50
  }),
49
51
  )
@@ -9,10 +9,13 @@ import SimpleFeature, { Feature } from '@jbrowse/core/util/simpleFeature'
9
9
  import { TwoBitFile } from '@gmod/twobit'
10
10
  import { readConfObject } from '@jbrowse/core/configuration'
11
11
  import { AnyConfigurationModel } from '@jbrowse/core/configuration/configurationSchema'
12
+ import PluginManager from '@jbrowse/core/PluginManager'
13
+ import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'
12
14
 
13
15
  export default class TwoBitAdapter
14
16
  extends BaseFeatureDataAdapter
15
- implements SequenceAdapter {
17
+ implements SequenceAdapter
18
+ {
16
19
  private twobit: typeof TwoBitFile
17
20
 
18
21
  // the chromSizesData can be used to speed up loading since TwoBit has to do
@@ -25,7 +28,7 @@ export default class TwoBitAdapter
25
28
  // config editor, may want better way to check "optional config slots" in
26
29
  // future
27
30
  if (conf.uri !== '/path/to/default.chrom.sizes' && conf.uri !== '') {
28
- const file = openLocation(conf)
31
+ const file = openLocation(conf, this.pluginManager)
29
32
  const data = (await file.readFile('utf8')) as string
30
33
  return Object.fromEntries(
31
34
  data
@@ -40,11 +43,18 @@ export default class TwoBitAdapter
40
43
  return undefined
41
44
  }
42
45
 
43
- constructor(config: AnyConfigurationModel) {
44
- super(config)
46
+ constructor(
47
+ config: AnyConfigurationModel,
48
+ getSubAdapter?: getSubAdapterType,
49
+ pluginManager?: PluginManager,
50
+ ) {
51
+ super(config, getSubAdapter, pluginManager)
45
52
  this.chromSizesData = this.initChromSizes()
46
53
  this.twobit = new TwoBitFile({
47
- filehandle: openLocation(readConfObject(config, 'twoBitLocation')),
54
+ filehandle: openLocation(
55
+ readConfObject(config, 'twoBitLocation'),
56
+ this.pluginManager,
57
+ ),
48
58
  })
49
59
  }
50
60
 
@@ -5,11 +5,14 @@ export default ConfigurationSchema(
5
5
  {
6
6
  twoBitLocation: {
7
7
  type: 'fileLocation',
8
- defaultValue: { uri: '/path/to/my.2bit' },
8
+ defaultValue: { uri: '/path/to/my.2bit', locationType: 'UriLocation' },
9
9
  },
10
10
  chromSizesLocation: {
11
11
  type: 'fileLocation',
12
- defaultValue: { uri: '/path/to/default.chrom.sizes' },
12
+ defaultValue: {
13
+ uri: '/path/to/default.chrom.sizes',
14
+ locationType: 'UriLocation',
15
+ },
13
16
  description:
14
17
  'An optional chrom.sizes file can be supplied to speed up loading since parsing the twobit file can take time',
15
18
  },
package/src/index.ts CHANGED
@@ -6,6 +6,8 @@ import TrackType from '@jbrowse/core/pluggableElementTypes/TrackType'
6
6
  import Plugin from '@jbrowse/core/Plugin'
7
7
  import PluginManager from '@jbrowse/core/PluginManager'
8
8
  import { BaseLinearDisplayComponent } from '@jbrowse/plugin-linear-genome-view'
9
+ import { FileLocation } from '@jbrowse/core/util/types'
10
+ import { makeIndex } from '@jbrowse/core/util/tracks'
9
11
  import { configSchema as bgzipFastaAdapterConfigSchema } from './BgzipFastaAdapter'
10
12
  import { configSchema as chromSizesAdapterConfigSchema } from './ChromSizesAdapter'
11
13
  import {
@@ -20,6 +22,11 @@ import {
20
22
  import { configSchema as twoBitAdapterConfigSchema } from './TwoBitAdapter'
21
23
  import GCContentAdapterF from './GCContentAdapter'
22
24
  import { createReferenceSeqTrackConfig } from './referenceSeqTrackConfig'
25
+ import {
26
+ AdapterGuesser,
27
+ getFileName,
28
+ TrackTypeGuesser,
29
+ } from '@jbrowse/core/util/tracks'
23
30
 
24
31
  /* adjust in both directions */
25
32
  class DivSequenceRenderer extends FeatureRendererType {
@@ -43,16 +50,60 @@ export default class SequencePlugin extends Plugin {
43
50
  new AdapterType({
44
51
  name: 'TwoBitAdapter',
45
52
  configSchema: twoBitAdapterConfigSchema,
53
+ adapterMetadata: {
54
+ category: null,
55
+ hiddenFromGUI: true,
56
+ displayName: null,
57
+ description: null,
58
+ },
46
59
  getAdapterClass: () =>
47
60
  import('./TwoBitAdapter/TwoBitAdapter').then(r => r.default),
48
61
  }),
49
62
  )
63
+ pluginManager.addToExtensionPoint(
64
+ 'Core-guessAdapterForLocation',
65
+ (adapterGuesser: AdapterGuesser) => {
66
+ return (
67
+ file: FileLocation,
68
+ index?: FileLocation,
69
+ adapterHint?: string,
70
+ ) => {
71
+ const regexGuess = /\.2bit$/i
72
+ const adapterName = 'TwoBitAdapter'
73
+ const fileName = getFileName(file)
74
+ if (regexGuess.test(fileName) || adapterHint === adapterName) {
75
+ return {
76
+ type: adapterName,
77
+ twoBitLocation: file,
78
+ }
79
+ }
80
+ return adapterGuesser(file, index, adapterHint)
81
+ }
82
+ },
83
+ )
84
+ pluginManager.addToExtensionPoint(
85
+ 'Core-guessTrackTypeForLocation',
86
+ (trackTypeGuesser: TrackTypeGuesser) => {
87
+ return (adapterName: string) => {
88
+ if (adapterName === 'TwoBitAdapter') {
89
+ return 'ReferenceSequenceTrack'
90
+ }
91
+ return trackTypeGuesser(adapterName)
92
+ }
93
+ },
94
+ )
50
95
 
51
96
  pluginManager.addAdapterType(
52
97
  () =>
53
98
  new AdapterType({
54
99
  name: 'ChromSizesAdapter',
55
100
  configSchema: chromSizesAdapterConfigSchema,
101
+ adapterMetadata: {
102
+ category: null,
103
+ hiddenFromGUI: true,
104
+ displayName: null,
105
+ description: null,
106
+ },
56
107
  getAdapterClass: () =>
57
108
  import('./ChromSizesAdapter/ChromSizesAdapter').then(
58
109
  r => r.default,
@@ -65,18 +116,63 @@ export default class SequencePlugin extends Plugin {
65
116
  new AdapterType({
66
117
  name: 'IndexedFastaAdapter',
67
118
  configSchema: indexedFastaAdapterConfigSchema,
119
+ adapterMetadata: {
120
+ category: null,
121
+ hiddenFromGUI: true,
122
+ displayName: null,
123
+ description: null,
124
+ },
68
125
  getAdapterClass: () =>
69
126
  import('./IndexedFastaAdapter/IndexedFastaAdapter').then(
70
127
  r => r.default,
71
128
  ),
72
129
  }),
73
130
  )
131
+ pluginManager.addToExtensionPoint(
132
+ 'Core-guessAdapterForLocation',
133
+ (adapterGuesser: AdapterGuesser) => {
134
+ return (
135
+ file: FileLocation,
136
+ index?: FileLocation,
137
+ adapterHint?: string,
138
+ ) => {
139
+ const regexGuess = /\.(fa|fasta|fas|fna|mfa)$/i
140
+ const adapterName = 'IndexedFastaAdapter'
141
+ const fileName = getFileName(file)
142
+ if (regexGuess.test(fileName) || adapterHint === adapterName) {
143
+ return {
144
+ type: adapterName,
145
+ fastaLocation: file,
146
+ faiLocation: index || makeIndex(file, '.fai'),
147
+ }
148
+ }
149
+ return adapterGuesser(file, index, adapterHint)
150
+ }
151
+ },
152
+ )
153
+ pluginManager.addToExtensionPoint(
154
+ 'Core-guessTrackTypeForLocation',
155
+ (trackTypeGuesser: TrackTypeGuesser) => {
156
+ return (adapterName: string) => {
157
+ if (adapterName === 'IndexedFastaAdapter') {
158
+ return 'ReferenceSequenceTrack'
159
+ }
160
+ return trackTypeGuesser(adapterName)
161
+ }
162
+ },
163
+ )
74
164
 
75
165
  pluginManager.addAdapterType(
76
166
  () =>
77
167
  new AdapterType({
78
168
  name: 'BgzipFastaAdapter',
79
169
  configSchema: bgzipFastaAdapterConfigSchema,
170
+ adapterMetadata: {
171
+ category: null,
172
+ hiddenFromGUI: true,
173
+ displayName: null,
174
+ description: null,
175
+ },
80
176
  getAdapterClass: () =>
81
177
  import('./BgzipFastaAdapter/BgzipFastaAdapter').then(
82
178
  r => r.default,
@@ -84,10 +180,50 @@ export default class SequencePlugin extends Plugin {
84
180
  }),
85
181
  )
86
182
 
183
+ pluginManager.addToExtensionPoint(
184
+ 'Core-guessAdapterForLocation',
185
+ (adapterGuesser: AdapterGuesser) => {
186
+ return (
187
+ file: FileLocation,
188
+ index?: FileLocation,
189
+ adapterHint?: string,
190
+ ) => {
191
+ const regexGuess = /\.(fa|fasta|fas|fna|mfa)\.b?gz$/i
192
+ const adapterName = 'BgzipFastaAdapter'
193
+ const fileName = getFileName(file)
194
+ if (regexGuess.test(fileName) || adapterHint === adapterName) {
195
+ return {
196
+ type: adapterName,
197
+ faiLocation: makeIndex(file, '.fai'),
198
+ gziLocation: makeIndex(file, '.gzi'),
199
+ }
200
+ }
201
+ return adapterGuesser(file, index, adapterHint)
202
+ }
203
+ },
204
+ )
205
+ pluginManager.addToExtensionPoint(
206
+ 'Core-guessTrackTypeForLocation',
207
+ (trackTypeGuesser: TrackTypeGuesser) => {
208
+ return (adapterName: string) => {
209
+ if (adapterName === 'BgzipFastaAdapter') {
210
+ return 'ReferenceSequenceTrack'
211
+ }
212
+ return trackTypeGuesser(adapterName)
213
+ }
214
+ },
215
+ )
216
+
87
217
  pluginManager.addAdapterType(
88
218
  () =>
89
219
  new AdapterType({
90
220
  name: 'GCContentAdapter',
221
+ adapterMetadata: {
222
+ category: null,
223
+ hiddenFromGUI: true,
224
+ displayName: null,
225
+ description: null,
226
+ },
91
227
  ...pluginManager.load(GCContentAdapterF),
92
228
  }),
93
229
  )