@jbrowse/text-indexing 2.6.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.
- package/LICENSE +201 -0
- package/dist/TextIndexing.d.ts +11 -0
- package/dist/TextIndexing.js +135 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +20 -0
- package/dist/types/common.d.ts +28 -0
- package/dist/types/common.js +154 -0
- package/dist/types/gff3Adapter.d.ts +2 -0
- package/dist/types/gff3Adapter.js +62 -0
- package/dist/types/vcfAdapter.d.ts +2 -0
- package/dist/types/vcfAdapter.js +67 -0
- package/dist/util.d.ts +118 -0
- package/dist/util.js +52 -0
- package/esm/TextIndexing.d.ts +11 -0
- package/esm/TextIndexing.js +128 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/esm/types/common.d.ts +28 -0
- package/esm/types/common.js +142 -0
- package/esm/types/gff3Adapter.d.ts +2 -0
- package/esm/types/gff3Adapter.js +55 -0
- package/esm/types/vcfAdapter.d.ts +2 -0
- package/esm/types/vcfAdapter.js +60 -0
- package/esm/util.d.ts +118 -0
- package/esm/util.js +46 -0
- package/package.json +61 -0
- package/src/TextIndexing.ts +283 -0
- package/src/index.ts +3 -0
- package/src/types/common.test.ts +38 -0
- package/src/types/common.ts +170 -0
- package/src/types/gff3Adapter.ts +75 -0
- package/src/types/vcfAdapter.ts +86 -0
- package/src/util.ts +177 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2020] [Evolutionary Software Foundation]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Track, indexType } from './util';
|
|
2
|
+
export declare function indexTracks(args: {
|
|
3
|
+
tracks: Track[];
|
|
4
|
+
outLocation?: string;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
attributes?: string[];
|
|
7
|
+
assemblies?: string[];
|
|
8
|
+
exclude?: string[];
|
|
9
|
+
indexType?: indexType;
|
|
10
|
+
statusCallback: (message: string) => void;
|
|
11
|
+
}): Promise<never[]>;
|
|
@@ -0,0 +1,135 @@
|
|
|
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 = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const stream_1 = require("stream");
|
|
10
|
+
const gff3Adapter_1 = require("./types/gff3Adapter");
|
|
11
|
+
const vcfAdapter_1 = require("./types/vcfAdapter");
|
|
12
|
+
const common_1 = require("./types/common");
|
|
13
|
+
const ixixx_1 = require("ixixx");
|
|
14
|
+
const util_1 = require("./util");
|
|
15
|
+
const util_2 = require("@jbrowse/core/util");
|
|
16
|
+
async function indexTracks(args) {
|
|
17
|
+
const { tracks, outLocation, attributes, exclude, assemblies, indexType, statusCallback, signal, } = args;
|
|
18
|
+
const idxType = indexType || 'perTrack';
|
|
19
|
+
(0, util_2.checkAbortSignal)(signal);
|
|
20
|
+
await (idxType === 'perTrack'
|
|
21
|
+
? perTrackIndex(tracks, statusCallback, outLocation, attributes, exclude, signal)
|
|
22
|
+
: aggregateIndex(tracks, statusCallback, outLocation, attributes, assemblies, exclude, signal));
|
|
23
|
+
(0, util_2.checkAbortSignal)(signal);
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
exports.indexTracks = indexTracks;
|
|
27
|
+
async function perTrackIndex(tracks, statusCallback, outLocation, attributes, exclude, signal) {
|
|
28
|
+
const outFlag = outLocation || '.';
|
|
29
|
+
const isDir = fs_1.default.lstatSync(outFlag).isDirectory();
|
|
30
|
+
const confFilePath = isDir ? path_1.default.join(outFlag, 'config.json') : outFlag;
|
|
31
|
+
const outDir = path_1.default.dirname(confFilePath);
|
|
32
|
+
const trixDir = path_1.default.join(outDir, 'trix');
|
|
33
|
+
if (!fs_1.default.existsSync(trixDir)) {
|
|
34
|
+
fs_1.default.mkdirSync(trixDir);
|
|
35
|
+
}
|
|
36
|
+
// default settings
|
|
37
|
+
const attrs = attributes || ['Name', 'ID'];
|
|
38
|
+
const excludeTypes = exclude || ['exon', 'CDS'];
|
|
39
|
+
const force = true;
|
|
40
|
+
const supportedTracks = tracks.filter(track => { var _a; return (0, util_1.supportedIndexingAdapters)((_a = track.adapter) === null || _a === void 0 ? void 0 : _a.type); });
|
|
41
|
+
for (const trackConfig of supportedTracks) {
|
|
42
|
+
const { textSearching, trackId, assemblyNames } = trackConfig;
|
|
43
|
+
const id = `${trackId}-index`;
|
|
44
|
+
if ((textSearching === null || textSearching === void 0 ? void 0 : textSearching.textSearchAdapter) && !force) {
|
|
45
|
+
console.warn(`Note: ${trackId} has already been indexed with this configuration, use --force to overwrite this track. Skipping for now`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
await indexDriver([trackConfig], outDir, attrs, id, true, excludeTypes, assemblyNames, statusCallback, signal);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function aggregateIndex(tracks, statusCallback, outLocation, attributes, assemblies, exclude, signal) {
|
|
52
|
+
const outFlag = outLocation || '.';
|
|
53
|
+
const isDir = fs_1.default.lstatSync(outFlag).isDirectory();
|
|
54
|
+
const confFilePath = isDir ? path_1.default.join(outFlag, 'config.json') : outFlag;
|
|
55
|
+
const outDir = path_1.default.dirname(confFilePath);
|
|
56
|
+
const trixDir = path_1.default.join(outDir, 'trix');
|
|
57
|
+
if (!fs_1.default.existsSync(trixDir)) {
|
|
58
|
+
fs_1.default.mkdirSync(trixDir);
|
|
59
|
+
}
|
|
60
|
+
if (!assemblies) {
|
|
61
|
+
throw new Error('No assemblies passed. Assmeblies required for aggregate indexes');
|
|
62
|
+
}
|
|
63
|
+
for (const asm of assemblies) {
|
|
64
|
+
// console.log('Indexing assembly ' + asm + '...')
|
|
65
|
+
const id = asm + '-index';
|
|
66
|
+
// default settings
|
|
67
|
+
const attrs = attributes || ['Name', 'ID'];
|
|
68
|
+
const excludeTypes = exclude || ['exon', 'CDS'];
|
|
69
|
+
// const force = true
|
|
70
|
+
const quiet = true;
|
|
71
|
+
// supported tracks for given assembly
|
|
72
|
+
const supportedTracks = tracks
|
|
73
|
+
.filter(track => { var _a; return (0, util_1.supportedIndexingAdapters)((_a = track.adapter) === null || _a === void 0 ? void 0 : _a.type); })
|
|
74
|
+
.filter(track => (asm ? track.assemblyNames.includes(asm) : true));
|
|
75
|
+
await indexDriver(supportedTracks, outDir, attrs, id, quiet, excludeTypes, [asm], statusCallback, signal);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function indexDriver(tracks, idxLocation, attributes, name, quiet, exclude, assemblyNames, statusCallback, signal) {
|
|
79
|
+
const readable = stream_1.Readable.from(indexFiles(tracks, attributes, idxLocation, quiet, exclude, statusCallback, signal));
|
|
80
|
+
statusCallback('Indexing files.');
|
|
81
|
+
try {
|
|
82
|
+
const ixIxxStream = await runIxIxx(readable, idxLocation, name);
|
|
83
|
+
(0, util_2.checkAbortSignal)(signal);
|
|
84
|
+
await (0, common_1.generateMeta)({
|
|
85
|
+
configs: tracks,
|
|
86
|
+
attributes,
|
|
87
|
+
outDir: idxLocation,
|
|
88
|
+
name,
|
|
89
|
+
exclude,
|
|
90
|
+
assemblyNames,
|
|
91
|
+
});
|
|
92
|
+
(0, util_2.checkAbortSignal)(signal);
|
|
93
|
+
return ixIxxStream;
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
throw e;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function* indexFiles(tracks, attributes, outLocation, quiet, typesToExclude, statusCallback, signal) {
|
|
100
|
+
for (const track of tracks) {
|
|
101
|
+
const { adapter, textSearching } = track;
|
|
102
|
+
const { type } = adapter;
|
|
103
|
+
const { indexingFeatureTypesToExclude: types = typesToExclude, indexingAttributes: attrs = attributes, } = textSearching || {};
|
|
104
|
+
// currently only supporting GFF3Tabix and VCFTabix
|
|
105
|
+
switch (type) {
|
|
106
|
+
case 'Gff3TabixAdapter': {
|
|
107
|
+
yield* (0, gff3Adapter_1.indexGff3)(track, attrs, getLoc('gffGzLocation', track), outLocation, types, quiet, statusCallback, signal);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case 'Gff3Adapter': {
|
|
111
|
+
yield* (0, gff3Adapter_1.indexGff3)(track, attrs, getLoc('gffLocation', track), outLocation, types, quiet, statusCallback, signal);
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case 'VcfTabixAdapter': {
|
|
115
|
+
yield* (0, vcfAdapter_1.indexVcf)(track, attrs, getLoc('vcfGzLocation', track), outLocation, types, quiet, statusCallback, signal);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case 'VcfAdapter': {
|
|
119
|
+
yield* (0, vcfAdapter_1.indexVcf)(track, attrs, getLoc('vcfLocation', track), outLocation, types, quiet, statusCallback, signal);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
// No default
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
function getLoc(attr, config) {
|
|
128
|
+
const elt = config.adapter[attr];
|
|
129
|
+
return elt.uri || elt.localPath;
|
|
130
|
+
}
|
|
131
|
+
function runIxIxx(readStream, idxLocation, name) {
|
|
132
|
+
const ixFilename = path_1.default.join(idxLocation, 'trix', `${name}.ix`);
|
|
133
|
+
const ixxFilename = path_1.default.join(idxLocation, 'trix', `${name}.ixx`);
|
|
134
|
+
return (0, ixixx_1.ixIxxStream)(readStream, ixFilename, ixxFilename);
|
|
135
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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.indexTracks = void 0;
|
|
18
|
+
__exportStar(require("./util"), exports);
|
|
19
|
+
var TextIndexing_1 = require("./TextIndexing");
|
|
20
|
+
Object.defineProperty(exports, "indexTracks", { enumerable: true, get: function () { return TextIndexing_1.indexTracks; } });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { LocalPathLocation, UriLocation, Track } from '../util';
|
|
5
|
+
export declare function createRemoteStream(urlIn: string): Promise<import("node-fetch").Response>;
|
|
6
|
+
export declare function isURL(FileName: string): boolean;
|
|
7
|
+
export declare function getLocalOrRemoteStream(uri: string, out: string): Promise<{
|
|
8
|
+
totalBytes: number;
|
|
9
|
+
stream: NodeJS.ReadableStream | fs.ReadStream;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function makeLocation(location: string, protocol: string): UriLocation | LocalPathLocation;
|
|
12
|
+
export declare function guessAdapterFromFileName(filePath: string): Track;
|
|
13
|
+
/**
|
|
14
|
+
* Generates metadata of index given a filename (trackId or assembly)
|
|
15
|
+
* @param name - assembly name or trackId
|
|
16
|
+
* @param attributes - attributes indexed
|
|
17
|
+
* @param include - feature types included from index
|
|
18
|
+
* @param exclude - feature types excluded from index
|
|
19
|
+
* @param configs - list of track
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateMeta({ configs, attributes, outDir, name, exclude, assemblyNames, }: {
|
|
22
|
+
configs: Track[];
|
|
23
|
+
attributes: string[];
|
|
24
|
+
outDir: string;
|
|
25
|
+
name: string;
|
|
26
|
+
exclude: string[];
|
|
27
|
+
assemblyNames: string[];
|
|
28
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,154 @@
|
|
|
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.generateMeta = exports.guessAdapterFromFileName = exports.makeLocation = exports.getLocalOrRemoteStream = exports.isURL = exports.createRemoteStream = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
// Method for handing off the parsing of a gff3 file URL.
|
|
11
|
+
// Calls the proper parser depending on if it is gzipped or not.
|
|
12
|
+
// Returns a @gmod/gff stream.
|
|
13
|
+
async function createRemoteStream(urlIn) {
|
|
14
|
+
const response = await (0, node_fetch_1.default)(urlIn);
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
throw new Error(`Failed to fetch ${urlIn} status ${response.status} ${response.statusText}`);
|
|
17
|
+
}
|
|
18
|
+
return response;
|
|
19
|
+
}
|
|
20
|
+
exports.createRemoteStream = createRemoteStream;
|
|
21
|
+
// Checks if the passed in string is a valid URL.
|
|
22
|
+
// Returns a boolean.
|
|
23
|
+
function isURL(FileName) {
|
|
24
|
+
let url;
|
|
25
|
+
try {
|
|
26
|
+
url = new URL(FileName);
|
|
27
|
+
}
|
|
28
|
+
catch (_) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
32
|
+
}
|
|
33
|
+
exports.isURL = isURL;
|
|
34
|
+
async function getLocalOrRemoteStream(uri, out) {
|
|
35
|
+
var _a;
|
|
36
|
+
let stream;
|
|
37
|
+
let totalBytes = 0;
|
|
38
|
+
if (isURL(uri)) {
|
|
39
|
+
const result = await createRemoteStream(uri);
|
|
40
|
+
totalBytes = +(((_a = result.headers) === null || _a === void 0 ? void 0 : _a.get('Content-Length')) || 0);
|
|
41
|
+
stream = result.body;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const filename = path_1.default.isAbsolute(uri) ? uri : path_1.default.join(out, uri);
|
|
45
|
+
totalBytes = fs_1.default.statSync(filename).size;
|
|
46
|
+
stream = fs_1.default.createReadStream(filename);
|
|
47
|
+
}
|
|
48
|
+
return { totalBytes, stream };
|
|
49
|
+
}
|
|
50
|
+
exports.getLocalOrRemoteStream = getLocalOrRemoteStream;
|
|
51
|
+
function makeLocation(location, protocol) {
|
|
52
|
+
if (protocol === 'uri') {
|
|
53
|
+
return { uri: location, locationType: 'UriLocation' };
|
|
54
|
+
}
|
|
55
|
+
if (protocol === 'localPath') {
|
|
56
|
+
return {
|
|
57
|
+
localPath: path_1.default.resolve(location),
|
|
58
|
+
locationType: 'LocalPathLocation',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`invalid protocol ${protocol}`);
|
|
62
|
+
}
|
|
63
|
+
exports.makeLocation = makeLocation;
|
|
64
|
+
function guessAdapterFromFileName(filePath) {
|
|
65
|
+
// const uri = isURL(filePath) ? filePath : path.resolve(filePath)
|
|
66
|
+
const protocol = isURL(filePath) ? 'uri' : 'localPath';
|
|
67
|
+
const name = path_1.default.basename(filePath);
|
|
68
|
+
if (/\.vcf\.b?gz$/i.test(filePath)) {
|
|
69
|
+
return {
|
|
70
|
+
trackId: name,
|
|
71
|
+
name: name,
|
|
72
|
+
assemblyNames: [],
|
|
73
|
+
adapter: {
|
|
74
|
+
type: 'VcfTabixAdapter',
|
|
75
|
+
vcfGzLocation: makeLocation(filePath, protocol),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else if (/\.gff3?\.b?gz$/i.test(filePath)) {
|
|
80
|
+
return {
|
|
81
|
+
trackId: name,
|
|
82
|
+
name,
|
|
83
|
+
assemblyNames: [],
|
|
84
|
+
adapter: {
|
|
85
|
+
type: 'Gff3TabixAdapter',
|
|
86
|
+
gffGzLocation: makeLocation(filePath, protocol),
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
else if (/\.gtf?$/i.test(filePath)) {
|
|
91
|
+
return {
|
|
92
|
+
trackId: name,
|
|
93
|
+
name,
|
|
94
|
+
assemblyNames: [],
|
|
95
|
+
adapter: {
|
|
96
|
+
type: 'GtfAdapter',
|
|
97
|
+
gtfLocation: makeLocation(filePath, protocol),
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
else if (/\.vcf$/i.test(filePath)) {
|
|
102
|
+
return {
|
|
103
|
+
trackId: name,
|
|
104
|
+
name,
|
|
105
|
+
assemblyNames: [],
|
|
106
|
+
adapter: {
|
|
107
|
+
type: 'VcfAdapter',
|
|
108
|
+
vcfLocation: makeLocation(filePath, protocol),
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
else if (/\.gff3?$/i.test(filePath)) {
|
|
113
|
+
return {
|
|
114
|
+
trackId: name,
|
|
115
|
+
name,
|
|
116
|
+
assemblyNames: [],
|
|
117
|
+
adapter: {
|
|
118
|
+
type: 'Gff3Adapter',
|
|
119
|
+
gffLocation: makeLocation(filePath, protocol),
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
throw new Error(`Unsupported file type ${filePath}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.guessAdapterFromFileName = guessAdapterFromFileName;
|
|
128
|
+
/**
|
|
129
|
+
* Generates metadata of index given a filename (trackId or assembly)
|
|
130
|
+
* @param name - assembly name or trackId
|
|
131
|
+
* @param attributes - attributes indexed
|
|
132
|
+
* @param include - feature types included from index
|
|
133
|
+
* @param exclude - feature types excluded from index
|
|
134
|
+
* @param configs - list of track
|
|
135
|
+
*/
|
|
136
|
+
async function generateMeta({ configs, attributes, outDir, name, exclude, assemblyNames, }) {
|
|
137
|
+
const tracks = configs.map(config => {
|
|
138
|
+
const { trackId, textSearching, adapter } = config;
|
|
139
|
+
const includeExclude = (textSearching === null || textSearching === void 0 ? void 0 : textSearching.indexingFeatureTypesToExclude) || exclude;
|
|
140
|
+
const metaAttrs = (textSearching === null || textSearching === void 0 ? void 0 : textSearching.indexingAttributes) || attributes;
|
|
141
|
+
return {
|
|
142
|
+
trackId: trackId,
|
|
143
|
+
attributesIndexed: metaAttrs,
|
|
144
|
+
excludedTypes: includeExclude,
|
|
145
|
+
adapterConf: adapter,
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
fs_1.default.writeFileSync(path_1.default.join(outDir, 'trix', `${name}_meta.json`), JSON.stringify({
|
|
149
|
+
dateCreated: new Date().toISOString(),
|
|
150
|
+
tracks,
|
|
151
|
+
assemblyNames,
|
|
152
|
+
}, null, 2));
|
|
153
|
+
}
|
|
154
|
+
exports.generateMeta = generateMeta;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Track } from '../util';
|
|
2
|
+
export declare function indexGff3(config: Track, attributes: string[], inLocation: string, outLocation: string, typesToExclude: string[], quiet: boolean, statusCallback: (message: string) => void, signal?: AbortSignal): AsyncGenerator<string, void, unknown>;
|
|
@@ -0,0 +1,62 @@
|
|
|
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 = void 0;
|
|
7
|
+
const zlib_1 = require("zlib");
|
|
8
|
+
const readline_1 = __importDefault(require("readline"));
|
|
9
|
+
const common_1 = require("./common");
|
|
10
|
+
const util_1 = require("@jbrowse/core/util");
|
|
11
|
+
async function* indexGff3(config, attributes, inLocation, outLocation, typesToExclude, quiet, statusCallback, signal) {
|
|
12
|
+
const { trackId } = config;
|
|
13
|
+
let receivedBytes = 0;
|
|
14
|
+
const { totalBytes, stream } = await (0, common_1.getLocalOrRemoteStream)(inLocation, outLocation);
|
|
15
|
+
stream.on('data', chunk => {
|
|
16
|
+
receivedBytes += chunk.length;
|
|
17
|
+
// send an update?
|
|
18
|
+
const progress = Math.round((receivedBytes / totalBytes) * 100);
|
|
19
|
+
statusCallback(`${progress}`);
|
|
20
|
+
});
|
|
21
|
+
const rl = readline_1.default.createInterface({
|
|
22
|
+
input: inLocation.match(/.b?gz$/) ? stream.pipe((0, zlib_1.createGunzip)()) : stream,
|
|
23
|
+
});
|
|
24
|
+
for await (const line of rl) {
|
|
25
|
+
if (line.startsWith('#')) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
else if (line.startsWith('>')) {
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
const [seq_id, , type, start, end, , , , col9] = line.split('\t');
|
|
32
|
+
const locStr = `${seq_id}:${start}..${end}`;
|
|
33
|
+
if (!typesToExclude.includes(type)) {
|
|
34
|
+
// turns gff3 attrs into a map, and converts the arrays into space
|
|
35
|
+
// separated strings
|
|
36
|
+
const col9attrs = Object.fromEntries(col9
|
|
37
|
+
.split(';')
|
|
38
|
+
.map(f => f.trim())
|
|
39
|
+
.filter(f => !!f)
|
|
40
|
+
.map(f => f.split('='))
|
|
41
|
+
.map(([key, val]) => [
|
|
42
|
+
key.trim(),
|
|
43
|
+
decodeURIComponent(val).trim().split(',').join(' '),
|
|
44
|
+
]));
|
|
45
|
+
const attrs = attributes
|
|
46
|
+
.map(attr => col9attrs[attr])
|
|
47
|
+
.filter((f) => !!f);
|
|
48
|
+
if (attrs.length) {
|
|
49
|
+
const record = JSON.stringify([
|
|
50
|
+
encodeURIComponent(locStr),
|
|
51
|
+
encodeURIComponent(trackId),
|
|
52
|
+
...attrs.map(a => encodeURIComponent(a)),
|
|
53
|
+
]).replaceAll(',', '|');
|
|
54
|
+
// Check abort signal
|
|
55
|
+
(0, util_1.checkAbortSignal)(signal);
|
|
56
|
+
yield `${record} ${[...new Set(attrs)].join(' ')}\n`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// console.log('done')
|
|
61
|
+
}
|
|
62
|
+
exports.indexGff3 = indexGff3;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Track } from '../util';
|
|
2
|
+
export declare function indexVcf(config: Track, attributesToIndex: string[], inLocation: string, outLocation: string, typesToExclude: string[], quiet: boolean, statusCallback: (message: string) => void, signal?: AbortSignal): AsyncGenerator<string, void, unknown>;
|