@jbrowse/cli 4.3.0 → 5.0.0-beta.10

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 (71) hide show
  1. package/README.md +451 -72
  2. package/dist/base.js +0 -3
  3. package/dist/bin.js +2 -1
  4. package/dist/cliFetch.js +3 -0
  5. package/dist/commands/add-assembly/index.js +46 -19
  6. package/dist/commands/add-assembly/utils.js +204 -290
  7. package/dist/commands/add-connection.js +73 -79
  8. package/dist/commands/add-track-json.js +24 -12
  9. package/dist/commands/add-track-utils/adapter-utils.js +189 -288
  10. package/dist/commands/add-track-utils/file-operations.js +27 -11
  11. package/dist/commands/add-track-utils/multiwig.js +47 -0
  12. package/dist/commands/add-track-utils/track-config.js +66 -25
  13. package/dist/commands/add-track-utils/validators.js +36 -20
  14. package/dist/commands/add-track.js +200 -62
  15. package/dist/commands/admin-server/index.js +39 -50
  16. package/dist/commands/admin-server/utils.js +238 -126
  17. package/dist/commands/create.js +18 -34
  18. package/dist/commands/make-density/density-generator.js +180 -0
  19. package/dist/commands/make-density/index.js +139 -0
  20. package/dist/commands/make-pif/index.js +133 -11
  21. package/dist/commands/make-pif/pif-generator.js +243 -43
  22. package/dist/commands/process-utils.js +13 -2
  23. package/dist/commands/remove-track.js +20 -13
  24. package/dist/commands/set-default-session.js +35 -31
  25. package/dist/commands/shared/config-operations.js +3 -10
  26. package/dist/commands/shared/density.js +12 -0
  27. package/dist/commands/shared/sort-utils.js +67 -10
  28. package/dist/commands/shared/validators.js +38 -3
  29. package/dist/commands/sort-bed.js +2 -33
  30. package/dist/commands/sort-gff.js +2 -33
  31. package/dist/commands/text-index/adapter-utils.js +19 -26
  32. package/dist/commands/text-index/aggregate.js +40 -34
  33. package/dist/commands/text-index/command.js +37 -7
  34. package/dist/commands/text-index/config-utils.js +62 -85
  35. package/dist/commands/text-index/file-list.js +32 -18
  36. package/dist/commands/text-index/index.js +4 -4
  37. package/dist/commands/text-index/indexing-utils.js +44 -96
  38. package/dist/commands/text-index/per-track.js +44 -31
  39. package/dist/commands/text-index/validators.js +1 -1
  40. package/dist/commands/upgrade.js +20 -32
  41. package/dist/commands/validate/configManifest.generated.js +7613 -0
  42. package/dist/commands/validate/configSchema.generated.js +20400 -0
  43. package/dist/commands/validate/displayDefaultKeys.js +28 -0
  44. package/dist/commands/validate/index.js +113 -0
  45. package/dist/commands/validate/liftConfig.js +34 -0
  46. package/dist/commands/validate/markRules/aggregateFieldName.js +9 -0
  47. package/dist/commands/validate/markRules/autoBin.js +27 -0
  48. package/dist/commands/validate/markRules/colorScale.js +244 -0
  49. package/dist/commands/validate/markRules/cssColorsLevel4.js +162 -0
  50. package/dist/commands/validate/markRules/jexlStrings.js +23 -0
  51. package/dist/commands/validate/markRules/markProblems.js +532 -0
  52. package/dist/commands/validate/markRules/markRuleFacts.js +6 -0
  53. package/dist/commands/validate/markRules/markSpecs.js +96 -0
  54. package/dist/commands/validate/markRules/markVocabulary.js +57 -0
  55. package/dist/commands/validate/markRules/shapeNameList.js +7 -0
  56. package/dist/commands/validate/markRules/stepChannels.js +55 -0
  57. package/dist/commands/validate/schemaValidate.js +425 -0
  58. package/dist/commands/validate/suggest.js +35 -0
  59. package/dist/commands/validate/types.js +6 -0
  60. package/dist/commands/validate/validateConfig.js +502 -0
  61. package/dist/index.js +104 -50
  62. package/dist/types/common.js +3 -27
  63. package/dist/utils.js +309 -128
  64. package/dist/version.js +1 -1
  65. package/package.json +8 -14
  66. package/bin/run +0 -4
  67. package/bundle/index.js +0 -3686
  68. package/dist/commands/make-pif/cigar-utils.js +0 -24
  69. package/dist/commands/make-pif/file-utils.js +0 -30
  70. package/dist/commands/track-utils.js +0 -74
  71. package/dist/util.js +0 -35
package/dist/index.js CHANGED
@@ -1,35 +1,90 @@
1
1
  #!/usr/bin/env node
