@jbrowse/text-indexing 3.7.0 → 4.0.1

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,4 +1,4 @@
1
- import type { Track, indexType } from './util';
1
+ import type { Track, indexType } from './util.ts';
2
2
  export declare function indexTracks(args: {
3
3
  tracks: Track[];
4
4
  outDir?: string;
@@ -4,9 +4,9 @@ import { Readable } from 'stream';
4
4
  import { isSupportedIndexingAdapter } from '@jbrowse/core/util';
5
5
  import { checkStopToken } from '@jbrowse/core/util/stopToken';
6
6
  import { ixIxxStream } from 'ixixx';
7
- import { generateMeta } from './types/common';
8
- import { indexGff3 } from './types/gff3Adapter';
9
- import { indexVcf } from './types/vcfAdapter';
7
+ import { generateMeta } from "./types/common.js";
8
+ import { indexGff3 } from "./types/gff3Adapter.js";
9
+ import { indexVcf } from "./types/vcfAdapter.js";
10
10
  export async function indexTracks(args) {
11
11
  const { tracks, outDir, attributesToIndex, featureTypesToExclude, assemblyNames, indexType, statusCallback, stopToken, } = args;
12
12
  const idxType = indexType || 'perTrack';
@@ -41,7 +41,7 @@ async function perTrackIndex({ tracks, statusCallback, outDir: paramOutDir, attr
41
41
  if (!fs.existsSync(trixDir)) {
42
42
  fs.mkdirSync(trixDir);
43
43
  }
44
- const supportedTracks = tracks.filter(track => { var _a; return isSupportedIndexingAdapter((_a = track.adapter) === null || _a === void 0 ? void 0 : _a.type); });
44
+ const supportedTracks = tracks.filter(track => isSupportedIndexingAdapter(track.adapter?.type));
45
45
  for (const trackConfig of supportedTracks) {
46
46
  const { trackId, assemblyNames } = trackConfig;
47
47
  const id = `${trackId}-index`;
@@ -72,7 +72,7 @@ async function aggregateIndex({ tracks, statusCallback, outDir: paramOutDir, att
72
72
  for (const asm of assemblyNames) {
73
73
  const id = `${asm}-index`;
74
74
  const supportedTracks = tracks
75
- .filter(track => { var _a; return isSupportedIndexingAdapter((_a = track.adapter) === null || _a === void 0 ? void 0 : _a.type); })
75
+ .filter(track => isSupportedIndexingAdapter(track.adapter?.type))
76
76
  .filter(track => (asm ? track.assemblyNames.includes(asm) : true));
77
77
  await indexDriver({
78
78
  tracks: supportedTracks,
@@ -176,8 +176,7 @@ async function* indexFiles({ tracks, attributesToIndex: idx1, outDir, featureTyp
176
176
  return;
177
177
  }
178
178
  function getLoc(attr, config) {
179
- var _a;
180
- const elt = (_a = config.adapter) === null || _a === void 0 ? void 0 : _a[attr];
179
+ const elt = config.adapter?.[attr];
181
180
  if (!elt) {
182
181
  throw new Error(`can't get find ${attr} from ${config.adapter} for text indexing`);
183
182
  }
package/esm/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './util';
2
- export * from './types/common';
3
- export { indexTracks } from './TextIndexing';
4
- export { indexGff3 } from './types/gff3Adapter';
5
- export { indexVcf } from './types/vcfAdapter';
1
+ export * from './util.ts';
2
+ export * from './types/common.ts';
3
+ export { indexTracks } from './TextIndexing.ts';
4
+ export { indexGff3 } from './types/gff3Adapter.ts';
5
+ export { indexVcf } from './types/vcfAdapter.ts';
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export * from './util';
2
- export * from './types/common';
3
- export { indexTracks } from './TextIndexing';
4
- export { indexGff3 } from './types/gff3Adapter';
5
- export { indexVcf } from './types/vcfAdapter';
1
+ export * from "./util.js";
2
+ export * from "./types/common.js";
3
+ export { indexTracks } from "./TextIndexing.js";
4
+ export { indexGff3 } from "./types/gff3Adapter.js";
5
+ export { indexVcf } from "./types/vcfAdapter.js";
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import fetch from 'node-fetch';
3
- import type { LocalPathLocation, Track, UriLocation } from '../util';
3
+ import type { LocalPathLocation, Track, UriLocation } from '../util.ts';
4
4
  export declare function createRemoteStream(urlIn: string): Promise<fetch.Response>;
5
5
  export declare function isURL(FileName: string): boolean;
6
6
  export declare function getLocalOrRemoteStream({ file, out, onBytesReceived, onTotalBytes, }: {
@@ -121,8 +121,8 @@ export async function generateMeta({ configs, attributesToIndex, outDir, name, f
121
121
  const { trackId, textSearching, adapter } = config;
122
122
  return {
123
123
  trackId,
124
- attributesIndexed: (textSearching === null || textSearching === void 0 ? void 0 : textSearching.indexingAttributes) || attributesToIndex,
125
- excludedTypes: (textSearching === null || textSearching === void 0 ? void 0 : textSearching.indexingFeatureTypesToExclude) ||
124
+ attributesIndexed: textSearching?.indexingAttributes || attributesToIndex,
125
+ excludedTypes: textSearching?.indexingFeatureTypesToExclude ||
126
126
  featureTypesToExclude,
127
127
  adapterConf: adapter,
128
128
  };
@@ -1,7 +1,7 @@
1
1
  import readline from 'readline';
2
2
  import { createGunzip } from 'zlib';
3
- import { decodeURIComponentNoThrow } from '../util';
4
- import { getLocalOrRemoteStream } from './common';
3
+ import { decodeURIComponentNoThrow } from "../util.js";
4
+ import { getLocalOrRemoteStream } from "./common.js";
5
5
  export async function* indexGff3({ config, attributesToIndex, inLocation, outDir, featureTypesToExclude, onStart, onUpdate, }) {
6
6
  const { trackId } = config;
7
7
  const stream = await getLocalOrRemoteStream({
@@ -1,7 +1,7 @@
1
1
  import readline from 'readline';
2
2
  import { createGunzip } from 'zlib';
3
- import { decodeURIComponentNoThrow } from '../util';
4
- import { getLocalOrRemoteStream } from './common';
3
+ import { decodeURIComponentNoThrow } from "../util.js";
4
+ import { getLocalOrRemoteStream } from "./common.js";
5
5
  export async function* indexVcf({ config, attributesToIndex, inLocation, outDir, onStart, onUpdate, }) {
6
6
  const { trackId } = config;
7
7
  const stream = await getLocalOrRemoteStream({
package/esm/util.js CHANGED
@@ -33,7 +33,7 @@ export function findTrackConfigsToIndex(tracks, trackIds, assemblyName) {
33
33
  return currentTrack;
34
34
  })
35
35
  .filter(track => assemblyName ? track.assemblyNames.includes(assemblyName) : true)
36
- .filter(track => { var _a; return isSupportedIndexingAdapter((_a = track.adapter) === null || _a === void 0 ? void 0 : _a.type); });
36
+ .filter(track => isSupportedIndexingAdapter(track.adapter?.type));
37
37
  }
38
38
  export function decodeURIComponentNoThrow(uri) {
39
39
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/text-indexing",
3
- "version": "3.7.0",
3
+ "version": "4.0.1",
4
4
  "description": "JBrowse 2 text indexing for desktop",
5
5
  "keywords": [
6
6
  "jbrowse",
@@ -18,38 +18,15 @@
18
18
  "directory": "packages/text-indexing"
19
19
  },
20
20
  "author": "JBrowse Team",
21
- "distMain": "dist/index.js",
22
- "distModule": "esm/index.js",
23
- "srcMain": "src/index.ts",
24
- "srcModule": "src/index.ts",
25
- "main": "dist/index.js",
26
- "module": "esm/index.js",
21
+ "main": "esm/index.js",
27
22
  "files": [
28
- "dist",
29
23
  "esm"
30
24
  ],
31
- "scripts": {
32
- "build:esm": "tsc --build tsconfig.build.esm.json",
33
- "build:commonjs": "tsc --build tsconfig.build.commonjs.json",
34
- "build": "npm run build:esm && npm run build:commonjs",
35
- "test": "cd ../..; jest --passWithNoTests packages/text-indexing",
36
- "clean": "rimraf dist esm *.tsbuildinfo",
37
- "prebuild": "yarn clean",
38
- "prepack": "yarn build && yarn useDist",
39
- "postpack": "yarn useSrc",
40
- "useDist": "node ../../scripts/useDist.js",
41
- "useSrc": "node ../../scripts/useSrc.js"
42
- },
43
25
  "dependencies": {
44
- "@babel/runtime": "^7.16.3",
45
- "@jbrowse/core": "^3.7.0",
46
- "ixixx": "^2.0.1",
47
- "mobx": "^6.0.0",
48
- "mobx-react": "^9.0.0",
49
- "mobx-state-tree": "^5.0.0",
50
- "node-fetch": "^2.6.0",
51
- "rxjs": "^7.0.0",
52
- "sanitize-filename": "^1.6.3"
26
+ "ixixx": "^3.0.2",
27
+ "node-fetch": "^2.7.0",
28
+ "sanitize-filename": "^1.6.3",
29
+ "@jbrowse/core": "^4.0.1"
53
30
  },
54
31
  "peerDependencies": {
55
32
  "react": ">=18.0.0",
@@ -58,5 +35,19 @@
58
35
  "publishConfig": {
59
36
  "access": "public"
60
37
  },
61
- "gitHead": "85bdd0d58286b7adbfd408146b15847676317635"
62
- }
38
+ "sideEffects": false,
39
+ "scripts": {
40
+ "build:esm": "tsc -p tsconfig.build.esm.json",
41
+ "build": "pnpm build:esm",
42
+ "test": "cd ../..; jest --passWithNoTests packages/text-indexing",
43
+ "clean": "rimraf esm *.tsbuildinfo",
44
+ "prebuild": "pnpm clean"
45
+ },
46
+ "types": "esm/index.d.ts",
47
+ "exports": {
48
+ ".": {
49
+ "types": "./esm/index.d.ts",
50
+ "import": "./esm/index.js"
51
+ }
52
+ }
53
+ }
@@ -1,11 +0,0 @@
1
- import type { Track, indexType } from './util';
2
- export declare function indexTracks(args: {
3
- tracks: Track[];
4
- outDir?: string;
5
- stopToken?: string;
6
- attributesToIndex?: string[];
7
- assemblyNames?: string[];
8
- featureTypesToExclude?: string[];
9
- indexType?: indexType;
10
- statusCallback: (message: string) => void;
11
- }): Promise<never[]>;
@@ -1,196 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.indexTracks = indexTracks;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const stream_1 = require("stream");
10
- const util_1 = require("@jbrowse/core/util");
11
- const stopToken_1 = require("@jbrowse/core/util/stopToken");
12
- const ixixx_1 = require("ixixx");
13
- const common_1 = require("./types/common");
14
- const gff3Adapter_1 = require("./types/gff3Adapter");
15
- const vcfAdapter_1 = require("./types/vcfAdapter");
16
- async function indexTracks(args) {
17
- const { tracks, outDir, attributesToIndex, featureTypesToExclude, assemblyNames, indexType, statusCallback, stopToken, } = args;
18
- const idxType = indexType || 'perTrack';
19
- (0, stopToken_1.checkStopToken)(stopToken);
20
- await (idxType === 'perTrack'
21
- ? perTrackIndex({
22
- tracks,
23
- statusCallback,
24
- outDir,
25
- attributesToIndex,
26
- featureTypesToExclude,
27
- stopToken,
28
- })
29
- : aggregateIndex({
30
- tracks,
31
- statusCallback,
32
- outDir,
33
- attributesToIndex,
34
- assemblyNames,
35
- featureTypesToExclude,
36
- stopToken,
37
- }));
38
- (0, stopToken_1.checkStopToken)(stopToken);
39
- return [];
40
- }
41
- async function perTrackIndex({ tracks, statusCallback, outDir: paramOutDir, attributesToIndex = ['Name', 'ID'], featureTypesToExclude = ['exon', 'CDS'], stopToken, }) {
42
- const outFlag = paramOutDir || '.';
43
- const isDir = fs_1.default.lstatSync(outFlag).isDirectory();
44
- const confFilePath = isDir ? path_1.default.join(outFlag, 'config.json') : outFlag;
45
- const outDir = path_1.default.dirname(confFilePath);
46
- const trixDir = path_1.default.join(outDir, 'trix');
47
- if (!fs_1.default.existsSync(trixDir)) {
48
- fs_1.default.mkdirSync(trixDir);
49
- }
50
- const supportedTracks = tracks.filter(track => { var _a; return (0, util_1.isSupportedIndexingAdapter)((_a = track.adapter) === null || _a === void 0 ? void 0 : _a.type); });
51
- for (const trackConfig of supportedTracks) {
52
- const { trackId, assemblyNames } = trackConfig;
53
- const id = `${trackId}-index`;
54
- await indexDriver({
55
- tracks: [trackConfig],
56
- outDir,
57
- attributesToIndex,
58
- name: id,
59
- featureTypesToExclude,
60
- assemblyNames,
61
- statusCallback,
62
- stopToken,
63
- });
64
- }
65
- }
66
- async function aggregateIndex({ tracks, statusCallback, outDir: paramOutDir, attributesToIndex = ['Name', 'ID'], featureTypesToExclude = ['exon', 'CDS'], stopToken, assemblyNames, }) {
67
- const outFlag = paramOutDir || '.';
68
- const isDir = fs_1.default.lstatSync(outFlag).isDirectory();
69
- const confFilePath = isDir ? path_1.default.join(outFlag, 'config.json') : outFlag;
70
- const outDir = path_1.default.dirname(confFilePath);
71
- const trixDir = path_1.default.join(outDir, 'trix');
72
- if (!fs_1.default.existsSync(trixDir)) {
73
- fs_1.default.mkdirSync(trixDir);
74
- }
75
- if (!assemblyNames) {
76
- throw new Error('No assemblies passed. Assmeblies required for aggregate indexes');
77
- }
78
- for (const asm of assemblyNames) {
79
- const id = `${asm}-index`;
80
- const supportedTracks = tracks
81
- .filter(track => { var _a; return (0, util_1.isSupportedIndexingAdapter)((_a = track.adapter) === null || _a === void 0 ? void 0 : _a.type); })
82
- .filter(track => (asm ? track.assemblyNames.includes(asm) : true));
83
- await indexDriver({
84
- tracks: supportedTracks,
85
- outDir: outDir,
86
- attributesToIndex,
87
- name: id,
88
- featureTypesToExclude,
89
- assemblyNames: [asm],
90
- statusCallback,
91
- stopToken,
92
- });
93
- }
94
- }
95
- async function indexDriver({ tracks, outDir, attributesToIndex, name, featureTypesToExclude, assemblyNames, statusCallback, stopToken, }) {
96
- const readable = stream_1.Readable.from(indexFiles({
97
- tracks,
98
- attributesToIndex,
99
- outDir,
100
- featureTypesToExclude,
101
- statusCallback,
102
- stopToken,
103
- }));
104
- statusCallback('Indexing files.');
105
- await runIxIxx(readable, outDir, name);
106
- (0, stopToken_1.checkStopToken)(stopToken);
107
- await (0, common_1.generateMeta)({
108
- configs: tracks,
109
- attributesToIndex,
110
- outDir,
111
- name,
112
- featureTypesToExclude,
113
- assemblyNames,
114
- });
115
- (0, stopToken_1.checkStopToken)(stopToken);
116
- }
117
- async function* indexFiles({ tracks, attributesToIndex: idx1, outDir, featureTypesToExclude: edx1, statusCallback, }) {
118
- for (const track of tracks) {
119
- const { adapter, textSearching } = track;
120
- const { type } = adapter || {};
121
- const { indexingFeatureTypesToExclude: featureTypesToExclude = edx1, indexingAttributes: attributesToIndex = idx1, } = textSearching || {};
122
- let myTotalBytes;
123
- if (type === 'Gff3Adapter') {
124
- yield* (0, gff3Adapter_1.indexGff3)({
125
- config: track,
126
- attributesToIndex,
127
- inLocation: getLoc('gffLocation', track),
128
- outDir,
129
- featureTypesToExclude,
130
- onStart: totalBytes => {
131
- myTotalBytes = totalBytes;
132
- },
133
- onUpdate: progressBytes => {
134
- statusCallback(`${progressBytes}/${myTotalBytes}`);
135
- },
136
- });
137
- }
138
- if (type === 'Gff3TabixAdapter') {
139
- yield* (0, gff3Adapter_1.indexGff3)({
140
- config: track,
141
- attributesToIndex,
142
- inLocation: getLoc('gffGzLocation', track),
143
- outDir,
144
- featureTypesToExclude,
145
- onStart: totalBytes => {
146
- myTotalBytes = totalBytes;
147
- },
148
- onUpdate: progressBytes => {
149
- statusCallback(`${progressBytes}/${myTotalBytes}`);
150
- },
151
- });
152
- }
153
- else if (type === 'VcfAdapter') {
154
- yield* (0, vcfAdapter_1.indexVcf)({
155
- config: track,
156
- attributesToIndex,
157
- inLocation: getLoc('vcfLocation', track),
158
- outDir,
159
- onStart: totalBytes => {
160
- myTotalBytes = totalBytes;
161
- },
162
- onUpdate: progressBytes => {
163
- statusCallback(`${progressBytes}/${myTotalBytes}`);
164
- },
165
- });
166
- }
167
- else if (type === 'VcfTabixAdapter') {
168
- yield* (0, vcfAdapter_1.indexVcf)({
169
- config: track,
170
- attributesToIndex,
171
- inLocation: getLoc('vcfGzLocation', track),
172
- outDir,
173
- onStart: totalBytes => {
174
- myTotalBytes = totalBytes;
175
- },
176
- onUpdate: progressBytes => {
177
- statusCallback(`${progressBytes}/${myTotalBytes}`);
178
- },
179
- });
180
- }
181
- }
182
- return;
183
- }
184
- function getLoc(attr, config) {
185
- var _a;
186
- const elt = (_a = config.adapter) === null || _a === void 0 ? void 0 : _a[attr];
187
- if (!elt) {
188
- throw new Error(`can't get find ${attr} from ${config.adapter} for text indexing`);
189
- }
190
- return elt.uri || elt.localPath;
191
- }
192
- function runIxIxx(readStream, idxLocation, name) {
193
- const ixFilename = path_1.default.join(idxLocation, 'trix', `${name}.ix`);
194
- const ixxFilename = path_1.default.join(idxLocation, 'trix', `${name}.ixx`);
195
- return (0, ixixx_1.ixIxxStream)(readStream, ixFilename, ixxFilename);
196
- }
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './util';
2
- export * from './types/common';
3
- export { indexTracks } from './TextIndexing';
4
- export { indexGff3 } from './types/gff3Adapter';
5
- export { indexVcf } from './types/vcfAdapter';
package/dist/index.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.indexVcf = exports.indexGff3 = exports.indexTracks = void 0;
18
- __exportStar(require("./util"), exports);
19
- __exportStar(require("./types/common"), exports);
20
- var TextIndexing_1 = require("./TextIndexing");
21
- Object.defineProperty(exports, "indexTracks", { enumerable: true, get: function () { return TextIndexing_1.indexTracks; } });
22
- var gff3Adapter_1 = require("./types/gff3Adapter");
23
- Object.defineProperty(exports, "indexGff3", { enumerable: true, get: function () { return gff3Adapter_1.indexGff3; } });
24
- var vcfAdapter_1 = require("./types/vcfAdapter");
25
- Object.defineProperty(exports, "indexVcf", { enumerable: true, get: function () { return vcfAdapter_1.indexVcf; } });
@@ -1,21 +0,0 @@
1
- import fs from 'fs';
2
- import fetch from 'node-fetch';
3
- import type { LocalPathLocation, Track, UriLocation } from '../util';
4
- export declare function createRemoteStream(urlIn: string): Promise<fetch.Response>;
5
- export declare function isURL(FileName: string): boolean;
6
- export declare function getLocalOrRemoteStream({ file, out, onBytesReceived, onTotalBytes, }: {
7
- file: string;
8
- out: string;
9
- onBytesReceived: (totalBytesReceived: number) => void;
10
- onTotalBytes: (totalBytes: number) => void;
11
- }): Promise<NodeJS.ReadableStream | fs.ReadStream>;
12
- export declare function makeLocation(location: string, protocol: string): UriLocation | LocalPathLocation;
13
- export declare function guessAdapterFromFileName(filePath: string): Track;
14
- export declare function generateMeta({ configs, attributesToIndex, outDir, name, featureTypesToExclude, assemblyNames, }: {
15
- configs: Track[];
16
- attributesToIndex: string[];
17
- outDir: string;
18
- name: string;
19
- featureTypesToExclude: string[];
20
- assemblyNames: string[];
21
- }): Promise<void>;
@@ -1,143 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createRemoteStream = createRemoteStream;
7
- exports.isURL = isURL;
8
- exports.getLocalOrRemoteStream = getLocalOrRemoteStream;
9
- exports.makeLocation = makeLocation;
10
- exports.guessAdapterFromFileName = guessAdapterFromFileName;
11
- exports.generateMeta = generateMeta;
12
- const fs_1 = __importDefault(require("fs"));
13
- const path_1 = __importDefault(require("path"));
14
- const node_fetch_1 = __importDefault(require("node-fetch"));
15
- async function createRemoteStream(urlIn) {
16
- const res = await (0, node_fetch_1.default)(urlIn);
17
- if (!res.ok) {
18
- throw new Error(`Failed to fetch ${urlIn} status ${res.status} ${await res.text()}`);
19
- }
20
- return res;
21
- }
22
- function isURL(FileName) {
23
- let url;
24
- try {
25
- url = new URL(FileName);
26
- }
27
- catch (_) {
28
- return false;
29
- }
30
- return url.protocol === 'http:' || url.protocol === 'https:';
31
- }
32
- async function getLocalOrRemoteStream({ file, out, onBytesReceived, onTotalBytes, }) {
33
- let receivedBytes = 0;
34
- if (isURL(file)) {
35
- const result = await createRemoteStream(file);
36
- result.body.on('data', chunk => {
37
- receivedBytes += chunk.length;
38
- onBytesReceived(receivedBytes);
39
- });
40
- onTotalBytes(+(result.headers.get('Content-Length') || 0));
41
- return result.body;
42
- }
43
- else {
44
- const filename = path_1.default.isAbsolute(file) ? file : path_1.default.join(out, file);
45
- const stream = fs_1.default.createReadStream(filename);
46
- stream.on('data', chunk => {
47
- receivedBytes += chunk.length;
48
- onBytesReceived(receivedBytes);
49
- });
50
- onTotalBytes(fs_1.default.statSync(filename).size);
51
- return stream;
52
- }
53
- }
54
- function makeLocation(location, protocol) {
55
- if (protocol === 'uri') {
56
- return { uri: location, locationType: 'UriLocation' };
57
- }
58
- if (protocol === 'localPath') {
59
- return {
60
- localPath: path_1.default.resolve(location),
61
- locationType: 'LocalPathLocation',
62
- };
63
- }
64
- throw new Error(`invalid protocol ${protocol}`);
65
- }
66
- function guessAdapterFromFileName(filePath) {
67
- const protocol = isURL(filePath) ? 'uri' : 'localPath';
68
- const name = path_1.default.basename(filePath);
69
- if (/\.vcf\.b?gz$/i.test(filePath)) {
70
- return {
71
- trackId: name,
72
- name: name,
73
- assemblyNames: [],
74
- adapter: {
75
- type: 'VcfTabixAdapter',
76
- vcfGzLocation: makeLocation(filePath, protocol),
77
- },
78
- };
79
- }
80
- else if (/\.gff3?\.b?gz$/i.test(filePath)) {
81
- return {
82
- trackId: name,
83
- name,
84
- assemblyNames: [],
85
- adapter: {
86
- type: 'Gff3TabixAdapter',
87
- gffGzLocation: makeLocation(filePath, protocol),
88
- },
89
- };
90
- }
91
- else if (/\.gtf?$/i.test(filePath)) {
92
- return {
93
- trackId: name,
94
- name,
95
- assemblyNames: [],
96
- adapter: {
97
- type: 'GtfAdapter',
98
- gtfLocation: makeLocation(filePath, protocol),
99
- },
100
- };
101
- }
102
- else if (/\.vcf$/i.test(filePath)) {
103
- return {
104
- trackId: name,
105
- name,
106
- assemblyNames: [],
107
- adapter: {
108
- type: 'VcfAdapter',
109
- vcfLocation: makeLocation(filePath, protocol),
110
- },
111
- };
112
- }
113
- else if (/\.gff3?$/i.test(filePath)) {
114
- return {
115
- trackId: name,
116
- name,
117
- assemblyNames: [],
118
- adapter: {
119
- type: 'Gff3Adapter',
120
- gffLocation: makeLocation(filePath, protocol),
121
- },
122
- };
123
- }
124
- else {
125
- throw new Error(`Unsupported file type ${filePath}`);
126
- }
127
- }
128
- async function generateMeta({ configs, attributesToIndex, outDir, name, featureTypesToExclude, assemblyNames, }) {
129
- fs_1.default.writeFileSync(path_1.default.join(outDir, 'trix', `${name}_meta.json`), JSON.stringify({
130
- dateCreated: new Date().toISOString(),
131
- tracks: configs.map(config => {
132
- const { trackId, textSearching, adapter } = config;
133
- return {
134
- trackId,
135
- attributesIndexed: (textSearching === null || textSearching === void 0 ? void 0 : textSearching.indexingAttributes) || attributesToIndex,
136
- excludedTypes: (textSearching === null || textSearching === void 0 ? void 0 : textSearching.indexingFeatureTypesToExclude) ||
137
- featureTypesToExclude,
138
- adapterConf: adapter,
139
- };
140
- }),
141
- assemblyNames,
142
- }, null, 2));
143
- }
@@ -1,11 +0,0 @@
1
- export declare function indexGff3({ config, attributesToIndex, inLocation, outDir, featureTypesToExclude, onStart, onUpdate, }: {
2
- config: {
3
- trackId: string;
4
- };
5
- attributesToIndex: string[];
6
- inLocation: string;
7
- outDir: string;
8
- featureTypesToExclude: string[];
9
- onStart: (totalBytes: number) => void;
10
- onUpdate: (progressBytes: number) => void;
11
- }): AsyncGenerator<string, void, unknown>;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.indexGff3 = indexGff3;
7
- const readline_1 = __importDefault(require("readline"));
8
- const zlib_1 = require("zlib");
9
- const util_1 = require("../util");
10
- const common_1 = require("./common");
11
- async function* indexGff3({ config, attributesToIndex, inLocation, outDir, featureTypesToExclude, onStart, onUpdate, }) {
12
- const { trackId } = config;
13
- const stream = await (0, common_1.getLocalOrRemoteStream)({
14
- file: inLocation,
15
- out: outDir,
16
- onTotalBytes: onStart,
17
- onBytesReceived: onUpdate,
18
- });
19
- const rl = readline_1.default.createInterface({
20
- input: /.b?gz$/.exec(inLocation) ? stream.pipe((0, zlib_1.createGunzip)()) : stream,
21
- });
22
- for await (const line of rl) {
23
- if (!line.trim()) {
24
- continue;
25
- }
26
- else if (line.startsWith('#')) {
27
- continue;
28
- }
29
- else if (line.startsWith('>')) {
30
- break;
31
- }
32
- const [seq_id, , type, start, end, , , , col9] = line.split('\t');
33
- const locStr = `${seq_id}:${start}..${end}`;
34
- if (!featureTypesToExclude.includes(type)) {
35
- const col9attrs = Object.fromEntries(col9
36
- .split(';')
37
- .map(f => f.trim())
38
- .filter(f => !!f)
39
- .map(f => f.split('='))
40
- .map(([key, val]) => [
41
- key.trim(),
42
- val
43
- ? (0, util_1.decodeURIComponentNoThrow)(val).trim().split(',').join(' ')
44
- : undefined,
45
- ]));
46
- const attrs = attributesToIndex
47
- .map(attr => col9attrs[attr])
48
- .filter((f) => !!f);
49
- if (attrs.length) {
50
- const record = JSON.stringify([
51
- encodeURIComponent(locStr),
52
- encodeURIComponent(trackId),
53
- ...attrs.map(a => encodeURIComponent(a)),
54
- ]).replaceAll(',', '|');
55
- yield `${record} ${[...new Set(attrs)].join(' ')}\n`;
56
- }
57
- }
58
- }
59
- }
@@ -1,8 +0,0 @@
1
- export declare function indexVcf({ config, attributesToIndex, inLocation, outDir, onStart, onUpdate, }: {
2
- config: any;
3
- attributesToIndex: string[];
4
- inLocation: string;
5
- outDir: string;
6
- onStart: (totalBytes: number) => void;
7
- onUpdate: (progressBytes: number) => void;
8
- }): AsyncGenerator<string, void, unknown>;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.indexVcf = indexVcf;
7
- const readline_1 = __importDefault(require("readline"));
8
- const zlib_1 = require("zlib");
9
- const util_1 = require("../util");
10
- const common_1 = require("./common");
11
- async function* indexVcf({ config, attributesToIndex, inLocation, outDir, onStart, onUpdate, }) {
12
- const { trackId } = config;
13
- const stream = await (0, common_1.getLocalOrRemoteStream)({
14
- file: inLocation,
15
- out: outDir,
16
- onTotalBytes: onStart,
17
- onBytesReceived: onUpdate,
18
- });
19
- const gzStream = /.b?gz$/.exec(inLocation)
20
- ? stream.pipe((0, zlib_1.createGunzip)())
21
- : stream;
22
- const rl = readline_1.default.createInterface({
23
- input: gzStream,
24
- });
25
- for await (const line of rl) {
26
- if (line.startsWith('#')) {
27
- continue;
28
- }
29
- const [ref, pos, id, _ref, _alt, _qual, _filter, info] = line.split('\t');
30
- const fields = Object.fromEntries(info
31
- .split(';')
32
- .map(f => f.trim())
33
- .filter(f => !!f)
34
- .map(f => f.split('='))
35
- .map(([key, val]) => [
36
- key.trim(),
37
- val
38
- ? (0, util_1.decodeURIComponentNoThrow)(val).trim().split(',').join(' ')
39
- : undefined,
40
- ]));
41
- const end = fields.END;
42
- const locStr = `${ref}:${pos}..${end || +pos + 1}`;
43
- if (id === '.') {
44
- continue;
45
- }
46
- const infoAttrs = attributesToIndex
47
- .map(attr => fields[attr])
48
- .filter((f) => !!f);
49
- const ids = id.split(',');
50
- for (const id of ids) {
51
- const attrs = [id];
52
- const record = JSON.stringify([
53
- encodeURIComponent(locStr),
54
- encodeURIComponent(trackId),
55
- encodeURIComponent(id || ''),
56
- ...infoAttrs.map(a => encodeURIComponent(a || '')),
57
- ]).replaceAll(',', '|');
58
- yield `${record} ${[...new Set(attrs)].join(' ')}\n`;
59
- }
60
- }
61
- }
package/dist/util.d.ts DELETED
@@ -1,127 +0,0 @@
1
- export interface UriLocation {
2
- uri: string;
3
- locationType: 'UriLocation';
4
- }
5
- export interface LocalPathLocation {
6
- localPath: string;
7
- locationType: 'LocalPathLocation';
8
- }
9
- export interface IndexedFastaAdapter {
10
- type: 'IndexedFastaAdapter';
11
- fastaLocation: UriLocation;
12
- faiLocation: UriLocation;
13
- }
14
- export interface BgzipFastaAdapter {
15
- type: 'BgzipFastaAdapter';
16
- fastaLocation: UriLocation;
17
- faiLocation: UriLocation;
18
- gziLocation: UriLocation;
19
- }
20
- export interface TwoBitAdapter {
21
- type: 'TwoBitAdapter';
22
- twoBitLocation: UriLocation;
23
- }
24
- export interface ChromeSizesAdapter {
25
- type: 'ChromSizesAdapter';
26
- chromSizesLocation: UriLocation;
27
- }
28
- export interface CustomSequenceAdapter {
29
- type: string;
30
- }
31
- export interface RefNameAliasAdapter {
32
- type: 'RefNameAliasAdapter';
33
- location: UriLocation;
34
- }
35
- export interface CustomRefNameAliasAdapter {
36
- type: string;
37
- }
38
- export interface Assembly {
39
- displayName?: string;
40
- name: string;
41
- aliases?: string[];
42
- sequence: Sequence;
43
- refNameAliases?: {
44
- adapter: RefNameAliasAdapter | CustomRefNameAliasAdapter;
45
- };
46
- refNameColors?: string[];
47
- }
48
- export interface Sequence {
49
- type: 'ReferenceSequenceTrack';
50
- trackId: string;
51
- adapter: IndexedFastaAdapter | BgzipFastaAdapter | TwoBitAdapter | ChromeSizesAdapter | CustomSequenceAdapter;
52
- }
53
- type Loc = UriLocation | LocalPathLocation;
54
- export interface Gff3TabixAdapter {
55
- type: 'Gff3TabixAdapter';
56
- gffGzLocation: Loc;
57
- }
58
- export interface Gff3Adapter {
59
- type: 'Gff3Adapter';
60
- gffLocation: Loc;
61
- }
62
- export interface GtfAdapter {
63
- type: 'GtfAdapter';
64
- gtfLocation: Loc;
65
- }
66
- export interface VcfTabixAdapter {
67
- type: 'VcfTabixAdapter';
68
- vcfGzLocation: Loc;
69
- }
70
- export interface VcfAdapter {
71
- type: 'VcfAdapter';
72
- vcfLocation: Loc;
73
- }
74
- export interface Track {
75
- adapter?: {
76
- type: string;
77
- [key: string]: unknown;
78
- };
79
- textSearching?: TextSearching;
80
- name: string;
81
- assemblyNames: string[];
82
- trackId: string;
83
- }
84
- export interface TextSearching {
85
- indexingFeatureTypesToExclude?: string[];
86
- indexingAttributes?: string[];
87
- textSearchAdapter: TrixTextSearchAdapter;
88
- }
89
- export interface TrixTextSearchAdapter {
90
- type: string;
91
- textSearchAdapterId: string;
92
- ixFilePath: UriLocation;
93
- ixxFilePath: UriLocation;
94
- metaFilePath: UriLocation;
95
- assemblyNames: string[];
96
- }
97
- export interface Config {
98
- assemblies?: Assembly[];
99
- assembly?: Assembly;
100
- configuration?: Record<string, unknown>;
101
- aggregateTextSearchAdapters?: TrixTextSearchAdapter[];
102
- connections?: unknown[];
103
- defaultSession?: Record<string, unknown>;
104
- tracks?: Track[];
105
- }
106
- export type indexType = 'aggregate' | 'perTrack';
107
- export declare function createTextSearchConf(name: string, trackIds: string[], assemblyNames: string[], locationPath: string): {
108
- type: string;
109
- textSearchAdapterId: string;
110
- ixFilePath: {
111
- localPath: string;
112
- locationType: string;
113
- };
114
- ixxFilePath: {
115
- localPath: string;
116
- locationType: string;
117
- };
118
- metaFilePath: {
119
- localPath: string;
120
- locationType: string;
121
- };
122
- tracks: string[];
123
- assemblyNames: string[];
124
- };
125
- export declare function findTrackConfigsToIndex(tracks: Track[], trackIds: string[], assemblyName?: string): Track[];
126
- export declare function decodeURIComponentNoThrow(uri: string): string;
127
- export {};
package/dist/util.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createTextSearchConf = createTextSearchConf;
7
- exports.findTrackConfigsToIndex = findTrackConfigsToIndex;
8
- exports.decodeURIComponentNoThrow = decodeURIComponentNoThrow;
9
- const path_1 = __importDefault(require("path"));
10
- const util_1 = require("@jbrowse/core/util");
11
- const sanitize_filename_1 = __importDefault(require("sanitize-filename"));
12
- function createTextSearchConf(name, trackIds, assemblyNames, locationPath) {
13
- const base = path_1.default.join(locationPath, 'trix');
14
- const n = (0, sanitize_filename_1.default)(name);
15
- return {
16
- type: 'TrixTextSearchAdapter',
17
- textSearchAdapterId: name,
18
- ixFilePath: {
19
- localPath: path_1.default.join(base, `${n}.ix`),
20
- locationType: 'LocalPathLocation',
21
- },
22
- ixxFilePath: {
23
- localPath: path_1.default.join(base, `${n}.ixx`),
24
- locationType: 'LocalPathLocation',
25
- },
26
- metaFilePath: {
27
- localPath: path_1.default.join(base, `${n}.json`),
28
- locationType: 'LocalPathLocation',
29
- },
30
- tracks: trackIds,
31
- assemblyNames,
32
- };
33
- }
34
- function findTrackConfigsToIndex(tracks, trackIds, assemblyName) {
35
- return trackIds
36
- .map(trackId => {
37
- const currentTrack = tracks.find(t => trackId === t.trackId);
38
- if (!currentTrack) {
39
- throw new Error(`Track not found in session for trackId ${trackId}`);
40
- }
41
- return currentTrack;
42
- })
43
- .filter(track => assemblyName ? track.assemblyNames.includes(assemblyName) : true)
44
- .filter(track => { var _a; return (0, util_1.isSupportedIndexingAdapter)((_a = track.adapter) === null || _a === void 0 ? void 0 : _a.type); });
45
- }
46
- function decodeURIComponentNoThrow(uri) {
47
- try {
48
- return decodeURIComponent(uri);
49
- }
50
- catch (e) {
51
- return uri;
52
- }
53
- }