@jbrowse/cli 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.
Files changed (58) hide show
  1. package/README.md +4 -0
  2. package/bin/run +0 -0
  3. package/bundle/index.js +2280 -2722
  4. package/dist/bin.js +2 -2
  5. package/dist/commands/{add-assembly.js → add-assembly/index.js} +10 -10
  6. package/dist/commands/{assembly-utils.js → add-assembly/utils.js} +69 -105
  7. package/dist/commands/add-connection.js +10 -15
  8. package/dist/commands/add-track-json.js +26 -31
  9. package/dist/commands/add-track-utils/track-config.js +3 -15
  10. package/dist/commands/add-track-utils/validators.js +4 -9
  11. package/dist/commands/add-track.js +23 -25
  12. package/dist/commands/{admin-server.js → admin-server/index.js} +9 -9
  13. package/dist/commands/{admin-server-utils.js → admin-server/utils.js} +7 -16
  14. package/dist/commands/create.js +8 -8
  15. package/dist/commands/{make-pif.js → make-pif/index.js} +11 -17
  16. package/dist/commands/{make-pif-utils → make-pif}/pif-generator.js +6 -6
  17. package/dist/commands/{sort-bed-utils/process-utils.js → process-utils.js} +0 -10
  18. package/dist/commands/remove-track.js +6 -11
  19. package/dist/commands/set-default-session.js +8 -12
  20. package/dist/commands/shared/config-operations.js +37 -0
  21. package/dist/commands/shared/sort-utils.js +57 -0
  22. package/dist/commands/shared/validators.js +18 -0
  23. package/dist/commands/sort-bed.js +13 -24
  24. package/dist/commands/sort-gff.js +13 -24
  25. package/dist/commands/text-index/adapter-utils.js +43 -0
  26. package/dist/commands/text-index/aggregate.js +52 -0
  27. package/dist/commands/{text-index.js → text-index/command.js} +13 -6
  28. package/dist/commands/text-index/config-utils.js +134 -0
  29. package/dist/commands/{text-index-utils → text-index}/file-list.js +12 -15
  30. package/dist/commands/text-index/index.js +11 -0
  31. package/dist/commands/{text-index-utils → text-index}/indexing-utils.js +30 -20
  32. package/dist/commands/text-index/per-track.js +54 -0
  33. package/dist/commands/track-utils.js +33 -33
  34. package/dist/commands/upgrade.js +8 -8
  35. package/dist/index.js +39 -27
  36. package/dist/types/common.js +9 -8
  37. package/dist/types/gff3Adapter.js +17 -48
  38. package/dist/types/streamUtils.js +66 -0
  39. package/dist/types/vcfAdapter.js +17 -54
  40. package/dist/util.js +14 -7
  41. package/dist/utils.js +10 -5
  42. package/package.json +14 -17
  43. package/dist/commands/make-pif-utils/validators.js +0 -22
  44. package/dist/commands/sort-bed-utils/constants.js +0 -12
  45. package/dist/commands/sort-bed-utils/sort-utils.js +0 -24
  46. package/dist/commands/sort-bed-utils/validators.js +0 -22
  47. package/dist/commands/sort-gff-utils/constants.js +0 -13
  48. package/dist/commands/sort-gff-utils/process-utils.js +0 -23
  49. package/dist/commands/sort-gff-utils/sort-utils.js +0 -55
  50. package/dist/commands/sort-gff-utils/validators.js +0 -21
  51. package/dist/commands/text-index-utils/adapter-utils.js +0 -63
  52. package/dist/commands/text-index-utils/aggregate.js +0 -87
  53. package/dist/commands/text-index-utils/config-utils.js +0 -59
  54. package/dist/commands/text-index-utils/index.js +0 -9
  55. package/dist/commands/text-index-utils/per-track.js +0 -65
  56. /package/dist/commands/{make-pif-utils → make-pif}/cigar-utils.js +0 -0
  57. /package/dist/commands/{make-pif-utils → make-pif}/file-utils.js +0 -0
  58. /package/dist/commands/{text-index-utils → text-index}/validators.js +0 -0
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.waitForProcessClose = waitForProcessClose;
4
- exports.handleProcessError = handleProcessError;
5
- async function waitForProcessClose(child) {
6
- return new Promise((resolve, reject) => {
7
- child.on('close', code => {
8
- resolve(code);
9
- });
10
- child.on('error', err => {
11
- reject(err);
12
- });
13
- });
14
- }
15
- function handleProcessError(error) {
16
- if (error instanceof Error) {
17
- console.error(`Process error: ${error.message}`);
18
- }
19
- else {
20
- console.error('Unknown process error:', error);
21
- }
22
- process.exit(1);
23
- }
@@ -1,55 +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.getMinimalEnvironment = getMinimalEnvironment;
7
- exports.createSortCommandForStdin = createSortCommandForStdin;
8
- exports.createSortCommandForFile = createSortCommandForFile;
9
- exports.spawnSortProcessFromFile = spawnSortProcessFromFile;
10
- exports.spawnSortProcessFromStdin = spawnSortProcessFromStdin;
11
- exports.spawnSortProcess = spawnSortProcess;
12
- const child_process_1 = require("child_process");
13
- const tmp_1 = __importDefault(require("tmp"));
14
- function getMinimalEnvironment() {
15
- return {
16
- ...process.env,
17
- LC_ALL: 'C',
18
- };
19
- }
20
- function createSortCommandForStdin() {
21
- // Create a temporary file to store stdin content, then process it
22
- // This allows us to read the data twice - once for headers, once for sorting
23
- const tmpFile = tmp_1.default.fileSync({
24
- prefix: 'jbrowse-sort-gff',
25
- }).name;
26
- const sortCmd = `sort -t"\`printf '\\t'\`" -k1,1 -k4,4n`;
27
- // Save stdin to temp file, extract headers, sort non-headers, then cleanup
28
- return `cat > ${tmpFile} && (grep "^#" ${tmpFile}; grep -v "^#" ${tmpFile} | ${sortCmd}) && rm -f ${tmpFile}`;
29
- }
30
- function createSortCommandForFile(file) {
31
- // When reading from a file, we can read it multiple times directly
32
- // Need to wrap in parentheses to ensure both grep outputs are combined
33
- return `(grep "^#" "${file}"; grep -v "^#" "${file}" | sort -t"\`printf '\\t'\`" -k1,1 -k4,4n)`;
34
- }
35
- function spawnSortProcessFromFile(file) {
36
- const command = createSortCommandForFile(file);
37
- const env = getMinimalEnvironment();
38
- return (0, child_process_1.spawn)('sh', ['-c', command], {
39
- env,
40
- stdio: 'inherit',
41
- });
42
- }
43
- function spawnSortProcessFromStdin() {
44
- const command = createSortCommandForStdin();
45
- const env = getMinimalEnvironment();
46
- return (0, child_process_1.spawn)('sh', ['-c', command], {
47
- env,
48
- stdio: 'inherit',
49
- });
50
- }
51
- function spawnSortProcess(options) {
52
- return options.file
53
- ? spawnSortProcessFromFile(options.file)
54
- : spawnSortProcessFromStdin();
55
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateFileArgument = validateFileArgument;
4
- exports.validateRequiredCommands = validateRequiredCommands;
5
- const command_exists_1 = require("command-exists");
6
- function validateFileArgument(file) {
7
- // Allow no file argument for stdin input
8
- if (!file && process.stdin.isTTY) {
9
- console.error('Error: Missing required argument: file');
10
- console.error('Usage: jbrowse sort-gff <file>');
11
- console.error(' OR pipe data via stdin: cat file.gff | jbrowse sort-gff');
12
- process.exit(1);
13
- }
14
- }
15
- function validateRequiredCommands() {
16
- const requiredCommands = ['sh', 'sort', 'grep'];
17
- const missingCommands = requiredCommands.filter(cmd => !(0, command_exists_1.sync)(cmd));
18
- if (missingCommands.length > 0) {
19
- throw new Error('Error: Unable to sort, requires unix type environment with sort, grep');
20
- }
21
- }
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLoc = getLoc;
4
- exports.createTrixAdapter = createTrixAdapter;
5
- exports.createPerTrackTrixAdapter = createPerTrackTrixAdapter;
6
- exports.getAdapterLocation = getAdapterLocation;
7
- function getLoc(elt) {
8
- return elt.locationType === 'LocalPathLocation' ? elt.localPath : elt.uri;
9
- }
10
- function createTrixAdapter(id, asm, assemblyNames) {
11
- return {
12
- type: 'TrixTextSearchAdapter',
13
- textSearchAdapterId: id,
14
- ixFilePath: {
15
- uri: `trix/${asm}.ix`,
16
- locationType: 'UriLocation',
17
- },
18
- ixxFilePath: {
19
- uri: `trix/${asm}.ixx`,
20
- locationType: 'UriLocation',
21
- },
22
- metaFilePath: {
23
- uri: `trix/${asm}_meta.json`,
24
- locationType: 'UriLocation',
25
- },
26
- assemblyNames: assemblyNames || [asm],
27
- };
28
- }
29
- function createPerTrackTrixAdapter(trackId, assemblyNames) {
30
- return {
31
- type: 'TrixTextSearchAdapter',
32
- textSearchAdapterId: `${trackId}-index`,
33
- ixFilePath: {
34
- uri: `trix/${trackId}.ix`,
35
- locationType: 'UriLocation',
36
- },
37
- ixxFilePath: {
38
- uri: `trix/${trackId}.ixx`,
39
- locationType: 'UriLocation',
40
- },
41
- metaFilePath: {
42
- uri: `trix/${trackId}_meta.json`,
43
- locationType: 'UriLocation',
44
- },
45
- assemblyNames: assemblyNames,
46
- };
47
- }
48
- function getAdapterLocation(adapter) {
49
- const { type } = adapter || {};
50
- if (type === 'Gff3TabixAdapter') {
51
- return adapter.gffGzLocation || adapter;
52
- }
53
- else if (type === 'Gff3Adapter') {
54
- return adapter.gffLocation || adapter;
55
- }
56
- else if (type === 'VcfAdapter') {
57
- return adapter.vcfLocation || adapter;
58
- }
59
- else if (type === 'VcfTabixAdapter') {
60
- return adapter.vcfGzLocation || adapter;
61
- }
62
- return undefined;
63
- }
@@ -1,87 +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.aggregateIndex = aggregateIndex;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const config_utils_1 = require("./config-utils");
10
- const indexing_utils_1 = require("./indexing-utils");
11
- async function aggregateIndex(flags) {
12
- const { out, target, tracks, assemblies, attributes, quiet, force, exclude, dryrun, prefixSize, } = flags;
13
- const outFlag = target || out || '.';
14
- const isDir = fs_1.default.lstatSync(outFlag).isDirectory();
15
- const confPath = isDir ? path_1.default.join(outFlag, 'config.json') : outFlag;
16
- const outLocation = path_1.default.dirname(confPath);
17
- const config = (0, config_utils_1.readConf)(confPath);
18
- const trixDir = path_1.default.join(outLocation, 'trix');
19
- if (!fs_1.default.existsSync(trixDir)) {
20
- fs_1.default.mkdirSync(trixDir);
21
- }
22
- const aggregateTextSearchAdapters = config.aggregateTextSearchAdapters || [];
23
- const asms = assemblies?.split(',') ||
24
- config.assemblies?.map(a => a.name) ||
25
- (config.assembly ? [config.assembly.name] : []);
26
- if (!asms.length) {
27
- throw new Error('No assemblies found');
28
- }
29
- for (const asm of asms) {
30
- const trackConfigs = (0, config_utils_1.getTrackConfigs)(confPath, tracks?.split(','), asm);
31
- if (!trackConfigs.length) {
32
- console.log(`Indexing assembly ${asm}...(no tracks found)...`);
33
- continue;
34
- }
35
- console.log(`Indexing assembly ${asm}...`);
36
- if (dryrun) {
37
- console.log(trackConfigs.map(e => `${e.trackId} ${e.adapter?.type}`).join('\n'));
38
- }
39
- else {
40
- const id = `${asm}-index`;
41
- const idx = aggregateTextSearchAdapters.findIndex(x => x.textSearchAdapterId === id);
42
- if (idx !== -1 && !force) {
43
- console.log(`Note: ${asm} has already been indexed with this configuration, use --force to overwrite this assembly. Skipping for now`);
44
- continue;
45
- }
46
- await (0, indexing_utils_1.indexDriver)({
47
- trackConfigs,
48
- outLocation,
49
- quiet,
50
- name: asm,
51
- attributes: attributes.split(','),
52
- typesToExclude: exclude.split(','),
53
- assemblyNames: [asm],
54
- prefixSize,
55
- });
56
- const trixConf = {
57
- type: 'TrixTextSearchAdapter',
58
- textSearchAdapterId: id,
59
- ixFilePath: {
60
- uri: `trix/${asm}.ix`,
61
- locationType: 'UriLocation',
62
- },
63
- ixxFilePath: {
64
- uri: `trix/${asm}.ixx`,
65
- locationType: 'UriLocation',
66
- },
67
- metaFilePath: {
68
- uri: `trix/${asm}_meta.json`,
69
- locationType: 'UriLocation',
70
- },
71
- assemblyNames: [asm],
72
- };
73
- if (idx === -1) {
74
- aggregateTextSearchAdapters.push(trixConf);
75
- }
76
- else {
77
- aggregateTextSearchAdapters[idx] = trixConf;
78
- }
79
- }
80
- }
81
- if (!dryrun) {
82
- (0, config_utils_1.writeConf)({
83
- ...config,
84
- aggregateTextSearchAdapters,
85
- }, confPath);
86
- }
87
- }
@@ -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.readConf = readConf;
7
- exports.writeConf = writeConf;
8
- exports.getConfigPath = getConfigPath;
9
- exports.ensureTrixDir = ensureTrixDir;
10
- exports.getAssemblyNames = getAssemblyNames;
11
- exports.getTrackConfigs = getTrackConfigs;
12
- const fs_1 = __importDefault(require("fs"));
13
- const path_1 = __importDefault(require("path"));
14
- const common_1 = require("../../types/common");
15
- function readConf(configPath) {
16
- return JSON.parse(fs_1.default.readFileSync(configPath, 'utf8'));
17
- }
18
- function writeConf(obj, configPath) {
19
- fs_1.default.writeFileSync(configPath, JSON.stringify(obj, null, 2));
20
- }
21
- function getConfigPath(outFlag) {
22
- const isDir = fs_1.default.lstatSync(outFlag).isDirectory();
23
- const configPath = isDir ? path_1.default.join(outFlag, 'config.json') : outFlag;
24
- const outLocation = path_1.default.dirname(configPath);
25
- return { configPath, outLocation };
26
- }
27
- function ensureTrixDir(outLocation) {
28
- const trixDir = path_1.default.join(outLocation, 'trix');
29
- if (!fs_1.default.existsSync(trixDir)) {
30
- fs_1.default.mkdirSync(trixDir);
31
- }
32
- return trixDir;
33
- }
34
- function getAssemblyNames(config, assemblies) {
35
- const asms = assemblies?.split(',') ||
36
- config.assemblies?.map(a => a.name) ||
37
- (config.assembly ? [config.assembly.name] : []);
38
- if (!asms.length) {
39
- throw new Error('No assemblies found');
40
- }
41
- return asms;
42
- }
43
- function getTrackConfigs(configPath, trackIds, assemblyName) {
44
- const { tracks } = readConf(configPath);
45
- if (!tracks) {
46
- return [];
47
- }
48
- const trackIdsToIndex = trackIds || tracks.map(track => track.trackId);
49
- return trackIdsToIndex
50
- .map(trackId => {
51
- const currentTrack = tracks.find(t => trackId === t.trackId);
52
- if (!currentTrack) {
53
- throw new Error(`Track not found in config.json for trackId ${trackId}, please add track configuration before indexing.`);
54
- }
55
- return currentTrack;
56
- })
57
- .filter(track => (0, common_1.supported)(track.adapter?.type))
58
- .filter(track => assemblyName ? track.assemblyNames.includes(assemblyName) : true);
59
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.indexFileList = exports.perTrackIndex = exports.aggregateIndex = void 0;
4
- var aggregate_1 = require("./aggregate");
5
- Object.defineProperty(exports, "aggregateIndex", { enumerable: true, get: function () { return aggregate_1.aggregateIndex; } });
6
- var per_track_1 = require("./per-track");
7
- Object.defineProperty(exports, "perTrackIndex", { enumerable: true, get: function () { return per_track_1.perTrackIndex; } });
8
- var file_list_1 = require("./file-list");
9
- Object.defineProperty(exports, "indexFileList", { enumerable: true, get: function () { return file_list_1.indexFileList; } });
@@ -1,65 +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.perTrackIndex = perTrackIndex;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const adapter_utils_1 = require("./adapter-utils");
10
- const config_utils_1 = require("./config-utils");
11
- const indexing_utils_1 = require("./indexing-utils");
12
- const validators_1 = require("./validators");
13
- async function perTrackIndex(flags) {
14
- const { out, target, tracks, assemblies, attributes, quiet, force, exclude, prefixSize, } = flags;
15
- const outFlag = target || out || '.';
16
- const isDir = fs_1.default.lstatSync(outFlag).isDirectory();
17
- const confFilePath = isDir ? path_1.default.join(outFlag, 'config.json') : outFlag;
18
- const outLocation = path_1.default.dirname(confFilePath);
19
- const config = (0, config_utils_1.readConf)(confFilePath);
20
- const configTracks = config.tracks || [];
21
- const trixDir = path_1.default.join(outLocation, 'trix');
22
- if (!fs_1.default.existsSync(trixDir)) {
23
- fs_1.default.mkdirSync(trixDir);
24
- }
25
- (0, validators_1.validateAssembliesForPerTrack)(assemblies);
26
- const confs = (0, config_utils_1.getTrackConfigs)(confFilePath, tracks?.split(','));
27
- if (!confs.length) {
28
- throw new Error('Tracks not found in config.json, please add track configurations before indexing.');
29
- }
30
- for (const trackConfig of confs) {
31
- const { textSearching, trackId, assemblyNames } = trackConfig;
32
- if (textSearching?.textSearchAdapter && !force) {
33
- console.log(`Note: ${trackId} has already been indexed with this configuration, use --force to overwrite this track. Skipping for now`);
34
- continue;
35
- }
36
- console.log(`Indexing track ${trackId}...`);
37
- await (0, indexing_utils_1.indexDriver)({
38
- trackConfigs: [trackConfig],
39
- attributes: attributes.split(','),
40
- outLocation,
41
- quiet,
42
- name: trackId,
43
- typesToExclude: exclude.split(','),
44
- assemblyNames,
45
- prefixSize,
46
- });
47
- if (!textSearching?.textSearchAdapter) {
48
- // modifies track with new text search adapter
49
- const index = configTracks.findIndex(track => trackId === track.trackId);
50
- if (index !== -1) {
51
- configTracks[index] = {
52
- ...trackConfig,
53
- textSearching: {
54
- ...textSearching,
55
- textSearchAdapter: (0, adapter_utils_1.createPerTrackTrixAdapter)(trackId, assemblyNames),
56
- },
57
- };
58
- }
59
- else {
60
- console.log("Error: can't find trackId");
61
- }
62
- }
63
- (0, config_utils_1.writeConf)({ ...config, tracks: configTracks }, confFilePath);
64
- }
65
- }