2
- import { parseArgs } from 'util';
3
- // Command imports
4
- import { run as addAssemblyRun } from "./commands/add-assembly/index.js";
5
- import { run as addConnectionRun } from "./commands/add-connection.js";
6
- import { run as addTrackJsonRun } from "./commands/add-track-json.js";
7
- import { run as addTrackRun } from "./commands/add-track.js";
8
- import { run as adminServerRun } from "./commands/admin-server/index.js";
9
- import { run as createRun } from "./commands/create.js";
10
- import { run as makePIFRun } from "./commands/make-pif/index.js";
11
- import { run as removeTrackRun } from "./commands/remove-track.js";
12
- import { run as setDefaultSessionRun } from "./commands/set-default-session.js";
13
- import { run as sortBedRun } from "./commands/sort-bed.js";
14
- import { run as sortGffRun } from "./commands/sort-gff.js";
15
- import { run as textIndexRun } from "./commands/text-index/index.js";
16
- import { run as upgradeRun } from "./commands/upgrade.js";
17
- import { version } from "./version.js";
18
- const commands = {
19
- create: createRun,
20
- 'add-assembly': addAssemblyRun,
21
- 'add-track': addTrackRun,
22
- 'text-index': textIndexRun,
23
- 'admin-server': adminServerRun,
24
- upgrade: upgradeRun,
25
- 'make-pif': makePIFRun,
26
- 'sort-gff': sortGffRun,
27
- 'sort-bed': sortBedRun,
28
- 'add-connection': addConnectionRun,
29
- 'add-track-json': addTrackJsonRun,
30
- 'remove-track': removeTrackRun,
31
- 'set-default-session': setDefaultSessionRun,
32
- };
2
+ import { parseArgs } from 'node:util';
3
+ import { version } from './version.js';
4
+ // single source of truth for both dispatch and the global help listing, so a
5
+ // new command can never be wired into one but forgotten in the other.
6
+ //
7
+ // Each command is LOADED WHEN IT IS DISPATCHED, not imported here: a static
8
+ // import list makes every invocation pay for every command's module graph, and
9
+ // text-index's parsers alone are most of it. `jbrowse add-track` went from
10
+ // 0.35s to 0.21s of startup, which is the whole of what that command does.
11
+ const registry = [
12
+ {
13
+ name: 'create',
14
+ summary: 'Downloads and installs the latest JBrowse 2 release',
15
+ load: () => import('./commands/create.js').then(m => m.run),
16
+ },
17
+ {
18
+ name: 'add-assembly',
19
+ summary: 'Add an assembly to a JBrowse 2 configuration',
20
+ load: () => import('./commands/add-assembly/index.js').then(m => m.run),
21
+ },
22
+ {
23
+ name: 'add-track',
24
+ summary: 'Add a track to a JBrowse 2 configuration',
25
+ load: () => import('./commands/add-track.js').then(m => m.run),
26
+ },
27
+ {
28
+ name: 'validate',
29
+ summary: 'Check a configuration for errors, including ones JBrowse accepts silently',
30
+ load: () => import('./commands/validate/index.js').then(m => m.run),
31
+ },
32
+ {
33
+ name: 'text-index',
34
+ summary: 'Make a text-indexing file for any given track(s)',
35
+ load: () => import('./commands/text-index/index.js').then(m => m.run),
36
+ },
37
+ {
38
+ name: 'admin-server',
39
+ summary: 'Start up a small admin server for JBrowse configuration',
40
+ load: () => import('./commands/admin-server/index.js').then(m => m.run),
41
+ },
42
+ {
43
+ name: 'upgrade',
44
+ summary: 'Upgrades JBrowse 2 to latest version',
45
+ load: () => import('./commands/upgrade.js').then(m => m.run),
46
+ },
47
+ {
48
+ name: 'make-pif',
49
+ summary: 'Creates pairwise indexed PAF (PIF), with bgzip and tabix',
50
+ load: () => import('./commands/make-pif/index.js').then(m => m.run),
51
+ },
52
+ {
53
+ name: 'make-density',
54
+ summary: 'Counts feature starts per bin into a bigWig density sidecar, with bedGraphToBigWig',
55
+ load: () => import('./commands/make-density/index.js').then(m => m.run),
56
+ },
57
+ {
58
+ name: 'sort-gff',
59
+ summary: 'Sort a GFF/GTF for tabix: sort -k1,1 -k4,4n, header kept on top',
60
+ load: () => import('./commands/sort-gff.js').then(m => m.run),
61
+ },
62
+ {
63
+ name: 'sort-bed',
64
+ summary: 'Sort a BED for tabix: sort -k1,1 -k2,2n, header kept on top',
65
+ load: () => import('./commands/sort-bed.js').then(m => m.run),
66
+ },
67
+ {
68
+ name: 'add-connection',
69
+ summary: 'Add a connection to a JBrowse 2 configuration',
70
+ load: () => import('./commands/add-connection.js').then(m => m.run),
71
+ },
72
+ {
73
+ name: 'add-track-json',
74
+ summary: 'Add a track configuration directly from a JSON hunk',
75
+ load: () => import('./commands/add-track-json.js').then(m => m.run),
76
+ },
77
+ {
78
+ name: 'remove-track',
79
+ summary: 'Remove a track configuration from a JBrowse 2 configuration',
80
+ load: () => import('./commands/remove-track.js').then(m => m.run),
81
+ },
82
+ {
83
+ name: 'set-default-session',
84
+ summary: 'Set a default session with views and tracks',
85
+ load: () => import('./commands/set-default-session.js').then(m => m.run),
86
+ },
87
+ ];
33
88
  export async function main(args) {
34
89
  try {
35
90
  const { values: flags, positionals } = parseArgs({
@@ -64,16 +119,23 @@ export async function main(args) {
64
119
  showGlobalHelp();
65
120
  process.exit(1);
66
121
  }
67
- const command = commands[commandName];
68
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
122
+ const command = registry.find(c => c.name === commandName);
69
123
  if (!command) {
70
124
  console.error(`Error: Unknown command "${commandName}"`);
71
- console.error(`Available commands: ${Object.keys(commands).join(', ')}`);
125
+ console.error(`Available commands: ${registry.map(c => c.name).join(', ')}`);
72
126
  process.exit(1);
73
127
  }
74
- // Pass the remaining arguments to the command
75
- const commandArgs = args.slice(1); // Remove the command name from args
76
- await command(commandArgs);
128
+ // Pass everything after the command token to the command. Slicing from the
129
+ // command's actual position (rather than a hardcoded index 0) keeps this
130
+ // correct when a global flag precedes the command, e.g. `jbrowse -v create`
131
+ const commandArgs = args.slice(args.indexOf(commandName) + 1);
132
+ // ...but that slice drops a help flag written before the command, so
133
+ // `jbrowse --help create` used to run create with no args and fail on the
134
+ // missing positional instead of printing its help
135
+ if (flags.help && !commandArgs.some(a => a === '--help' || a === '-h')) {
136
+ commandArgs.push('--help');
137
+ }
138
+ await (await command.load())(commandArgs);
77
139
  }
78
140
  catch (error) {
79
141
  const message = error instanceof Error ? error.message : String(error);
@@ -93,6 +155,10 @@ Try setting a custom TMPDIR with more available space:
93
155
  }
94
156
  }
95
157
  function showGlobalHelp() {
158
+ const width = Math.max(...registry.map(c => c.name.length)) + 2;
159
+ const commandLines = registry
160
+ .map(c => ` ${c.name.padEnd(width)}${c.summary}`)
161
+ .join('\n');
96
162
  console.log(`
97
163
  JBrowse CLI
98
164
 
@@ -100,19 +166,7 @@ USAGE
100
166
  $ jbrowse <command> [options]
101
167
 
102
168
  COMMANDS
103
- create Downloads and installs the latest JBrowse 2 release
104
- add-assembly Add an assembly to a JBrowse 2 configuration
105
- add-track Add a track to a JBrowse 2 configuration
106
- text-index Make a text-indexing file for any given track(s)
107
- admin-server Start up a small admin server for JBrowse configuration
108
- upgrade Upgrades JBrowse 2 to latest version
109
- make-pif Creates pairwise indexed PAF (PIF), with bgzip and tabix
110
- sort-gff Helper utility to sort GFF files for tabix
111
- sort-bed Helper utility to sort BED files for tabix
112
- add-connection Add a connection to a JBrowse 2 configuration
113
- add-track-json Add a track configuration directly from a JSON hunk
114
- remove-track Remove a track configuration from a JBrowse 2 configuration
115
- set-default-session Set a default session with views and tracks
169
+ ${commandLines}
116
170
 
117
171
  OPTIONS
118
172
  -h, --help Show help
@@ -1,27 +1,3 @@
1
- import fetch from "../cliFetch.js";
2
- export async function createRemoteStream(urlIn) {
3
- const res = await fetch(urlIn);
4
- if (!res.ok) {
5
- throw new Error(`Failed to fetch ${urlIn} status ${res.status} ${await res.text()}`);
6
- }
7
- return res;
8
- }
9
- export function isURL(FileName) {
10
- let url;
11
- try {
12
- url = new URL(FileName);
13
- }
14
- catch (_) {
15
- return false;
16
- }
17
- return url.protocol === 'http:' || url.protocol === 'https:';
18
- }
19
- const SUPPORTED_ADAPTERS = new Set([
20
- 'Gff3TabixAdapter',
21
- 'VcfTabixAdapter',
22
- 'Gff3Adapter',
23
- 'VcfAdapter',
24
- ]);
25
- export function supported(type = '') {
26
- return SUPPORTED_ADAPTERS.has(type);
27
- }
1
+ // the indexer package owns both of these: which adapter types text-index can
2
+ // handle, and the URL test its stream opener uses to pick fetch vs fs
3
+ export { isURL, isSupportedIndexingAdapter as supported, } from '@jbrowse/text-indexing-core';