@jbrowse/plugin-legacy-jbrowse 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/dist/JBrowse1Connection/jb1ToJb2.d.ts +1 -0
- package/dist/JBrowse1Connection/types.d.ts +2 -0
- package/dist/JBrowse1TextSeachAdapter/HttpMap.d.ts +1 -15
- package/dist/JBrowse1TextSeachAdapter/JBrowse1TextSearchAdapter.d.ts +12 -8
- package/dist/NCListAdapter/NCListAdapter.d.ts +3 -1
- package/dist/plugin-legacy-jbrowse.cjs.development.js +334 -398
- package/dist/plugin-legacy-jbrowse.cjs.development.js.map +1 -1
- package/dist/plugin-legacy-jbrowse.cjs.production.min.js +1 -1
- package/dist/plugin-legacy-jbrowse.cjs.production.min.js.map +1 -1
- package/dist/plugin-legacy-jbrowse.esm.js +336 -399
- package/dist/plugin-legacy-jbrowse.esm.js.map +1 -1
- package/package.json +5 -3
- package/src/JBrowse1Connection/configSchema.ts +4 -1
- package/src/JBrowse1Connection/jb1ConfigLoad.ts +24 -27
- package/src/JBrowse1Connection/jb1ConfigParse.ts +10 -12
- package/src/JBrowse1Connection/jb1ToJb2.ts +93 -43
- package/src/JBrowse1Connection/types.ts +2 -0
- package/src/JBrowse1TextSeachAdapter/HttpMap.test.ts +8 -20
- package/src/JBrowse1TextSeachAdapter/HttpMap.ts +17 -75
- package/src/JBrowse1TextSeachAdapter/JBrowse1TextSearchAdapter.test.ts +2 -4
- package/src/JBrowse1TextSeachAdapter/JBrowse1TextSearchAdapter.ts +42 -58
- package/src/JBrowse1TextSeachAdapter/configSchema.ts +2 -2
- package/src/NCListAdapter/NCListAdapter.test.ts +4 -1
- package/src/NCListAdapter/NCListAdapter.ts +15 -8
- package/src/NCListAdapter/configSchema.ts +4 -1
- package/src/__snapshots__/index.test.js.snap +3 -0
- package/src/index.test.js +1 -0
- package/src/index.ts +23 -0
- package/dist/JBrowse1TextSeachAdapter/Crc32.d.ts +0 -19
- package/src/JBrowse1TextSeachAdapter/Crc32.test.ts +0 -21
- package/src/JBrowse1TextSeachAdapter/Crc32.ts +0 -77
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import BaseResult
|
|
2
|
-
LocStringResult,
|
|
3
|
-
} from '@jbrowse/core/TextSearch/BaseResults'
|
|
1
|
+
import BaseResult from '@jbrowse/core/TextSearch/BaseResults'
|
|
4
2
|
import path from 'path'
|
|
5
3
|
import meta from '../../test_data/names/meta.json'
|
|
6
4
|
import first from '../../test_data/names/0.json'
|
|
@@ -37,6 +35,7 @@ test('adapter can fetch files from names index', async () => {
|
|
|
37
35
|
textSearchAdapterId: 'JBrowse1GenerateNamesAdapterTest',
|
|
38
36
|
namesIndexLocation: {
|
|
39
37
|
uri: urlPath,
|
|
38
|
+
locationType: 'UriLocation',
|
|
40
39
|
},
|
|
41
40
|
}
|
|
42
41
|
// create adapter
|
|
@@ -61,6 +60,5 @@ test('adapter can fetch files from names index', async () => {
|
|
|
61
60
|
const test2 = results2[0]
|
|
62
61
|
expect(test2 instanceof BaseResult).toBeTruthy()
|
|
63
62
|
expect(test2.getLabel()).toEqual('Apple3')
|
|
64
|
-
expect(test2 instanceof LocStringResult).toBeTruthy()
|
|
65
63
|
expect(test2.getLocation()).toEqual('ctgA:17399-23000')
|
|
66
64
|
})
|
|
@@ -3,33 +3,42 @@ import {
|
|
|
3
3
|
BaseArgs,
|
|
4
4
|
BaseAdapter,
|
|
5
5
|
} from '@jbrowse/core/data_adapters/BaseAdapter'
|
|
6
|
-
import BaseResult
|
|
7
|
-
LocStringResult,
|
|
8
|
-
} from '@jbrowse/core/TextSearch/BaseResults'
|
|
9
|
-
import { isElectron } from '@jbrowse/core/util'
|
|
6
|
+
import BaseResult from '@jbrowse/core/TextSearch/BaseResults'
|
|
10
7
|
import { Instance } from 'mobx-state-tree'
|
|
11
8
|
import { readConfObject } from '@jbrowse/core/configuration'
|
|
12
9
|
import MyConfigSchema from './configSchema'
|
|
13
10
|
import HttpMap from './HttpMap'
|
|
11
|
+
import PluginManager from '@jbrowse/core/PluginManager'
|
|
12
|
+
import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'
|
|
14
13
|
|
|
15
14
|
export interface TooManyHits {
|
|
16
15
|
name: string
|
|
17
16
|
hitLimit: number
|
|
18
17
|
}
|
|
18
|
+
|
|
19
|
+
interface SearchResults {
|
|
20
|
+
prefix: ({ name: string } | string)[]
|
|
21
|
+
exact: [string, number, string, string, number, number][]
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
export type NamesIndexRecord = string | Array<string | number>
|
|
25
|
+
|
|
26
|
+
// Jbrowse1 text search adapter
|
|
27
|
+
// Uses index built by generate-names.pl
|
|
20
28
|
export default class JBrowse1TextSearchAdapter
|
|
21
29
|
extends BaseAdapter
|
|
22
|
-
implements BaseTextSearchAdapter
|
|
23
|
-
|
|
24
|
-
Jbrowse1 text search adapter
|
|
25
|
-
Uses index built by generate-names.pl
|
|
26
|
-
*/
|
|
30
|
+
implements BaseTextSearchAdapter
|
|
31
|
+
{
|
|
27
32
|
httpMap: HttpMap
|
|
28
33
|
|
|
29
34
|
tracksNames?: string[]
|
|
30
35
|
|
|
31
|
-
constructor(
|
|
32
|
-
|
|
36
|
+
constructor(
|
|
37
|
+
config: Instance<typeof MyConfigSchema>,
|
|
38
|
+
getSubAdapter?: getSubAdapterType,
|
|
39
|
+
pluginManager?: PluginManager,
|
|
40
|
+
) {
|
|
41
|
+
super(config, getSubAdapter, pluginManager)
|
|
33
42
|
const namesIndexLocation = readConfObject(config, 'namesIndexLocation')
|
|
34
43
|
if (!namesIndexLocation) {
|
|
35
44
|
throw new Error('must provide namesIndexLocation')
|
|
@@ -38,7 +47,6 @@ export default class JBrowse1TextSearchAdapter
|
|
|
38
47
|
url: namesIndexLocation.baseUri
|
|
39
48
|
? new URL(namesIndexLocation.uri, namesIndexLocation.baseUri).href
|
|
40
49
|
: namesIndexLocation.uri,
|
|
41
|
-
isElectron,
|
|
42
50
|
})
|
|
43
51
|
}
|
|
44
52
|
|
|
@@ -47,70 +55,46 @@ export default class JBrowse1TextSearchAdapter
|
|
|
47
55
|
* else it returns empty
|
|
48
56
|
* @param query - string query
|
|
49
57
|
*/
|
|
50
|
-
async loadIndexFile(query: string) {
|
|
51
|
-
|
|
52
|
-
string,
|
|
53
|
-
Record<string, Array<NamesIndexRecord | TooManyHits>>
|
|
54
|
-
> = await this.httpMap.getBucket(query)
|
|
55
|
-
return bucketContents
|
|
58
|
+
async loadIndexFile(query: string): Promise<Record<string, SearchResults>> {
|
|
59
|
+
return this.httpMap.getBucket(query)
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
/**
|
|
59
|
-
* Returns list of results
|
|
60
|
-
* @param args - search options/arguments include: search query
|
|
61
|
-
* limit of results to return, SearchType...prefix | full | exact", etc.
|
|
62
|
-
*/
|
|
63
62
|
async searchIndex(args: BaseArgs) {
|
|
64
63
|
const { searchType, queryString } = args
|
|
65
|
-
const tracks = this.tracksNames
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (entries !== {} && entries[queryString]) {
|
|
70
|
-
// note: defaults to exact if no searchType is provided
|
|
71
|
-
return this.formatResults(
|
|
72
|
-
entries[queryString][searchType || 'exact'],
|
|
73
|
-
tracks,
|
|
74
|
-
)
|
|
64
|
+
const tracks = this.tracksNames || (await this.httpMap.getTrackNames())
|
|
65
|
+
const entries = await this.loadIndexFile(queryString.toLowerCase())
|
|
66
|
+
if (entries[queryString]) {
|
|
67
|
+
return this.formatResults(entries[queryString], tracks, searchType)
|
|
75
68
|
}
|
|
76
69
|
return []
|
|
77
70
|
}
|
|
78
|
-
formatResults(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
71
|
+
formatResults(results: SearchResults, tracks: string[], searchType?: string) {
|
|
72
|
+
return [
|
|
73
|
+
...(searchType === 'exact'
|
|
74
|
+
? []
|
|
75
|
+
: results.prefix.map(result => {
|
|
76
|
+
return new BaseResult({
|
|
77
|
+
label: typeof result === 'object' ? result.name : result,
|
|
78
|
+
matchedAttribute: 'name',
|
|
79
|
+
matchedObject: { result: result },
|
|
80
|
+
})
|
|
81
|
+
})),
|
|
82
|
+
...results.exact.map(result => {
|
|
87
83
|
const name = result[0] as string
|
|
88
84
|
const trackIndex = result[1] as number
|
|
89
85
|
const refName = result[3] as string
|
|
90
86
|
const start = result[4] as number
|
|
91
87
|
const end = result[5] as number
|
|
92
88
|
const locstring = `${refName || name}:${start}-${end}`
|
|
93
|
-
|
|
89
|
+
return new BaseResult({
|
|
94
90
|
locString: locstring,
|
|
95
91
|
label: name,
|
|
96
92
|
matchedAttribute: 'name',
|
|
97
93
|
matchedObject: result,
|
|
98
|
-
trackId:
|
|
94
|
+
trackId: tracks[trackIndex],
|
|
99
95
|
})
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// {"name":"too many matches","hitLimit":1}
|
|
103
|
-
const defaultLabel = typeof result === 'object' ? result.name : result
|
|
104
|
-
const defaultResult = new BaseResult({
|
|
105
|
-
label: defaultLabel,
|
|
106
|
-
matchedAttribute: 'name',
|
|
107
|
-
matchedObject: { result: result },
|
|
108
|
-
})
|
|
109
|
-
return defaultResult
|
|
110
|
-
})
|
|
111
|
-
return formattedResults.filter(
|
|
112
|
-
result => result.getLabel() !== 'too many matches',
|
|
113
|
-
)
|
|
96
|
+
}),
|
|
97
|
+
].filter(result => result.getLabel() !== 'too many matches')
|
|
114
98
|
}
|
|
115
99
|
|
|
116
100
|
freeResources() {}
|
|
@@ -6,7 +6,7 @@ export default ConfigurationSchema(
|
|
|
6
6
|
// metadata about tracks and assemblies covered by text search adapter
|
|
7
7
|
namesIndexLocation: {
|
|
8
8
|
type: 'fileLocation',
|
|
9
|
-
defaultValue: { uri: '/volvox/names' },
|
|
9
|
+
defaultValue: { uri: '/volvox/names', locationType: 'UriLocation' },
|
|
10
10
|
description: 'the location of the JBrowse1 names index data directory',
|
|
11
11
|
},
|
|
12
12
|
tracks: {
|
|
@@ -14,7 +14,7 @@ export default ConfigurationSchema(
|
|
|
14
14
|
defaultValue: [],
|
|
15
15
|
description: 'List of tracks covered by text search adapter',
|
|
16
16
|
},
|
|
17
|
-
|
|
17
|
+
assemblyNames: {
|
|
18
18
|
type: 'stringArray',
|
|
19
19
|
defaultValue: [],
|
|
20
20
|
description: 'List of assemblies covered by text search adapter',
|
|
@@ -20,7 +20,10 @@ test('adapter can fetch features from ensembl_genes test set', async () => {
|
|
|
20
20
|
await fsPromises.stat(rootTemplate.replace('{refseq}', '21')) // will throw if doesnt exist
|
|
21
21
|
const args = {
|
|
22
22
|
refNames: [],
|
|
23
|
-
rootUrlTemplate: {
|
|
23
|
+
rootUrlTemplate: {
|
|
24
|
+
uri: decodeURI(new URL(`file://${rootTemplate}`).href),
|
|
25
|
+
locationType: 'UriLocation',
|
|
26
|
+
},
|
|
24
27
|
}
|
|
25
28
|
const adapter = new Adapter(configSchema.create(args))
|
|
26
29
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import NCListStore from '@gmod/nclist'
|
|
2
|
-
import { openUrl } from '@jbrowse/core/util/io'
|
|
3
2
|
import { Region } from '@jbrowse/core/util/types'
|
|
4
3
|
import {
|
|
5
4
|
BaseFeatureDataAdapter,
|
|
@@ -8,11 +7,13 @@ import {
|
|
|
8
7
|
import { Feature } from '@jbrowse/core/util/simpleFeature'
|
|
9
8
|
import { ObservableCreate } from '@jbrowse/core/util/rxjs'
|
|
10
9
|
import { checkAbortSignal } from '@jbrowse/core/util'
|
|
11
|
-
|
|
10
|
+
import { RemoteFile } from 'generic-filehandle'
|
|
12
11
|
import { Instance } from 'mobx-state-tree'
|
|
13
12
|
import { readConfObject } from '@jbrowse/core/configuration'
|
|
14
13
|
import NCListFeature from './NCListFeature'
|
|
15
14
|
import MyConfigSchema from './configSchema'
|
|
15
|
+
import PluginManager from '@jbrowse/core/PluginManager'
|
|
16
|
+
import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'
|
|
16
17
|
|
|
17
18
|
export default class NCListAdapter extends BaseFeatureDataAdapter {
|
|
18
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -20,8 +21,12 @@ export default class NCListAdapter extends BaseFeatureDataAdapter {
|
|
|
20
21
|
|
|
21
22
|
private configRefNames?: string[]
|
|
22
23
|
|
|
23
|
-
constructor(
|
|
24
|
-
|
|
24
|
+
constructor(
|
|
25
|
+
config: Instance<typeof MyConfigSchema>,
|
|
26
|
+
getSubAdapter?: getSubAdapterType,
|
|
27
|
+
pluginManager?: PluginManager,
|
|
28
|
+
) {
|
|
29
|
+
super(config, getSubAdapter, pluginManager)
|
|
25
30
|
const refNames = readConfObject(config, 'refNames')
|
|
26
31
|
const rootUrlTemplate = readConfObject(config, 'rootUrlTemplate')
|
|
27
32
|
this.configRefNames = refNames
|
|
@@ -30,10 +35,12 @@ export default class NCListAdapter extends BaseFeatureDataAdapter {
|
|
|
30
35
|
baseUrl: '',
|
|
31
36
|
urlTemplate: rootUrlTemplate.uri,
|
|
32
37
|
readFile: (url: string) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
new RemoteFile(
|
|
39
|
+
String(
|
|
40
|
+
rootUrlTemplate.baseUri
|
|
41
|
+
? new URL(url, rootUrlTemplate.baseUri).toString()
|
|
42
|
+
: url,
|
|
43
|
+
),
|
|
37
44
|
).readFile(),
|
|
38
45
|
})
|
|
39
46
|
}
|
|
@@ -5,7 +5,10 @@ export default ConfigurationSchema(
|
|
|
5
5
|
{
|
|
6
6
|
rootUrlTemplate: {
|
|
7
7
|
type: 'fileLocation',
|
|
8
|
-
defaultValue: {
|
|
8
|
+
defaultValue: {
|
|
9
|
+
uri: '/path/to/my/{refseq}/trackData.json',
|
|
10
|
+
locationType: 'UriLocation',
|
|
11
|
+
},
|
|
9
12
|
},
|
|
10
13
|
refNames: {
|
|
11
14
|
type: 'stringArray',
|
|
@@ -5,6 +5,9 @@ exports[`plugin in a stock JBrowse 1`] = `Object {}`;
|
|
|
5
5
|
exports[`test creating a text search adapter 1`] = `
|
|
6
6
|
Object {
|
|
7
7
|
"namesIndexLocation": Object {
|
|
8
|
+
"internetAccountId": undefined,
|
|
9
|
+
"internetAccountPreAuthorization": undefined,
|
|
10
|
+
"locationType": "UriLocation",
|
|
8
11
|
"uri": "names/",
|
|
9
12
|
},
|
|
10
13
|
"textSearchAdapterId": "JBrowse1GenerateNamesAdapterTest",
|
package/src/index.test.js
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,11 +3,13 @@ import TextSearchAdapterType from '@jbrowse/core/pluggableElementTypes/TextSearc
|
|
|
3
3
|
import ConnectionType from '@jbrowse/core/pluggableElementTypes/ConnectionType'
|
|
4
4
|
import Plugin from '@jbrowse/core/Plugin'
|
|
5
5
|
import PluginManager from '@jbrowse/core/PluginManager'
|
|
6
|
+
import { FileLocation } from '@jbrowse/core/util/types'
|
|
6
7
|
import { configSchema as ncListAdapterConfigSchema } from './NCListAdapter'
|
|
7
8
|
import {
|
|
8
9
|
AdapterClass as JBrowse1TextSearchAdapterClass,
|
|
9
10
|
configSchema as jbrowse1AdapterConfigSchema,
|
|
10
11
|
} from './JBrowse1TextSeachAdapter'
|
|
12
|
+
import { AdapterGuesser, getFileName } from '@jbrowse/core/util/tracks'
|
|
11
13
|
|
|
12
14
|
import {
|
|
13
15
|
configSchema as jbrowse1ConfigSchema,
|
|
@@ -27,6 +29,27 @@ export default class LegacyJBrowsePlugin extends Plugin {
|
|
|
27
29
|
import('./NCListAdapter/NCListAdapter').then(r => r.default),
|
|
28
30
|
}),
|
|
29
31
|
)
|
|
32
|
+
pluginManager.addToExtensionPoint(
|
|
33
|
+
'Core-guessAdapterForLocation',
|
|
34
|
+
(adapterGuesser: AdapterGuesser) => {
|
|
35
|
+
return (
|
|
36
|
+
file: FileLocation,
|
|
37
|
+
index?: FileLocation,
|
|
38
|
+
adapterHint?: string,
|
|
39
|
+
) => {
|
|
40
|
+
const regexGuess = /trackData.jsonz?$/i
|
|
41
|
+
const adapterName = 'NCListAdapter'
|
|
42
|
+
const fileName = getFileName(file)
|
|
43
|
+
if (regexGuess.test(fileName) || adapterHint === adapterName) {
|
|
44
|
+
return {
|
|
45
|
+
type: adapterName,
|
|
46
|
+
rootUrlTemplate: file,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return adapterGuesser(file, index, adapterHint)
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
)
|
|
30
53
|
|
|
31
54
|
pluginManager.addTextSearchAdapterType(
|
|
32
55
|
() =>
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns an array of bytes given a string
|
|
3
|
-
* @param str - string
|
|
4
|
-
*/
|
|
5
|
-
export declare function stringToBytes(str: string): number[];
|
|
6
|
-
/**
|
|
7
|
-
* crc32 raw
|
|
8
|
-
* @param bytes - bytes
|
|
9
|
-
* @param start - number
|
|
10
|
-
* @param end - number
|
|
11
|
-
* @param crc - number
|
|
12
|
-
*/
|
|
13
|
-
export declare function crc32Raw(bytes: number[], start: number, end: number, crc?: number): number;
|
|
14
|
-
/**
|
|
15
|
-
* crc32 given a string
|
|
16
|
-
* @param str - string
|
|
17
|
-
* @param crc - number
|
|
18
|
-
*/
|
|
19
|
-
export declare function crc32(str: string, crc?: number): number;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Implementation of JB2 crc32 is based on JBrowse1 implementation
|
|
3
|
-
* found here:
|
|
4
|
-
* https://github.com/GMOD/jbrowse/blob/b8324df0033796b6d502696dc65c9ff888aae2f3/src/JBrowse/Digest/Crc32.js
|
|
5
|
-
* Used converter online to verify results:
|
|
6
|
-
* https://crccalc.com/
|
|
7
|
-
*/
|
|
8
|
-
import { crc32, stringToBytes } from './Crc32'
|
|
9
|
-
|
|
10
|
-
describe('test JBrowse1 crc32 implementation', () => {
|
|
11
|
-
test('test string to bytes', () => {
|
|
12
|
-
// Note: utf8 string is turned into a decimal byte array
|
|
13
|
-
expect(stringToBytes('apple')).toEqual([97, 112, 112, 108, 101])
|
|
14
|
-
expect(stringToBytes('foo')).toEqual([102, 111, 111])
|
|
15
|
-
})
|
|
16
|
-
test('test crc32', () => {
|
|
17
|
-
// input: string, output: dec
|
|
18
|
-
expect(crc32('apple')).toBe(2838417488)
|
|
19
|
-
expect(crc32('foo')).toBe(2356372769)
|
|
20
|
-
})
|
|
21
|
-
})
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const crc32Table =
|
|
2
|
-
'00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D'
|
|
3
|
-
// Adapted from JBrowse1 crc32 implementation.
|
|
4
|
-
// https://github.com/GMOD/jbrowse/blob/b8324df0033796b6d502696dc65c9ff888aae2f3/src/JBrowse/Digest/Crc32.js
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns an array of bytes given a string
|
|
8
|
-
* @param str - string
|
|
9
|
-
*/
|
|
10
|
-
export function stringToBytes(str: string) {
|
|
11
|
-
let ch
|
|
12
|
-
let st
|
|
13
|
-
let re: number[] = []
|
|
14
|
-
for (let i = 0; i < str.length; i++) {
|
|
15
|
-
ch = str.charCodeAt(i) // get char
|
|
16
|
-
st = [] // set up "stack"
|
|
17
|
-
do {
|
|
18
|
-
st.push(ch & 0xff) // push byte to stack
|
|
19
|
-
ch >>= 8 // shift value down by 1 byte
|
|
20
|
-
} while (ch)
|
|
21
|
-
// add stack contents to result
|
|
22
|
-
// done because chars have "wrong" endianness
|
|
23
|
-
re = re.concat(st.reverse())
|
|
24
|
-
}
|
|
25
|
-
return re
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* crc32 raw
|
|
30
|
-
* @param bytes - bytes
|
|
31
|
-
* @param start - number
|
|
32
|
-
* @param end - number
|
|
33
|
-
* @param crc - number
|
|
34
|
-
*/
|
|
35
|
-
export function crc32Raw(bytes: number[], start: number, end: number, crc = 0) {
|
|
36
|
-
let n = 0 // a number between 0 and 255
|
|
37
|
-
let x // a hex number
|
|
38
|
-
const table = crc32Table
|
|
39
|
-
|
|
40
|
-
crc ^= -1
|
|
41
|
-
for (let i = start, iTop = end; i < iTop; i++) {
|
|
42
|
-
n = (crc ^ bytes[i]) & 0xff
|
|
43
|
-
x = `0x${table.substr(n * 9, 8)}`
|
|
44
|
-
crc = (crc >>> 8) ^ parseInt(x, 16)
|
|
45
|
-
}
|
|
46
|
-
crc ^= -1
|
|
47
|
-
// convert to unsigned 32-bit int if needed
|
|
48
|
-
if (crc < 0) {
|
|
49
|
-
crc += 4294967296
|
|
50
|
-
}
|
|
51
|
-
return crc
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* crc32 given a string
|
|
56
|
-
* @param str - string
|
|
57
|
-
* @param crc - number
|
|
58
|
-
*/
|
|
59
|
-
export function crc32(str: string, crc = 0) {
|
|
60
|
-
const bytes = stringToBytes(str)
|
|
61
|
-
let n = 0 // a number between 0 and 255
|
|
62
|
-
let x // a hex number
|
|
63
|
-
const table = crc32Table
|
|
64
|
-
|
|
65
|
-
crc ^= -1
|
|
66
|
-
for (let i = 0, iTop = bytes.length; i < iTop; i++) {
|
|
67
|
-
n = (crc ^ bytes[i]) & 0xff
|
|
68
|
-
x = `0x${table.substr(n * 9, 8)}`
|
|
69
|
-
crc = (crc >>> 8) ^ parseInt(x, 16)
|
|
70
|
-
}
|
|
71
|
-
crc ^= -1
|
|
72
|
-
// convert to unsigned 32-bit int if needed
|
|
73
|
-
if (crc < 0) {
|
|
74
|
-
crc += 4294967296
|
|
75
|
-
}
|
|
76
|
-
return crc
|
|
77
|
-
}
|