@jbrowse/text-indexing 5.0.0-beta.1 → 5.0.0-beta.11

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.
@@ -1,14 +1,12 @@
1
1
  import type { indexType } from './util.ts';
2
2
  import type { StatusCallback } from '@jbrowse/core/util';
3
- import type { StopToken } from '@jbrowse/core/util/stopToken';
4
- import type { Track } from '@jbrowse/text-indexing-core';
5
- export declare function indexTracks(args: {
3
+ import type { IndexingPolicy, Track } from '@jbrowse/text-indexing-core';
4
+ export declare function indexTracks({ tracks, outDir, policy, assemblyNames, indexType, statusCallback, signal, }: {
6
5
  tracks: Track[];
7
6
  outDir: string;
8
- stopToken?: StopToken;
9
- attributesToIndex?: string[];
7
+ signal?: AbortSignal;
8
+ policy?: IndexingPolicy;
10
9
  assemblyNames?: string[];
11
- featureTypesToExclude?: string[];
12
10
  indexType?: indexType;
13
11
  statusCallback: StatusCallback | undefined;
14
12
  }): Promise<void>;
@@ -1,89 +1,51 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { Readable } from 'node:stream';
4
- import { checkStopTokenThrottled, checkStopToken, createStopTokenChecker, } from '@jbrowse/core/util/stopToken';
5
- import { TRIX_DIR, defaultAttributesToIndex, defaultFeatureTypesToExclude, generateMeta, indexFiles, isSupportedIndexingAdapter, trixFilePaths, } from '@jbrowse/text-indexing-core';
6
- import { ixIxxStream } from 'ixixx';
7
- export async function indexTracks(args) {
8
- const { tracks, outDir, attributesToIndex, featureTypesToExclude, assemblyNames, indexType, statusCallback, stopToken, } = args;
9
- const idxType = indexType || 'perTrack';
10
- checkStopToken(stopToken);
11
- await (idxType === 'perTrack'
12
- ? perTrackIndex({
13
- tracks,
14
- statusCallback,
15
- outDir,
16
- attributesToIndex,
17
- featureTypesToExclude,
18
- stopToken,
19
- })
20
- : aggregateIndex({
21
- tracks,
22
- statusCallback,
23
- outDir,
24
- attributesToIndex,
25
- assemblyNames,
26
- featureTypesToExclude,
27
- stopToken,
28
- }));
29
- checkStopToken(stopToken);
30
- }
31
- function ensureTrixDir(outDir) {
32
- fs.mkdirSync(path.join(outDir, TRIX_DIR), { recursive: true });
33
- }
34
- async function perTrackIndex({ tracks, statusCallback, outDir, attributesToIndex = defaultAttributesToIndex, featureTypesToExclude = defaultFeatureTypesToExclude, stopToken, }) {
35
- ensureTrixDir(outDir);
36
- const supportedTracks = tracks.filter(track => isSupportedIndexingAdapter(track.adapter?.type));
37
- for (const trackConfig of supportedTracks) {
38
- const { trackId, assemblyNames } = trackConfig;
39
- await indexDriver({
40
- tracks: [trackConfig],
41
- outDir,
42
- attributesToIndex,
43
- name: `${trackId}-index`,
44
- featureTypesToExclude,
45
- assemblyNames,
46
- statusCallback,
47
- stopToken,
48
- });
1
+ import { checkAbortSignal } from '@jbrowse/core/util/aborting';
2
+ import { defaultIndexingPolicy, isSupportedIndexingAdapter, writeTrixIndex, } from '@jbrowse/text-indexing-core';
3
+ export async function indexTracks({ tracks, outDir, policy = defaultIndexingPolicy, assemblyNames, indexType = 'perTrack', statusCallback, signal, }) {
4
+ checkAbortSignal(signal);
5
+ const supported = tracks.filter(track => isSupportedIndexingAdapter(track.adapter?.type));
6
+ const write = (indexed, name, names) => indexDriver({
7
+ tracks: indexed,
8
+ outDir,
9
+ name,
10
+ policy,
11
+ assemblyNames: names,
12
+ statusCallback,
13
+ signal,
14
+ });
15
+ if (indexType === 'perTrack') {
16
+ for (const track of supported) {
17
+ await write([track], `${track.trackId}-index`, track.assemblyNames);
18
+ }
49
19
  }
50
- }
51
- async function aggregateIndex({ tracks, statusCallback, outDir, attributesToIndex = defaultAttributesToIndex, featureTypesToExclude = defaultFeatureTypesToExclude, stopToken, assemblyNames, }) {
52
- if (!assemblyNames) {
53
- throw new Error('No assemblies passed. Assemblies required for aggregate indexes');
20
+ else if (assemblyNames) {
21
+ for (const asm of assemblyNames) {
22
+ await write(supported.filter(track => track.assemblyNames.includes(asm)), `${asm}-index`, [asm]);
23
+ }
54
24
  }
55
- ensureTrixDir(outDir);
56
- for (const asm of assemblyNames) {
57
- const supportedTracks = tracks
58
- .filter(track => isSupportedIndexingAdapter(track.adapter?.type))
59
- .filter(track => track.assemblyNames.includes(asm));
60
- await indexDriver({
61
- tracks: supportedTracks,
62
- outDir,
63
- attributesToIndex,
64
- name: `${asm}-index`,
65
- featureTypesToExclude,
66
- assemblyNames: [asm],
67
- statusCallback,
68
- stopToken,
69
- });
25
+ else {
26
+ throw new Error('No assemblies passed. Assemblies required for aggregate indexes');
70
27
  }
28
+ checkAbortSignal(signal);
71
29
  }
72
- async function indexDriver({ tracks, outDir, attributesToIndex, name, featureTypesToExclude, assemblyNames, statusCallback, stopToken, }) {
73
- const checker = createStopTokenChecker(stopToken);
30
+ function indexDriver({ tracks, outDir, name, policy, assemblyNames, statusCallback, signal, }) {
74
31
  // accumulate across tracks so an aggregate index reports monotonic progress
75
32
  // rather than resetting to zero at each track. The denominator grows as each
76
33
  // track's size is discovered (we don't stat every file up front), but the
77
34
  // numerator only ever increases
78
35
  let bankedBytes = 0;
79
36
  let cumulativeTotal = 0;
80
- const readable = Readable.from(indexFiles({
37
+ statusCallback?.('Indexing files');
38
+ return writeTrixIndex({
81
39
  tracks,
82
- attributesToIndex,
83
40
  outDir,
84
- featureTypesToExclude,
41
+ name,
42
+ policy,
43
+ assemblyNames,
85
44
  checkAbort: () => {
86
- checkStopTokenThrottled(checker);
45
+ checkAbortSignal(signal);
46
+ },
47
+ onSort: () => {
48
+ statusCallback?.('Sorting and writing index');
87
49
  },
88
50
  makeProgress: () => {
89
51
  let trackTotal = 0;
@@ -104,26 +66,5 @@ async function indexDriver({ tracks, outDir, attributesToIndex, name, featureTyp
104
66
  },
105
67
  };
106
68
  },
107
- }));
108
- // records stream straight into ixIxx, so 'end' is where the byte counts stop
109
- // and the sort's own tail begins — otherwise minutes of a bar stuck at 100%
110
- readable.on('end', () => {
111
- statusCallback?.('Sorting and writing index');
112
69
  });
113
- statusCallback?.('Indexing files');
114
- await runIxIxx(readable, outDir, name);
115
- checkStopToken(stopToken);
116
- generateMeta({
117
- configs: tracks,
118
- attributesToIndex,
119
- outDir,
120
- name,
121
- featureTypesToExclude,
122
- assemblyNames,
123
- });
124
- checkStopToken(stopToken);
125
- }
126
- function runIxIxx(readStream, idxLocation, name) {
127
- const { ix, ixx } = trixFilePaths(idxLocation, name);
128
- return ixIxxStream(readStream, ix, ixx);
129
70
  }
package/esm/util.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import type { Track } from '@jbrowse/text-indexing-core';
2
2
  export type indexType = 'aggregate' | 'perTrack';
3
- export declare function createTextSearchConf(name: string, trackIds: string[], assemblyNames: string[], locationPath: string): {
4
- type: string;
5
- textSearchAdapterId: string;
3
+ export declare function createTextSearchConf(name: string, assemblyNames: string[], locationPath: string): {
4
+ type: 'TrixTextSearchAdapter';
6
5
  ixFilePath: {
7
6
  localPath: string;
8
7
  locationType: 'LocalPathLocation';
@@ -11,11 +10,6 @@ export declare function createTextSearchConf(name: string, trackIds: string[], a
11
10
  localPath: string;
12
11
  locationType: 'LocalPathLocation';
13
12
  };
14
- metaFilePath: {
15
- localPath: string;
16
- locationType: 'LocalPathLocation';
17
- };
18
- tracks: string[];
19
13
  assemblyNames: string[];
20
14
  };
21
15
  export declare function findTrackConfigsToIndex(tracks: Track[], trackIds: string[]): Track[];
package/esm/util.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { isSupportedIndexingAdapter, trixFilePaths, } from '@jbrowse/text-indexing-core';
2
- export function createTextSearchConf(name, trackIds, assemblyNames, locationPath) {
2
+ export function createTextSearchConf(name, assemblyNames, locationPath) {
3
3
  const paths = trixFilePaths(locationPath, name);
4
4
  return {
5
5
  type: 'TrixTextSearchAdapter',
6
- textSearchAdapterId: name,
7
6
  ixFilePath: {
8
7
  localPath: paths.ix,
9
8
  locationType: 'LocalPathLocation',
@@ -12,11 +11,6 @@ export function createTextSearchConf(name, trackIds, assemblyNames, locationPath
12
11
  localPath: paths.ixx,
13
12
  locationType: 'LocalPathLocation',
14
13
  },
15
- metaFilePath: {
16
- localPath: paths.meta,
17
- locationType: 'LocalPathLocation',
18
- },
19
- tracks: trackIds,
20
14
  assemblyNames,
21
15
  };
22
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/text-indexing",
3
- "version": "5.0.0-beta.1",
3
+ "version": "5.0.0-beta.11",
4
4
  "type": "module",
5
5
  "description": "JBrowse 2 text indexing for desktop",
6
6
  "keywords": [
@@ -20,13 +20,16 @@
20
20
  },
21
21
  "author": "JBrowse Team",
22
22
  "main": "esm/index.js",
23
+ "exports": {
24
+ ".": "./esm/index.js",
25
+ "./util": "./esm/util.js"
26
+ },
23
27
  "files": [
24
28
  "esm"
25
29
  ],
26
30
  "dependencies": {
27
- "ixixx": "^3.0.13",
28
- "@jbrowse/text-indexing-core": "^5.0.0-beta.1",
29
- "@jbrowse/core": "^5.0.0-beta.1"
31
+ "@jbrowse/text-indexing-core": "^5.0.0-beta.11",
32
+ "@jbrowse/core": "^5.0.0-beta.11"
30
33
  },
31
34
  "peerDependencies": {
32
35
  "react": ">=19.0.0",
@@ -43,8 +46,5 @@
43
46
  "clean": "rimraf esm *.tsbuildinfo",
44
47
  "prebuild": "pnpm clean"
45
48
  },
46
- "types": "esm/index.d.ts",
47
- "exports": {
48
- ".": "./esm/index.js"
49
- }
49
+ "types": "esm/index.d.ts"
50
50
  }