@jbrowse/plugin-legacy-jbrowse 2.6.1 → 2.6.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/dist/GuessNCList/index.js +0 -1
- package/dist/JBrowse1Connection/configSchema.js +0 -1
- package/dist/JBrowse1Connection/index.js +0 -1
- package/dist/JBrowse1Connection/jb1ConfigLoad.js +0 -1
- package/dist/JBrowse1Connection/jb1ConfigParse.js +0 -1
- package/dist/JBrowse1Connection/jb1ToJb2.js +0 -1
- package/dist/JBrowse1Connection/model.js +0 -1
- package/dist/JBrowse1Connection/types.js +0 -1
- package/dist/JBrowse1Connection/util.js +0 -1
- package/dist/JBrowse1TextSearchAdapter/HttpMap.js +0 -1
- package/dist/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.js +0 -1
- package/dist/JBrowse1TextSearchAdapter/configSchema.js +0 -1
- package/dist/JBrowse1TextSearchAdapter/index.js +0 -1
- package/dist/NCListAdapter/NCListAdapter.js +0 -1
- package/dist/NCListAdapter/NCListFeature.js +0 -1
- package/dist/NCListAdapter/configSchema.js +0 -1
- package/dist/NCListAdapter/index.js +0 -1
- package/dist/index.js +0 -1
- package/esm/GuessNCList/index.js +0 -1
- package/esm/JBrowse1Connection/configSchema.js +0 -1
- package/esm/JBrowse1Connection/index.js +0 -1
- package/esm/JBrowse1Connection/jb1ConfigLoad.js +0 -1
- package/esm/JBrowse1Connection/jb1ConfigParse.js +0 -1
- package/esm/JBrowse1Connection/jb1ToJb2.js +0 -1
- package/esm/JBrowse1Connection/model.js +0 -1
- package/esm/JBrowse1Connection/types.js +0 -1
- package/esm/JBrowse1Connection/util.js +0 -1
- package/esm/JBrowse1TextSearchAdapter/HttpMap.js +0 -1
- package/esm/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.js +0 -1
- package/esm/JBrowse1TextSearchAdapter/configSchema.js +0 -1
- package/esm/JBrowse1TextSearchAdapter/index.js +0 -1
- package/esm/NCListAdapter/NCListAdapter.js +0 -1
- package/esm/NCListAdapter/NCListFeature.js +0 -1
- package/esm/NCListAdapter/configSchema.js +0 -1
- package/esm/NCListAdapter/index.js +0 -1
- package/esm/index.js +0 -1
- package/package.json +3 -4
- package/dist/GuessNCList/index.js.map +0 -1
- package/dist/JBrowse1Connection/configSchema.js.map +0 -1
- package/dist/JBrowse1Connection/index.js.map +0 -1
- package/dist/JBrowse1Connection/jb1ConfigLoad.js.map +0 -1
- package/dist/JBrowse1Connection/jb1ConfigParse.js.map +0 -1
- package/dist/JBrowse1Connection/jb1ToJb2.js.map +0 -1
- package/dist/JBrowse1Connection/model.js.map +0 -1
- package/dist/JBrowse1Connection/types.js.map +0 -1
- package/dist/JBrowse1Connection/util.js.map +0 -1
- package/dist/JBrowse1TextSearchAdapter/HttpMap.js.map +0 -1
- package/dist/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.js.map +0 -1
- package/dist/JBrowse1TextSearchAdapter/configSchema.js.map +0 -1
- package/dist/JBrowse1TextSearchAdapter/index.js.map +0 -1
- package/dist/NCListAdapter/NCListAdapter.js.map +0 -1
- package/dist/NCListAdapter/NCListFeature.js.map +0 -1
- package/dist/NCListAdapter/configSchema.js.map +0 -1
- package/dist/NCListAdapter/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/esm/GuessNCList/index.js.map +0 -1
- package/esm/JBrowse1Connection/configSchema.js.map +0 -1
- package/esm/JBrowse1Connection/index.js.map +0 -1
- package/esm/JBrowse1Connection/jb1ConfigLoad.js.map +0 -1
- package/esm/JBrowse1Connection/jb1ConfigParse.js.map +0 -1
- package/esm/JBrowse1Connection/jb1ToJb2.js.map +0 -1
- package/esm/JBrowse1Connection/model.js.map +0 -1
- package/esm/JBrowse1Connection/types.js.map +0 -1
- package/esm/JBrowse1Connection/util.js.map +0 -1
- package/esm/JBrowse1TextSearchAdapter/HttpMap.js.map +0 -1
- package/esm/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.js.map +0 -1
- package/esm/JBrowse1TextSearchAdapter/configSchema.js.map +0 -1
- package/esm/JBrowse1TextSearchAdapter/index.js.map +0 -1
- package/esm/NCListAdapter/NCListAdapter.js.map +0 -1
- package/esm/NCListAdapter/NCListFeature.js.map +0 -1
- package/esm/NCListAdapter/configSchema.js.map +0 -1
- package/esm/NCListAdapter/index.js.map +0 -1
- package/esm/index.js.map +0 -1
- package/src/GuessNCList/index.ts +0 -27
- package/src/JBrowse1Connection/configSchema.ts +0 -42
- package/src/JBrowse1Connection/index.ts +0 -20
- package/src/JBrowse1Connection/jb1ConfigLoad.ts +0 -342
- package/src/JBrowse1Connection/jb1ConfigParse.ts +0 -423
- package/src/JBrowse1Connection/jb1ToJb2.ts +0 -529
- package/src/JBrowse1Connection/model.tsx +0 -69
- package/src/JBrowse1Connection/types.ts +0 -105
- package/src/JBrowse1Connection/util.ts +0 -149
- package/src/JBrowse1TextSearchAdapter/HttpMap.test.ts +0 -49
- package/src/JBrowse1TextSearchAdapter/HttpMap.ts +0 -100
- package/src/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.test.ts +0 -101
- package/src/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.ts +0 -100
- package/src/JBrowse1TextSearchAdapter/configSchema.ts +0 -44
- package/src/JBrowse1TextSearchAdapter/index.ts +0 -18
- package/src/NCListAdapter/NCListAdapter.test.ts +0 -58
- package/src/NCListAdapter/NCListAdapter.ts +0 -92
- package/src/NCListAdapter/NCListFeature.ts +0 -94
- package/src/NCListAdapter/__snapshots__/NCListAdapter.test.ts.snap +0 -30671
- package/src/NCListAdapter/configSchema.ts +0 -32
- package/src/NCListAdapter/index.ts +0 -16
- package/src/__snapshots__/index.test.ts.snap +0 -16
- package/src/index.test.ts +0 -35
- package/src/index.ts +0 -17
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import getValue from 'get-value'
|
|
2
|
-
import { Track, Source } from './types'
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
export function isTrack(arg: any): arg is Track {
|
|
6
|
-
return arg && arg.label && typeof arg.label === 'string'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
export function isSource(arg: any): arg is Source {
|
|
11
|
-
return arg && arg.url && typeof arg.url === 'string'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* updates a with values from b, recursively
|
|
16
|
-
*/
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
-
type Obj = Record<string, any>
|
|
19
|
-
export function deepUpdate(a: Obj, b: Obj): Obj {
|
|
20
|
-
for (const prop of Object.keys(b)) {
|
|
21
|
-
if (
|
|
22
|
-
prop in a &&
|
|
23
|
-
typeof b[prop] === 'object' &&
|
|
24
|
-
typeof a[prop] === 'object'
|
|
25
|
-
) {
|
|
26
|
-
deepUpdate(a[prop], b[prop])
|
|
27
|
-
} else if (a[prop] === undefined || b[prop] !== undefined) {
|
|
28
|
-
a[prop] = b[prop]
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return a
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* replace variables in a template string with values
|
|
36
|
-
*
|
|
37
|
-
* @param template - String with variable names in curly brackets
|
|
38
|
-
* e.g., `http://foo/{bar}?arg={baz.foo}`
|
|
39
|
-
* @param fillWith - object with attribute-value mappings
|
|
40
|
-
* e.g., `{ 'bar': 'someurl', 'baz': { 'foo': 42 } }`
|
|
41
|
-
* @returns the template string with variables in fillWith replaced
|
|
42
|
-
* e.g., 'htp://foo/someurl?arg=valueforbaz'
|
|
43
|
-
*/
|
|
44
|
-
export function fillTemplate(template: string, fillWith: Obj): string {
|
|
45
|
-
return template.replaceAll(/{([\s\w.]+)}/g, (match, varName) => {
|
|
46
|
-
varName = varName.replaceAll(/\s+/g, '')
|
|
47
|
-
const fill = getValue(fillWith, varName)
|
|
48
|
-
if (fill !== undefined) {
|
|
49
|
-
return typeof fill === 'function' ? fill(varName) : fill
|
|
50
|
-
}
|
|
51
|
-
if (fillWith.callback) {
|
|
52
|
-
// @ts-expect-error
|
|
53
|
-
const v = fillWith.callback.call(this, varName)
|
|
54
|
-
if (v !== undefined) {
|
|
55
|
-
return v
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return match
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Clones objects (including DOM nodes) and all children.
|
|
64
|
-
* Warning: do not clone cyclic structures
|
|
65
|
-
* (Lifted from dojo https://github.com/dojo/dojo/blob/master/_base/lang.js)
|
|
66
|
-
* @param src - The object to clone
|
|
67
|
-
*/
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
-
export function clone(src: any): any {
|
|
70
|
-
if (
|
|
71
|
-
!src ||
|
|
72
|
-
typeof src !== 'object' ||
|
|
73
|
-
Object.prototype.toString.call(src) === '[object Function]'
|
|
74
|
-
) {
|
|
75
|
-
// null, undefined, any non-object, or function
|
|
76
|
-
return src // anything
|
|
77
|
-
}
|
|
78
|
-
if (src.nodeType && 'cloneNode' in src) {
|
|
79
|
-
// DOM Node
|
|
80
|
-
return src.cloneNode(true) // Node
|
|
81
|
-
}
|
|
82
|
-
if (src instanceof Date) {
|
|
83
|
-
// Date
|
|
84
|
-
return new Date(src.getTime()) // Date
|
|
85
|
-
}
|
|
86
|
-
if (src instanceof RegExp) {
|
|
87
|
-
// RegExp
|
|
88
|
-
return new RegExp(src) // RegExp
|
|
89
|
-
}
|
|
90
|
-
let r
|
|
91
|
-
let i
|
|
92
|
-
let l
|
|
93
|
-
if (Array.isArray(src)) {
|
|
94
|
-
// array
|
|
95
|
-
r = []
|
|
96
|
-
for (i = 0, l = src.length; i < l; ++i) {
|
|
97
|
-
if (i in src) {
|
|
98
|
-
r[i] = clone(src[i])
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
// we don't clone functions for performance reasons
|
|
102
|
-
// }else if(d.isFunction(src)){
|
|
103
|
-
// // function
|
|
104
|
-
// r = function(){ return src.apply(this, arguments); };
|
|
105
|
-
} else {
|
|
106
|
-
// generic objects
|
|
107
|
-
r = src.constructor ? new src.constructor() : {}
|
|
108
|
-
}
|
|
109
|
-
return mixin(r, src, clone)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Copies/adds all properties of source to dest; returns dest.
|
|
114
|
-
* (Lifted from dojo https://github.com/dojo/dojo/blob/master/_base/lang.js)
|
|
115
|
-
*
|
|
116
|
-
* All properties, including functions (sometimes termed "methods"), excluding
|
|
117
|
-
* any non-standard extensions found in Object.prototype, are copied/added to
|
|
118
|
-
* dest. Copying/adding each particular property is delegated to copyFunc
|
|
119
|
-
* (if any); copyFunc defaults to the Javascript assignment operator if not
|
|
120
|
-
* provided. Notice that by default, mixin executes a so-called "shallow copy"
|
|
121
|
-
* and aggregate types are copied/added by reference.
|
|
122
|
-
* @param dest - The object to which to copy/add all properties contained in
|
|
123
|
-
* source.
|
|
124
|
-
* @param source - The object from which to draw all properties to copy into dest.
|
|
125
|
-
* @param copyFunc - The process used to copy/add a property in source; defaults
|
|
126
|
-
* to the Javascript assignment operator.
|
|
127
|
-
* @returns dest, as modified
|
|
128
|
-
*/
|
|
129
|
-
function mixin(dest: Obj, source: Obj, copyFunc: Function): Obj {
|
|
130
|
-
let name
|
|
131
|
-
let s
|
|
132
|
-
const empty = {}
|
|
133
|
-
for (name in source) {
|
|
134
|
-
// the (!(name in empty) || empty[name] !== s) condition avoids copying
|
|
135
|
-
// properties in "source" inherited from Object.prototype. For example,
|
|
136
|
-
// if dest has a custom toString() method, don't overwrite it with the
|
|
137
|
-
// toString() method that source inherited from Object.prototype
|
|
138
|
-
s = source[name]
|
|
139
|
-
if (
|
|
140
|
-
!(name in dest) ||
|
|
141
|
-
// @ts-expect-error
|
|
142
|
-
(dest[name] !== s && (!(name in empty) || empty[name] !== s))
|
|
143
|
-
) {
|
|
144
|
-
dest[name] = copyFunc ? copyFunc(s) : s
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return dest // Object
|
|
149
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import meta from '../../test_data/names/meta.json'
|
|
3
|
-
import first from '../../test_data/names/0.json'
|
|
4
|
-
import last from '../../test_data/names/f.json'
|
|
5
|
-
import HttpMap from './HttpMap'
|
|
6
|
-
|
|
7
|
-
test('read from meta', async () => {
|
|
8
|
-
const rootTemplate = path
|
|
9
|
-
.join(__dirname, '..', '..', '..', '..', 'test_data', 'names')
|
|
10
|
-
.replaceAll('\\', '\\\\')
|
|
11
|
-
|
|
12
|
-
jest.spyOn(global, 'fetch').mockImplementation(url => {
|
|
13
|
-
const response = `${url}`.includes('names/meta.json') ? meta : {}
|
|
14
|
-
return Promise.resolve(new Response(JSON.stringify(response)))
|
|
15
|
-
})
|
|
16
|
-
const hashMap = new HttpMap({ url: rootTemplate })
|
|
17
|
-
await hashMap.getBucket('apple')
|
|
18
|
-
|
|
19
|
-
// test compress and hash hex characters are set after initial search
|
|
20
|
-
expect(await hashMap.getHashHexCharacters()).toBe(1)
|
|
21
|
-
expect(await hashMap.getCompress()).toBe(0)
|
|
22
|
-
})
|
|
23
|
-
test('get bucket contents', async () => {
|
|
24
|
-
const rootTemplate = path
|
|
25
|
-
.join(__dirname, '..', '..', '..', '..', 'test_data', 'names')
|
|
26
|
-
.replaceAll('\\', '\\\\')
|
|
27
|
-
|
|
28
|
-
const spy = jest.spyOn(global, 'fetch')
|
|
29
|
-
spy.mockImplementation(url => {
|
|
30
|
-
let response = {}
|
|
31
|
-
if (`${url}`.includes('names/meta.json')) {
|
|
32
|
-
response = meta
|
|
33
|
-
}
|
|
34
|
-
if (`${url}`.includes('names/0.json')) {
|
|
35
|
-
response = first
|
|
36
|
-
}
|
|
37
|
-
if (`${url}`.includes('names/f.json')) {
|
|
38
|
-
response = last
|
|
39
|
-
}
|
|
40
|
-
return Promise.resolve(new Response(JSON.stringify(response)))
|
|
41
|
-
})
|
|
42
|
-
const hashMap = new HttpMap({ url: rootTemplate })
|
|
43
|
-
|
|
44
|
-
await hashMap.getBucket('apple')
|
|
45
|
-
expect(spy).toHaveBeenLastCalledWith(`${rootTemplate}/0.json`)
|
|
46
|
-
|
|
47
|
-
await hashMap.getBucket('apple3')
|
|
48
|
-
expect(spy).toHaveBeenLastCalledWith(`${rootTemplate}/f.json`)
|
|
49
|
-
})
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper class allows reading names index generated in JBrowse1
|
|
3
|
-
* Adapted from https://github.com/GMOD/jbrowse/blob/master/src/JBrowse/Store/Hash.js
|
|
4
|
-
*/
|
|
5
|
-
import crc32 from 'buffer-crc32'
|
|
6
|
-
|
|
7
|
-
export default class HttpMap {
|
|
8
|
-
url: string
|
|
9
|
-
|
|
10
|
-
constructor(args: { url: string }) {
|
|
11
|
-
// make sure url has a trailing slash
|
|
12
|
-
this.url = /\/$/.test(args.url) ? args.url : `${args.url}/`
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* loads meta.json file from names directory and reads number of hash_bits used
|
|
17
|
-
*/
|
|
18
|
-
async readMeta() {
|
|
19
|
-
const meta = await this.loadFile('meta.json')
|
|
20
|
-
const { compress, track_names: tracks } = meta
|
|
21
|
-
const hashHexCharacters = Math.ceil(meta.hash_bits / 4)
|
|
22
|
-
return { hashHexCharacters, compress, tracks }
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async getHashHexCharacters() {
|
|
26
|
-
const meta = await this.readMeta()
|
|
27
|
-
return meta.hashHexCharacters
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async getCompress() {
|
|
31
|
-
const meta = await this.readMeta()
|
|
32
|
-
return meta.compress
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async getTrackNames() {
|
|
36
|
-
const meta = await this.readMeta()
|
|
37
|
-
return meta.tracks
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Returns contents of a bucket given a key
|
|
42
|
-
* @param key - string
|
|
43
|
-
*/
|
|
44
|
-
async get(key: string) {
|
|
45
|
-
const bucket = await this.getBucket(key)
|
|
46
|
-
return bucket[key]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Returns a bucket given a key
|
|
51
|
-
* @param key - string
|
|
52
|
-
*/
|
|
53
|
-
async getBucket(key: string) {
|
|
54
|
-
const bucketIdent = this.hash(key)
|
|
55
|
-
const hexToDirPath = await this.hexToDirPath(bucketIdent)
|
|
56
|
-
return this.loadFile(hexToDirPath)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Loads a file using the url and provided id.
|
|
61
|
-
* Returns response object with contents of the file
|
|
62
|
-
* @param id - string
|
|
63
|
-
*/
|
|
64
|
-
async loadFile(id: string) {
|
|
65
|
-
const response = await fetch(`${this.url}${id}`)
|
|
66
|
-
if (!response.ok) {
|
|
67
|
-
throw new Error(`HTTP ${response.status} ${response.statusText}`)
|
|
68
|
-
}
|
|
69
|
-
return response.json()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Returns the corresponding path of the file given a hex string
|
|
74
|
-
* @param hex - hex string
|
|
75
|
-
*/
|
|
76
|
-
async hexToDirPath(hex: string) {
|
|
77
|
-
// zero-pad the hex string to be 8 chars if necessary
|
|
78
|
-
const hashHexCharacters = await this.getHashHexCharacters()
|
|
79
|
-
if (hashHexCharacters) {
|
|
80
|
-
const compress = await this.getCompress()
|
|
81
|
-
while (hex.length < 8) {
|
|
82
|
-
hex = `0${hex}`
|
|
83
|
-
}
|
|
84
|
-
hex = hex.slice(8 - hashHexCharacters)
|
|
85
|
-
const dirpath = []
|
|
86
|
-
for (let i = 0; i < hex.length; i += 3) {
|
|
87
|
-
dirpath.push(hex.slice(i, i + 3))
|
|
88
|
-
}
|
|
89
|
-
return `${dirpath.join('/')}.json${compress ? 'z' : ''}`
|
|
90
|
-
}
|
|
91
|
-
return ''
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
hash(data: string) {
|
|
95
|
-
return crc32(Buffer.from(data))
|
|
96
|
-
.toString('hex')
|
|
97
|
-
.toLowerCase()
|
|
98
|
-
.replace('-', 'n')
|
|
99
|
-
}
|
|
100
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import BaseResult from '@jbrowse/core/TextSearch/BaseResults'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import meta from '../../test_data/names/meta.json'
|
|
4
|
-
import first from '../../test_data/names/0.json'
|
|
5
|
-
import last from '../../test_data/names/f.json'
|
|
6
|
-
import Adapter from './JBrowse1TextSearchAdapter'
|
|
7
|
-
import configSchema from './configSchema'
|
|
8
|
-
|
|
9
|
-
function mockFetch(url: RequestInfo | URL) {
|
|
10
|
-
let response = {}
|
|
11
|
-
if (`${url}`.includes('names/meta.json')) {
|
|
12
|
-
response = meta
|
|
13
|
-
}
|
|
14
|
-
if (`${url}`.includes('names/0.json')) {
|
|
15
|
-
response = first
|
|
16
|
-
}
|
|
17
|
-
if (`${url}`.includes('names/f.json')) {
|
|
18
|
-
response = last
|
|
19
|
-
}
|
|
20
|
-
return Promise.resolve(new Response(JSON.stringify(response)))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const rootTemplate = path
|
|
24
|
-
.join(__dirname, '..', '..', '..', '..', 'test_data', 'names')
|
|
25
|
-
.replaceAll('\\', '\\\\')
|
|
26
|
-
|
|
27
|
-
test('search upper case', async () => {
|
|
28
|
-
const spy = jest.spyOn(global, 'fetch')
|
|
29
|
-
spy.mockImplementation(mockFetch)
|
|
30
|
-
|
|
31
|
-
const adapter = new Adapter(
|
|
32
|
-
configSchema.create({
|
|
33
|
-
type: 'JBrowse1TextSearchAdapter',
|
|
34
|
-
textSearchAdapterId: 'JBrowse1GenerateNamesAdapterTest',
|
|
35
|
-
namesIndexLocation: {
|
|
36
|
-
uri: decodeURI(new URL(`file://${rootTemplate}`).href),
|
|
37
|
-
locationType: 'UriLocation',
|
|
38
|
-
},
|
|
39
|
-
}),
|
|
40
|
-
)
|
|
41
|
-
const results = await adapter.searchIndex({
|
|
42
|
-
searchType: 'prefix',
|
|
43
|
-
queryString: 'Apple',
|
|
44
|
-
})
|
|
45
|
-
// check results are of type BaseResult for prefix search
|
|
46
|
-
expect(results.length).toBeGreaterThan(0)
|
|
47
|
-
expect(results[0] instanceof BaseResult).toBeTruthy()
|
|
48
|
-
expect(results[0].getLabel()).toEqual('Apple1')
|
|
49
|
-
expect(results[1].getLabel()).toEqual('Apple2')
|
|
50
|
-
expect(results[2].getLabel()).toEqual('Apple3')
|
|
51
|
-
|
|
52
|
-
// exact search
|
|
53
|
-
const results2 = await adapter.searchIndex({
|
|
54
|
-
searchType: 'exact',
|
|
55
|
-
queryString: 'Apple3',
|
|
56
|
-
})
|
|
57
|
-
// check results are of type location for exact search
|
|
58
|
-
expect(results2.length).toEqual(5)
|
|
59
|
-
expect(results2.length).toBeGreaterThan(0)
|
|
60
|
-
expect(results2[0] instanceof BaseResult).toBeTruthy()
|
|
61
|
-
expect(results2[0].getLabel()).toEqual('Apple3')
|
|
62
|
-
expect(results2[0].getLocation()).toEqual('ctgA:17399-23000')
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('search lower case', async () => {
|
|
66
|
-
const spy = jest.spyOn(global, 'fetch')
|
|
67
|
-
spy.mockImplementation(mockFetch)
|
|
68
|
-
|
|
69
|
-
const adapter = new Adapter(
|
|
70
|
-
configSchema.create({
|
|
71
|
-
type: 'JBrowse1TextSearchAdapter',
|
|
72
|
-
textSearchAdapterId: 'JBrowse1GenerateNamesAdapterTest',
|
|
73
|
-
namesIndexLocation: {
|
|
74
|
-
uri: decodeURI(new URL(`file://${rootTemplate}`).href),
|
|
75
|
-
locationType: 'UriLocation',
|
|
76
|
-
},
|
|
77
|
-
}),
|
|
78
|
-
)
|
|
79
|
-
const results = await adapter.searchIndex({
|
|
80
|
-
searchType: 'prefix',
|
|
81
|
-
queryString: 'apple',
|
|
82
|
-
})
|
|
83
|
-
// check results are of type BaseResult for prefix search
|
|
84
|
-
expect(results.length).toBeGreaterThan(0)
|
|
85
|
-
expect(results[0] instanceof BaseResult).toBeTruthy()
|
|
86
|
-
expect(results[0].getLabel()).toEqual('Apple1')
|
|
87
|
-
expect(results[1].getLabel()).toEqual('Apple2')
|
|
88
|
-
expect(results[2].getLabel()).toEqual('Apple3')
|
|
89
|
-
|
|
90
|
-
// exact search
|
|
91
|
-
const results2 = await adapter.searchIndex({
|
|
92
|
-
searchType: 'exact',
|
|
93
|
-
queryString: 'apple3',
|
|
94
|
-
})
|
|
95
|
-
// check results are of type location for exact search
|
|
96
|
-
expect(results2.length).toEqual(5)
|
|
97
|
-
expect(results2.length).toBeGreaterThan(0)
|
|
98
|
-
expect(results2[0] instanceof BaseResult).toBeTruthy()
|
|
99
|
-
expect(results2[0].getLabel()).toEqual('Apple3')
|
|
100
|
-
expect(results2[0].getLocation()).toEqual('ctgA:17399-23000')
|
|
101
|
-
})
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseTextSearchAdapter,
|
|
3
|
-
BaseTextSearchArgs,
|
|
4
|
-
BaseAdapter,
|
|
5
|
-
} from '@jbrowse/core/data_adapters/BaseAdapter'
|
|
6
|
-
import BaseResult from '@jbrowse/core/TextSearch/BaseResults'
|
|
7
|
-
import {
|
|
8
|
-
AnyConfigurationModel,
|
|
9
|
-
readConfObject,
|
|
10
|
-
} from '@jbrowse/core/configuration'
|
|
11
|
-
import HttpMap from './HttpMap'
|
|
12
|
-
import PluginManager from '@jbrowse/core/PluginManager'
|
|
13
|
-
import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'
|
|
14
|
-
|
|
15
|
-
export interface TooManyHits {
|
|
16
|
-
name: string
|
|
17
|
-
hitLimit: number
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface SearchResults {
|
|
21
|
-
prefix: ({ name: string } | string)[]
|
|
22
|
-
exact: [string, number, string, string, number, number][]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type NamesIndexRecord = string | Array<string | number>
|
|
26
|
-
|
|
27
|
-
type IndexFile = Record<string, SearchResults>
|
|
28
|
-
|
|
29
|
-
// Uses index built by generate-names.pl
|
|
30
|
-
export default class JBrowse1TextSearchAdapter
|
|
31
|
-
extends BaseAdapter
|
|
32
|
-
implements BaseTextSearchAdapter
|
|
33
|
-
{
|
|
34
|
-
httpMap: HttpMap
|
|
35
|
-
|
|
36
|
-
tracksNames?: string[]
|
|
37
|
-
|
|
38
|
-
constructor(
|
|
39
|
-
config: AnyConfigurationModel,
|
|
40
|
-
getSubAdapter?: getSubAdapterType,
|
|
41
|
-
pluginManager?: PluginManager,
|
|
42
|
-
) {
|
|
43
|
-
super(config, getSubAdapter, pluginManager)
|
|
44
|
-
const namesIndex = readConfObject(config, 'namesIndexLocation')
|
|
45
|
-
const { baseUri, uri } = namesIndex
|
|
46
|
-
this.httpMap = new HttpMap({
|
|
47
|
-
url: baseUri ? new URL(uri, baseUri).href : uri,
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Returns the contents of the file containing the query if it exists
|
|
53
|
-
* else it returns empty
|
|
54
|
-
* @param query - string query
|
|
55
|
-
*/
|
|
56
|
-
async loadIndexFile(query: string): Promise<IndexFile> {
|
|
57
|
-
return this.httpMap.getBucket(query)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async searchIndex(args: BaseTextSearchArgs) {
|
|
61
|
-
const { searchType, queryString } = args
|
|
62
|
-
const tracks = this.tracksNames || (await this.httpMap.getTrackNames())
|
|
63
|
-
const str = queryString.toLowerCase()
|
|
64
|
-
const entries = await this.loadIndexFile(str)
|
|
65
|
-
return entries[str]
|
|
66
|
-
? this.formatResults(entries[str], tracks, searchType)
|
|
67
|
-
: []
|
|
68
|
-
}
|
|
69
|
-
formatResults(results: SearchResults, tracks: string[], searchType?: string) {
|
|
70
|
-
return [
|
|
71
|
-
...(searchType === 'exact'
|
|
72
|
-
? []
|
|
73
|
-
: results.prefix.map(
|
|
74
|
-
result =>
|
|
75
|
-
new BaseResult({
|
|
76
|
-
label: typeof result === 'object' ? result.name : result,
|
|
77
|
-
matchedAttribute: 'name',
|
|
78
|
-
matchedObject: { result: result },
|
|
79
|
-
}),
|
|
80
|
-
)),
|
|
81
|
-
...results.exact.map(result => {
|
|
82
|
-
const name = result[0]
|
|
83
|
-
const trackIndex = result[1]
|
|
84
|
-
const refName = result[3]
|
|
85
|
-
const start = result[4]
|
|
86
|
-
const end = result[5]
|
|
87
|
-
const locstring = `${refName || name}:${start}-${end}`
|
|
88
|
-
return new BaseResult({
|
|
89
|
-
locString: locstring,
|
|
90
|
-
label: name,
|
|
91
|
-
matchedAttribute: 'name',
|
|
92
|
-
matchedObject: result,
|
|
93
|
-
trackId: tracks[trackIndex],
|
|
94
|
-
})
|
|
95
|
-
}),
|
|
96
|
-
].filter(result => result.getLabel() !== 'too many matches')
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
freeResources() {}
|
|
100
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ConfigurationSchema } from '@jbrowse/core/configuration'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* #config JBrowse1TextSearchAdapter
|
|
5
|
-
* note: metadata about tracks and assemblies covered by text search adapter
|
|
6
|
-
*/
|
|
7
|
-
function x() {} // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
8
|
-
|
|
9
|
-
export default ConfigurationSchema(
|
|
10
|
-
'JBrowse1TextSearchAdapter',
|
|
11
|
-
{
|
|
12
|
-
/**
|
|
13
|
-
* #slot
|
|
14
|
-
*/
|
|
15
|
-
namesIndexLocation: {
|
|
16
|
-
type: 'fileLocation',
|
|
17
|
-
defaultValue: { uri: '/volvox/names', locationType: 'UriLocation' },
|
|
18
|
-
description: 'the location of the JBrowse1 names index data directory',
|
|
19
|
-
},
|
|
20
|
-
/**
|
|
21
|
-
* #slot
|
|
22
|
-
*/
|
|
23
|
-
tracks: {
|
|
24
|
-
type: 'stringArray',
|
|
25
|
-
defaultValue: [],
|
|
26
|
-
description: 'List of tracks covered by text search adapter',
|
|
27
|
-
},
|
|
28
|
-
/**
|
|
29
|
-
* #slot
|
|
30
|
-
*/
|
|
31
|
-
assemblyNames: {
|
|
32
|
-
type: 'stringArray',
|
|
33
|
-
defaultValue: [],
|
|
34
|
-
description: 'List of assemblies covered by text search adapter',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
explicitlyTyped: true,
|
|
39
|
-
/**
|
|
40
|
-
* #identifier
|
|
41
|
-
*/
|
|
42
|
-
explicitIdentifier: 'textSearchAdapterId',
|
|
43
|
-
},
|
|
44
|
-
)
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import PluginManager from '@jbrowse/core/PluginManager'
|
|
2
|
-
import TextSearchAdapterType from '@jbrowse/core/pluggableElementTypes/TextSearchAdapterType'
|
|
3
|
-
|
|
4
|
-
// locals
|
|
5
|
-
import AdapterClass from './JBrowse1TextSearchAdapter'
|
|
6
|
-
import configSchema from './configSchema'
|
|
7
|
-
|
|
8
|
-
export default (pluginManager: PluginManager) => {
|
|
9
|
-
pluginManager.addTextSearchAdapterType(
|
|
10
|
-
() =>
|
|
11
|
-
new TextSearchAdapterType({
|
|
12
|
-
name: 'JBrowse1TextSearchAdapter',
|
|
13
|
-
configSchema,
|
|
14
|
-
AdapterClass,
|
|
15
|
-
description: 'A JBrowse 1 text search adapter',
|
|
16
|
-
}),
|
|
17
|
-
)
|
|
18
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { toArray } from 'rxjs/operators'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import { LocalFile, GenericFilehandle } from 'generic-filehandle'
|
|
4
|
-
import { firstValueFrom } from 'rxjs'
|
|
5
|
-
import Adapter from './NCListAdapter'
|
|
6
|
-
import configSchema from './configSchema'
|
|
7
|
-
|
|
8
|
-
export function generateReadBuffer(
|
|
9
|
-
getFileFunction: (str: string) => GenericFilehandle,
|
|
10
|
-
) {
|
|
11
|
-
return (request: Request) => {
|
|
12
|
-
const file = getFileFunction(request.url)
|
|
13
|
-
return file.readFile('utf8')
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
// @ts-expect-error
|
|
19
|
-
fetch.resetMocks()
|
|
20
|
-
// @ts-expect-error
|
|
21
|
-
fetch.mockResponse(
|
|
22
|
-
generateReadBuffer(
|
|
23
|
-
(url: string) =>
|
|
24
|
-
new LocalFile(path.join(__dirname, `../../test_data/${url}`)),
|
|
25
|
-
),
|
|
26
|
-
)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test('adapter can fetch features from ensembl_genes test set', async () => {
|
|
30
|
-
const args = {
|
|
31
|
-
refNames: [],
|
|
32
|
-
rootUrlTemplate: {
|
|
33
|
-
uri: 'ensembl_genes/{refseq}/trackData.json',
|
|
34
|
-
locationType: 'UriLocation',
|
|
35
|
-
},
|
|
36
|
-
}
|
|
37
|
-
const adapter = new Adapter(configSchema.create(args))
|
|
38
|
-
|
|
39
|
-
const features = adapter.getFeatures({
|
|
40
|
-
assemblyName: 'volvox',
|
|
41
|
-
refName: '21',
|
|
42
|
-
start: 34960388,
|
|
43
|
-
end: 35960388,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const featArr = await firstValueFrom(features.pipe(toArray()))
|
|
47
|
-
expect(featArr[0].get('refName')).toBe('21')
|
|
48
|
-
expect(featArr[0].id()).toBe(`test-21,0,0,19,22,0`)
|
|
49
|
-
const featJson = featArr.map(f => f.toJSON())
|
|
50
|
-
expect(featJson.length).toEqual(94)
|
|
51
|
-
for (const feature of featJson) {
|
|
52
|
-
expect(feature).toMatchSnapshot({ uniqueId: expect.any(String) })
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
expect(await adapter.hasDataForRefName('ctgA')).toBe(false)
|
|
56
|
-
expect(await adapter.hasDataForRefName('21')).toBe(true)
|
|
57
|
-
expect(await adapter.hasDataForRefName('20')).toBe(false)
|
|
58
|
-
})
|