@jbrowse/plugin-config 4.3.0 → 5.0.0-beta.2

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 (72) hide show
  1. package/esm/ConfigurationEditorWidget/components/AddNewField.d.ts +4 -0
  2. package/esm/ConfigurationEditorWidget/components/AddNewField.js +28 -0
  3. package/esm/ConfigurationEditorWidget/components/BooleanEditor.d.ts +4 -2
  4. package/esm/ConfigurationEditorWidget/components/BooleanEditor.js +19 -4
  5. package/esm/ConfigurationEditorWidget/components/CallbackEditor.d.ts +4 -2
  6. package/esm/ConfigurationEditorWidget/components/CallbackEditor.js +24 -42
  7. package/esm/ConfigurationEditorWidget/components/ColorEditor.d.ts +3 -11
  8. package/esm/ConfigurationEditorWidget/components/ColorEditor.js +28 -20
  9. package/esm/ConfigurationEditorWidget/components/ConfigurationEditor.d.ts +2 -3
  10. package/esm/ConfigurationEditorWidget/components/ConfigurationEditor.js +108 -17
  11. package/esm/ConfigurationEditorWidget/components/ConfigurationTextField.d.ts +1 -1
  12. package/esm/ConfigurationEditorWidget/components/ConfigurationTextField.js +10 -2
  13. package/esm/ConfigurationEditorWidget/components/HeadingComponent.d.ts +1 -1
  14. package/esm/ConfigurationEditorWidget/components/IntegerEditor.d.ts +10 -0
  15. package/esm/ConfigurationEditorWidget/components/IntegerEditor.js +9 -0
  16. package/esm/ConfigurationEditorWidget/components/JsonEditor.d.ts +3 -1
  17. package/esm/ConfigurationEditorWidget/components/JsonEditor.js +27 -40
  18. package/esm/ConfigurationEditorWidget/components/MapEntryCard.d.ts +8 -0
  19. package/esm/ConfigurationEditorWidget/components/MapEntryCard.js +23 -0
  20. package/esm/ConfigurationEditorWidget/components/MapSlotEditor.d.ts +8 -0
  21. package/esm/ConfigurationEditorWidget/components/MapSlotEditor.js +18 -0
  22. package/esm/ConfigurationEditorWidget/components/NumberEditor.d.ts +6 -4
  23. package/esm/ConfigurationEditorWidget/components/NumberEditor.js +24 -15
  24. package/esm/ConfigurationEditorWidget/components/NumberMapEditor.d.ts +4 -4
  25. package/esm/ConfigurationEditorWidget/components/NumberMapEditor.js +7 -31
  26. package/esm/ConfigurationEditorWidget/components/SlotEditor.d.ts +4 -5
  27. package/esm/ConfigurationEditorWidget/components/SlotEditor.js +83 -48
  28. package/esm/ConfigurationEditorWidget/components/StringArrayEditor.d.ts +3 -4
  29. package/esm/ConfigurationEditorWidget/components/StringArrayEditor.js +11 -24
  30. package/esm/ConfigurationEditorWidget/components/StringArrayMapEditor.d.ts +3 -6
  31. package/esm/ConfigurationEditorWidget/components/StringArrayMapEditor.js +14 -39
  32. package/esm/ConfigurationEditorWidget/components/TypeSelector.d.ts +1 -1
  33. package/esm/ConfigurationEditorWidget/components/TypeSelector.js +2 -2
  34. package/esm/ConfigurationEditorWidget/components/singularSlotName.d.ts +13 -0
  35. package/esm/ConfigurationEditorWidget/components/singularSlotName.js +23 -0
  36. package/esm/ConfigurationEditorWidget/components/useSlotEditorStyles.d.ts +2 -2
  37. package/esm/ConfigurationEditorWidget/components/useSlotEditorStyles.js +6 -1
  38. package/esm/ConfigurationEditorWidget/index.js +3 -3
  39. package/esm/ConfigurationEditorWidget/model.d.ts +8 -1
  40. package/esm/ConfigurationEditorWidget/model.js +40 -1
  41. package/esm/FromConfigAdapter/FromConfigAdapter.d.ts +6 -1
  42. package/esm/FromConfigAdapter/FromConfigAdapter.js +31 -1
  43. package/esm/FromConfigAdapter/configSchema.d.ts +36 -3
  44. package/esm/FromConfigAdapter/configSchema.js +34 -2
  45. package/esm/FromConfigAdapter/index.js +2 -2
  46. package/esm/FromConfigRegionsAdapter/FromConfigRegionsAdapter.d.ts +8 -0
  47. package/esm/FromConfigRegionsAdapter/FromConfigRegionsAdapter.js +10 -25
  48. package/esm/FromConfigRegionsAdapter/configSchema.d.ts +42 -3
  49. package/esm/FromConfigRegionsAdapter/configSchema.js +39 -2
  50. package/esm/FromConfigRegionsAdapter/index.js +2 -2
  51. package/esm/FromConfigSequenceAdapter/FromConfigSequenceAdapter.d.ts +15 -2
  52. package/esm/FromConfigSequenceAdapter/FromConfigSequenceAdapter.js +32 -40
  53. package/esm/FromConfigSequenceAdapter/configSchema.d.ts +41 -3
  54. package/esm/FromConfigSequenceAdapter/configSchema.js +38 -2
  55. package/esm/FromConfigSequenceAdapter/index.js +2 -2
  56. package/esm/NcbiSequenceReportAliasAdapter/NcbiSequenceReportAliasAdapter.d.ts +5 -4
  57. package/esm/NcbiSequenceReportAliasAdapter/NcbiSequenceReportAliasAdapter.js +28 -24
  58. package/esm/NcbiSequenceReportAliasAdapter/configSchema.d.ts +77 -9
  59. package/esm/NcbiSequenceReportAliasAdapter/configSchema.js +79 -12
  60. package/esm/NcbiSequenceReportAliasAdapter/index.js +3 -2
  61. package/esm/RefNameAliasAdapter/RefNameAliasAdapter.d.ts +4 -3
  62. package/esm/RefNameAliasAdapter/RefNameAliasAdapter.js +22 -28
  63. package/esm/RefNameAliasAdapter/configSchema.d.ts +87 -12
  64. package/esm/RefNameAliasAdapter/configSchema.js +86 -12
  65. package/esm/RefNameAliasAdapter/index.js +3 -2
  66. package/esm/aliasUtils.d.ts +4 -0
  67. package/esm/aliasUtils.js +26 -0
  68. package/esm/index.d.ts +2 -2
  69. package/esm/index.js +7 -7
  70. package/esm/normalizeUriSnapshot.d.ts +1 -0
  71. package/esm/normalizeUriSnapshot.js +13 -0
  72. package/package.json +11 -15
@@ -1,12 +1,48 @@
1
1
  import { ConfigurationSchema } from '@jbrowse/core/configuration';
2
- function x() { }
2
+ /**
3
+ * #config FromConfigSequenceAdapter
4
+ * #trackType ReferenceSequenceTrack
5
+ * #fileFormat inline | Inline sequence | Each feature's `seq` holds the bases for its region
6
+ * supplies reference sequence inline in the config; each feature's `seq` holds
7
+ * the bases for its region
8
+ *
9
+ * #example
10
+ * Used as the adapter of an assembly's `sequence` (a `ReferenceSequenceTrack`):
11
+ * ```js
12
+ * {
13
+ * type: 'ReferenceSequenceTrack',
14
+ * trackId: 'my_refseq',
15
+ * adapter: {
16
+ * type: 'FromConfigSequenceAdapter',
17
+ * features: [
18
+ * { uniqueId: 'ctgA', refName: 'ctgA', start: 0, end: 10, seq: 'ATGCATGCAT' },
19
+ * ],
20
+ * },
21
+ * }
22
+ * ```
23
+ */
3
24
  const sequenceConfigSchema = ConfigurationSchema('FromConfigSequenceAdapter', {
25
+ /**
26
+ * #slot
27
+ * stable identifier used as the adapter cache key; avoids hashing the
28
+ * (potentially large) features array. optional — falls back to hash.
29
+ */
30
+ adapterId: {
31
+ type: 'string',
32
+ defaultValue: '',
33
+ },
34
+ /**
35
+ * #slot
36
+ * one entry per reference sequence, each with a `uniqueId`, `refName`,
37
+ * `start`, `end`, and a `seq` string holding the bases for that span. The
38
+ * bases live in the config, so this is for small sequences — a plasmid, a
39
+ * test contig — not a genome.
40
+ */
4
41
  features: {
5
42
  type: 'frozen',
6
43
  defaultValue: [],
7
44
  },
8
45
  }, {
9
46
  explicitlyTyped: true,
10
- implicitIdentifier: 'adapterId',
11
47
  });
12
48
  export default sequenceConfigSchema;
@@ -1,10 +1,10 @@
1
1
  import { AdapterType } from '@jbrowse/core/pluggableElementTypes';
2
- import configSchema from "./configSchema.js";
2
+ import configSchema from './configSchema.js';
3
3
  export default function FromConfigSequenceAdapterF(pluginManager) {
4
4
  pluginManager.addAdapterType(() => new AdapterType({
5
5
  name: 'FromConfigSequenceAdapter',
6
6
  configSchema,
7
- getAdapterClass: () => import("./FromConfigSequenceAdapter.js").then(r => r.default),
7
+ getAdapterClass: () => import('./FromConfigSequenceAdapter.js').then(r => r.default),
8
8
  adapterMetadata: {
9
9
  hiddenFromGUI: true,
10
10
  },
@@ -1,9 +1,10 @@
1
1
  import { BaseAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
2
- import type { BaseRefNameAliasAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
3
- export default class NcbiSequenceReportAliasAdapter extends BaseAdapter implements BaseRefNameAliasAdapter {
4
- getRefNameAliases(): Promise<{
2
+ import type { NcbiSequenceReportAliasAdapterConfig } from './configSchema.ts';
3
+ import type { BaseOptions, BaseRefNameAliasAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
4
+ export default class NcbiSequenceReportAliasAdapter extends BaseAdapter<NcbiSequenceReportAliasAdapterConfig> implements BaseRefNameAliasAdapter {
5
+ getRefNameAliases(opts?: BaseOptions): Promise<{
5
6
  refName: string;
6
7
  aliases: string[];
7
- override: any;
8
+ override: boolean;
8
9
  }[]>;
9
10
  }
@@ -1,38 +1,42 @@
1
1
  import { BaseAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
2
- import { openLocation } from '@jbrowse/core/util/io';
2
+ import { readAliasRows } from '../aliasUtils.js';
3
+ // locate a column by its header name, throwing a column-specific error if a
4
+ // required one is absent
5
+ function requireColumn(header, name) {
6
+ const idx = header.indexOf(name);
7
+ if (idx === -1) {
8
+ throw new Error(`sequence_report.tsv header is missing required column "${name}"`);
9
+ }
10
+ return idx;
11
+ }
3
12
  export default class NcbiSequenceReportAliasAdapter extends BaseAdapter {
4
- async getRefNameAliases() {
5
- const loc = this.getConf('location');
6
- if (loc.uri === '' || loc.uri === '/path/to/my/sequence_report.tsv') {
13
+ async getRefNameAliases(opts) {
14
+ const rows = await readAliasRows(this.getConf('location'), this.pluginManager, opts);
15
+ if (rows.length === 0) {
7
16
  return [];
8
17
  }
9
18
  const override = this.getConf('useNameOverride');
10
- const results = await openLocation(loc, this.pluginManager).readFile('utf8');
11
- const lines = results
12
- .split(/\n|\r\n|\r/)
13
- .filter(f => !!f.trim())
14
- .map(row => row.split('\t'));
15
- const r = lines[0] || [];
16
- const genBankIdx = r.indexOf('GenBank seq accession');
17
- const refSeqIdx = r.indexOf('RefSeq seq accession');
18
- const ucscIdx = r.indexOf('UCSC style name');
19
- const seqNameIdx = r.indexOf('Sequence name');
20
- if (genBankIdx === -1 || refSeqIdx === -1 || ucscIdx === -1) {
21
- throw new Error('Header line must include "GenBank seq accession", "RefSeq seq accession", "UCSC style name", and "Sequence name"');
22
- }
23
- return lines
24
- .slice(1)
25
- .filter(cols => !!cols[ucscIdx] || !!cols[seqNameIdx])
19
+ const header = rows[0];
20
+ const dataRows = rows.slice(1);
21
+ const genBankIdx = requireColumn(header, 'GenBank seq accession');
22
+ const refSeqIdx = requireColumn(header, 'RefSeq seq accession');
23
+ const ucscIdx = requireColumn(header, 'UCSC style name');
24
+ // Sequence name is optional; -1 means absent
25
+ const seqNameIdx = header.indexOf('Sequence name');
26
+ const seqName = (cols) => seqNameIdx === -1 ? undefined : cols[seqNameIdx];
27
+ // refName comes from the UCSC name, falling back to the Sequence name; the
28
+ // filter guarantees one is present, so every mapped row has a truthy refName
29
+ return dataRows
30
+ .filter(cols => !!cols[ucscIdx] || !!seqName(cols))
26
31
  .map(cols => ({
27
- refName: (cols[ucscIdx] || cols[seqNameIdx]),
32
+ refName: (cols[ucscIdx] || seqName(cols)),
28
33
  aliases: [
29
34
  cols[genBankIdx],
30
35
  cols[refSeqIdx],
31
36
  cols[ucscIdx],
32
- cols[seqNameIdx],
37
+ seqName(cols),
33
38
  ].filter((f) => !!f),
34
39
  override,
35
- }))
36
- .filter(f => !!f.refName);
40
+ }));
37
41
  }
38
42
  }
@@ -1,15 +1,83 @@
1
+ import { normalizeUriSnapshot } from '../normalizeUriSnapshot.ts';
2
+ import type { Instance } from '@jbrowse/mobx-state-tree';
3
+ export declare const normalizeSnapshot: typeof normalizeUriSnapshot;
4
+ /**
5
+ * #config NcbiSequenceReportAliasAdapter
6
+ * can read "sequence_report.tsv" type files from NCBI
7
+ *
8
+ * #example
9
+ * Goes on an ASSEMBLY, under `refNameAliases` — not on a track. The file ships
10
+ * beside any RefSeq assembly on NCBI datasets and aliases the RefSeq, GenBank
11
+ * and UCSC-style names of every sequence at once, so it replaces a
12
+ * hand-maintained chromAlias table:
13
+ * ```js
14
+ * {
15
+ * name: 'GCF_000001405.40',
16
+ * sequence: {
17
+ * type: 'ReferenceSequenceTrack',
18
+ * trackId: 'GCF_000001405.40-ReferenceSequenceTrack',
19
+ * adapter: {
20
+ * type: 'BgzipFastaAdapter',
21
+ * uri: 'https://example.com/GCF_000001405.40.fa.gz',
22
+ * },
23
+ * },
24
+ * refNameAliases: {
25
+ * adapter: {
26
+ * type: 'NcbiSequenceReportAliasAdapter',
27
+ * uri: 'https://example.com/GCF_000001405.40_sequence_report.tsv',
28
+ * },
29
+ * },
30
+ * }
31
+ * ```
32
+ *
33
+ * #example keeping the FASTA's own names
34
+ * With an NCBI FASTA (`NC_000001.11`), the default displays UCSC-style names
35
+ * (`chr1`) while still fetching bases under the accession. Set
36
+ * `useNameOverride: false` to display the accessions instead, with `chr1` left
37
+ * searchable as an alias:
38
+ * ```js
39
+ * {
40
+ * name: 'GCF_000001405.40',
41
+ * sequence: {
42
+ * type: 'ReferenceSequenceTrack',
43
+ * trackId: 'GCF_000001405.40-ReferenceSequenceTrack',
44
+ * adapter: {
45
+ * type: 'BgzipFastaAdapter',
46
+ * uri: 'https://example.com/GCF_000001405.40.fa.gz',
47
+ * },
48
+ * },
49
+ * refNameAliases: {
50
+ * adapter: {
51
+ * type: 'NcbiSequenceReportAliasAdapter',
52
+ * uri: 'https://example.com/GCF_000001405.40_sequence_report.tsv',
53
+ * useNameOverride: false,
54
+ * },
55
+ * },
56
+ * }
57
+ * ```
58
+ */
1
59
  declare const NcbiSequenceReportAliasAdapterConfigSchema: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
2
- location: {
3
- type: string;
4
- defaultValue: {
5
- uri: string;
6
- locationType: string;
60
+ /**
61
+ * #slot
62
+ * location of the `sequence_report.tsv` NCBI publishes with an assembly. It
63
+ * carries the RefSeq, GenBank and UCSC-style name of every sequence, so one
64
+ * file aliases them all without hand-writing a chromAlias table.
65
+ */
66
+ readonly location: {
67
+ readonly type: "fileLocation";
68
+ readonly defaultValue: {
69
+ readonly uri: "/path/to/my/sequence_report.tsv";
70
+ readonly locationType: "UriLocation";
7
71
  };
8
72
  };
9
- useNameOverride: {
10
- type: string;
11
- defaultValue: boolean;
12
- description: string;
73
+ /**
74
+ * #slot
75
+ */
76
+ readonly useNameOverride: {
77
+ readonly type: "boolean";
78
+ readonly defaultValue: true;
79
+ readonly description: "forces usage of the UCSC names over the NCBI style names from a FASTA";
13
80
  };
14
81
  }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, undefined>>;
82
+ export type NcbiSequenceReportAliasAdapterConfig = Instance<typeof NcbiSequenceReportAliasAdapterConfigSchema>;
15
83
  export default NcbiSequenceReportAliasAdapterConfigSchema;
@@ -1,6 +1,68 @@
1
1
  import { ConfigurationSchema } from '@jbrowse/core/configuration';
2
- function x() { }
2
+ import { normalizeUriSnapshot } from '../normalizeUriSnapshot.js';
3
+ export const normalizeSnapshot = normalizeUriSnapshot;
4
+ /**
5
+ * #config NcbiSequenceReportAliasAdapter
6
+ * can read "sequence_report.tsv" type files from NCBI
7
+ *
8
+ * #example
9
+ * Goes on an ASSEMBLY, under `refNameAliases` — not on a track. The file ships
10
+ * beside any RefSeq assembly on NCBI datasets and aliases the RefSeq, GenBank
11
+ * and UCSC-style names of every sequence at once, so it replaces a
12
+ * hand-maintained chromAlias table:
13
+ * ```js
14
+ * {
15
+ * name: 'GCF_000001405.40',
16
+ * sequence: {
17
+ * type: 'ReferenceSequenceTrack',
18
+ * trackId: 'GCF_000001405.40-ReferenceSequenceTrack',
19
+ * adapter: {
20
+ * type: 'BgzipFastaAdapter',
21
+ * uri: 'https://example.com/GCF_000001405.40.fa.gz',
22
+ * },
23
+ * },
24
+ * refNameAliases: {
25
+ * adapter: {
26
+ * type: 'NcbiSequenceReportAliasAdapter',
27
+ * uri: 'https://example.com/GCF_000001405.40_sequence_report.tsv',
28
+ * },
29
+ * },
30
+ * }
31
+ * ```
32
+ *
33
+ * #example keeping the FASTA's own names
34
+ * With an NCBI FASTA (`NC_000001.11`), the default displays UCSC-style names
35
+ * (`chr1`) while still fetching bases under the accession. Set
36
+ * `useNameOverride: false` to display the accessions instead, with `chr1` left
37
+ * searchable as an alias:
38
+ * ```js
39
+ * {
40
+ * name: 'GCF_000001405.40',
41
+ * sequence: {
42
+ * type: 'ReferenceSequenceTrack',
43
+ * trackId: 'GCF_000001405.40-ReferenceSequenceTrack',
44
+ * adapter: {
45
+ * type: 'BgzipFastaAdapter',
46
+ * uri: 'https://example.com/GCF_000001405.40.fa.gz',
47
+ * },
48
+ * },
49
+ * refNameAliases: {
50
+ * adapter: {
51
+ * type: 'NcbiSequenceReportAliasAdapter',
52
+ * uri: 'https://example.com/GCF_000001405.40_sequence_report.tsv',
53
+ * useNameOverride: false,
54
+ * },
55
+ * },
56
+ * }
57
+ * ```
58
+ */
3
59
  const NcbiSequenceReportAliasAdapterConfigSchema = ConfigurationSchema('NcbiSequenceReportAliasAdapter', {
60
+ /**
61
+ * #slot
62
+ * location of the `sequence_report.tsv` NCBI publishes with an assembly. It
63
+ * carries the RefSeq, GenBank and UCSC-style name of every sequence, so one
64
+ * file aliases them all without hand-writing a chromAlias table.
65
+ */
4
66
  location: {
5
67
  type: 'fileLocation',
6
68
  defaultValue: {
@@ -8,6 +70,9 @@ const NcbiSequenceReportAliasAdapterConfigSchema = ConfigurationSchema('NcbiSequ
8
70
  locationType: 'UriLocation',
9
71
  },
10
72
  },
73
+ /**
74
+ * #slot
75
+ */
11
76
  useNameOverride: {
12
77
  type: 'boolean',
13
78
  defaultValue: true,
@@ -15,16 +80,18 @@ const NcbiSequenceReportAliasAdapterConfigSchema = ConfigurationSchema('NcbiSequ
15
80
  },
16
81
  }, {
17
82
  explicitlyTyped: true,
18
- preProcessSnapshot: snap => {
19
- return snap.uri
20
- ? {
21
- ...snap,
22
- location: {
23
- uri: snap.uri,
24
- baseUri: snap.baseUri,
25
- },
26
- }
27
- : snap;
28
- },
83
+ /**
84
+ * #preProcessSnapshot
85
+ *
86
+ *
87
+ * preprocessor to allow minimal config:
88
+ * ```json
89
+ * {
90
+ * "type": "NcbiSequenceReportAliasAdapter",
91
+ * "uri": "sequence_report.tsv"
92
+ * }
93
+ * ```
94
+ */
95
+ preProcessSnapshot: normalizeSnapshot,
29
96
  });
30
97
  export default NcbiSequenceReportAliasAdapterConfigSchema;
@@ -1,11 +1,12 @@
1
1
  import { AdapterType } from '@jbrowse/core/pluggableElementTypes';
2
- import configSchema from "./configSchema.js";
2
+ import configSchema, { normalizeSnapshot } from './configSchema.js';
3
3
  export default function NcbiSequenceReportAliasAdapterF(pluginManager) {
4
4
  pluginManager.addAdapterType(() => {
5
5
  return new AdapterType({
6
6
  name: 'NcbiSequenceReportAliasAdapter',
7
+ normalizeSnapshot,
7
8
  configSchema,
8
- getAdapterClass: () => import("./NcbiSequenceReportAliasAdapter.js").then(r => r.default),
9
+ getAdapterClass: () => import('./NcbiSequenceReportAliasAdapter.js').then(r => r.default),
9
10
  adapterMetadata: {
10
11
  hiddenFromGUI: true,
11
12
  },
@@ -1,7 +1,8 @@
1
1
  import { BaseAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
2
- import type { BaseRefNameAliasAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
3
- export default class RefNameAliasAdapter extends BaseAdapter implements BaseRefNameAliasAdapter {
4
- getRefNameAliases(): Promise<{
2
+ import type { RefNameAliasAdapterConfig } from './configSchema.ts';
3
+ import type { BaseOptions, BaseRefNameAliasAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
4
+ export default class RefNameAliasAdapter extends BaseAdapter<RefNameAliasAdapterConfig> implements BaseRefNameAliasAdapter {
5
+ getRefNameAliases(opts?: BaseOptions): Promise<{
5
6
  refName: string;
6
7
  aliases: string[];
7
8
  }[]>;
@@ -1,36 +1,30 @@
1
1
  import { BaseAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
2
- import { openLocation } from '@jbrowse/core/util/io';
2
+ import { readAliasRows } from '../aliasUtils.js';
3
+ // header lines start with '#'; the leading marker belongs to the first column
4
+ const isComment = (cols) => !!cols[0]?.startsWith('#');
5
+ // column names from a '#'-prefixed header row, with the marker stripped
6
+ const headerNames = (cols) => cols.map((col, i) => (i === 0 ? col.slice(1) : col).trim());
3
7
  export default class RefNameAliasAdapter extends BaseAdapter {
4
- async getRefNameAliases() {
5
- const loc = this.getConf('location');
6
- if (loc.uri === '' || loc.uri === '/path/to/my/aliases.txt') {
7
- return [];
8
- }
9
- const results = await openLocation(loc, this.pluginManager).readFile('utf8');
8
+ async getRefNameAliases(opts) {
9
+ const rows = await readAliasRows(this.getConf('location'), this.pluginManager, opts);
10
10
  const refColumn = this.getConf('refNameColumn');
11
11
  const refColumnHeaderName = this.getConf('refNameColumnHeaderName');
12
- const lines = results
13
- .trim()
14
- .split(/\n|\r\n|\r/)
15
- .filter(f => !!f);
16
- const header = lines.filter(f => f.startsWith('#'));
17
- const headerCol = refColumnHeaderName && header.length
18
- ? header
19
- .at(-1)
20
- .slice(1)
21
- .split('\t')
22
- .map(t => t.trim())
23
- .indexOf(refColumnHeaderName)
12
+ const lastHeader = rows.filter(isComment).at(-1);
13
+ const headerCol = refColumnHeaderName && lastHeader
14
+ ? headerNames(lastHeader).indexOf(refColumnHeaderName)
24
15
  : refColumn;
25
- return lines
26
- .filter(f => !f.startsWith('#'))
27
- .map(row => {
28
- const aliases = row.split('\t');
29
- const refName = aliases[headerCol];
30
- return {
31
- refName: refName,
32
- aliases: aliases.filter(f => !!f.trim()),
33
- };
16
+ if (headerCol === -1) {
17
+ throw new Error(`refNameColumnHeaderName "${refColumnHeaderName}" not found in alias file header`);
18
+ }
19
+ return rows
20
+ .filter(cols => !isComment(cols))
21
+ .flatMap(cols => {
22
+ // a blank refName column (short/ragged row, leading tab) would map every
23
+ // alias to an empty canonical name in buildRefNameMaps; drop such rows
24
+ const refName = cols[headerCol]?.trim();
25
+ return refName
26
+ ? [{ refName, aliases: cols.filter(f => !!f.trim()) }]
27
+ : [];
34
28
  });
35
29
  }
36
30
  }
@@ -1,19 +1,94 @@
1
+ import { normalizeUriSnapshot } from '../normalizeUriSnapshot.ts';
2
+ import type { Instance } from '@jbrowse/mobx-state-tree';
3
+ export declare const normalizeSnapshot: typeof normalizeUriSnapshot;
4
+ /**
5
+ * #config RefNameAliasAdapter
6
+ * can read "chromAliases" type files from UCSC or any tab separated file of
7
+ * refName aliases
8
+ *
9
+ * #example
10
+ * Goes on an ASSEMBLY, under `refNameAliases` — not on a track. Writing
11
+ * `refNameAliases: { uri: '...' }` is shorthand for exactly this adapter:
12
+ * ```js
13
+ * {
14
+ * name: 'hg38',
15
+ * sequence: {
16
+ * type: 'ReferenceSequenceTrack',
17
+ * trackId: 'hg38-ReferenceSequenceTrack',
18
+ * adapter: {
19
+ * type: 'BgzipFastaAdapter',
20
+ * uri: 'https://example.com/hg38.fa.gz',
21
+ * },
22
+ * },
23
+ * refNameAliases: {
24
+ * adapter: {
25
+ * type: 'RefNameAliasAdapter',
26
+ * uri: 'https://example.com/hg38.chromAlias.txt',
27
+ * },
28
+ * },
29
+ * }
30
+ * ```
31
+ *
32
+ * #example named column
33
+ * When the primary column — the one whose values match your FASTA — is not the
34
+ * first, name it. `refNameColumnHeaderName` reads the last `#`-prefixed line as
35
+ * the header; `refNameColumn` takes a zero-based index instead.
36
+ * ```js
37
+ * {
38
+ * name: 'hg38',
39
+ * sequence: {
40
+ * type: 'ReferenceSequenceTrack',
41
+ * trackId: 'hg38-ReferenceSequenceTrack',
42
+ * adapter: {
43
+ * type: 'BgzipFastaAdapter',
44
+ * uri: 'https://example.com/hg38.fa.gz',
45
+ * },
46
+ * },
47
+ * refNameAliases: {
48
+ * adapter: {
49
+ * type: 'RefNameAliasAdapter',
50
+ * uri: 'https://example.com/aliases.txt',
51
+ * refNameColumnHeaderName: 'ucsc',
52
+ * },
53
+ * },
54
+ * }
55
+ * ```
56
+ */
1
57
  declare const RefNameAliasAdapter: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
2
- location: {
3
- type: string;
4
- defaultValue: {
5
- uri: string;
6
- locationType: string;
58
+ /**
59
+ * #slot
60
+ * location of the alias table: a UCSC `chromAlias.txt`, or any
61
+ * tab-separated file whose rows each list the alternate names of one
62
+ * reference sequence (`chr1<TAB>1<TAB>NC_000001.11`). It is what lets a
63
+ * `1`-named file load against a `chr1`-named assembly.
64
+ */
65
+ readonly location: {
66
+ readonly type: "fileLocation";
67
+ readonly defaultValue: {
68
+ readonly uri: "/path/to/my/aliases.txt";
69
+ readonly locationType: "UriLocation";
7
70
  };
8
71
  };
9
- refNameColumn: {
10
- type: string;
11
- defaultValue: number;
72
+ /**
73
+ * #slot
74
+ * by default, the "ref names that match the fasta" are assumed to be in the
75
+ * first column (0), change this variable if needed
76
+ */
77
+ readonly refNameColumn: {
78
+ readonly type: "number";
79
+ readonly defaultValue: 0;
80
+ readonly advanced: true;
12
81
  };
13
- refNameColumnHeaderName: {
14
- type: string;
15
- description: string;
16
- defaultValue: string;
82
+ /**
83
+ * #slot
84
+ * refNameColumnHeaderName
85
+ */
86
+ readonly refNameColumnHeaderName: {
87
+ readonly type: "string";
88
+ readonly description: "alternative to refNameColumn, instead looks at header (starts with # and finds column name)";
89
+ readonly defaultValue: "";
90
+ readonly advanced: true;
17
91
  };
18
92
  }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, undefined>>;
93
+ export type RefNameAliasAdapterConfig = Instance<typeof RefNameAliasAdapter>;
19
94
  export default RefNameAliasAdapter;
@@ -1,6 +1,67 @@
1
1
  import { ConfigurationSchema } from '@jbrowse/core/configuration';
2
- function x() { }
2
+ import { normalizeUriSnapshot } from '../normalizeUriSnapshot.js';
3
+ export const normalizeSnapshot = normalizeUriSnapshot;
4
+ /**
5
+ * #config RefNameAliasAdapter
6
+ * can read "chromAliases" type files from UCSC or any tab separated file of
7
+ * refName aliases
8
+ *
9
+ * #example
10
+ * Goes on an ASSEMBLY, under `refNameAliases` — not on a track. Writing
11
+ * `refNameAliases: { uri: '...' }` is shorthand for exactly this adapter:
12
+ * ```js
13
+ * {
14
+ * name: 'hg38',
15
+ * sequence: {
16
+ * type: 'ReferenceSequenceTrack',
17
+ * trackId: 'hg38-ReferenceSequenceTrack',
18
+ * adapter: {
19
+ * type: 'BgzipFastaAdapter',
20
+ * uri: 'https://example.com/hg38.fa.gz',
21
+ * },
22
+ * },
23
+ * refNameAliases: {
24
+ * adapter: {
25
+ * type: 'RefNameAliasAdapter',
26
+ * uri: 'https://example.com/hg38.chromAlias.txt',
27
+ * },
28
+ * },
29
+ * }
30
+ * ```
31
+ *
32
+ * #example named column
33
+ * When the primary column — the one whose values match your FASTA — is not the
34
+ * first, name it. `refNameColumnHeaderName` reads the last `#`-prefixed line as
35
+ * the header; `refNameColumn` takes a zero-based index instead.
36
+ * ```js
37
+ * {
38
+ * name: 'hg38',
39
+ * sequence: {
40
+ * type: 'ReferenceSequenceTrack',
41
+ * trackId: 'hg38-ReferenceSequenceTrack',
42
+ * adapter: {
43
+ * type: 'BgzipFastaAdapter',
44
+ * uri: 'https://example.com/hg38.fa.gz',
45
+ * },
46
+ * },
47
+ * refNameAliases: {
48
+ * adapter: {
49
+ * type: 'RefNameAliasAdapter',
50
+ * uri: 'https://example.com/aliases.txt',
51
+ * refNameColumnHeaderName: 'ucsc',
52
+ * },
53
+ * },
54
+ * }
55
+ * ```
56
+ */
3
57
  const RefNameAliasAdapter = ConfigurationSchema('RefNameAliasAdapter', {
58
+ /**
59
+ * #slot
60
+ * location of the alias table: a UCSC `chromAlias.txt`, or any
61
+ * tab-separated file whose rows each list the alternate names of one
62
+ * reference sequence (`chr1<TAB>1<TAB>NC_000001.11`). It is what lets a
63
+ * `1`-named file load against a `chr1`-named assembly.
64
+ */
4
65
  location: {
5
66
  type: 'fileLocation',
6
67
  defaultValue: {
@@ -8,27 +69,40 @@ const RefNameAliasAdapter = ConfigurationSchema('RefNameAliasAdapter', {
8
69
  locationType: 'UriLocation',
9
70
  },
10
71
  },
72
+ /**
73
+ * #slot
74
+ * by default, the "ref names that match the fasta" are assumed to be in the
75
+ * first column (0), change this variable if needed
76
+ */
11
77
  refNameColumn: {
12
78
  type: 'number',
13
79
  defaultValue: 0,
80
+ advanced: true,
14
81
  },
82
+ /**
83
+ * #slot
84
+ * refNameColumnHeaderName
85
+ */
15
86
  refNameColumnHeaderName: {
16
87
  type: 'string',
17
88
  description: 'alternative to refNameColumn, instead looks at header (starts with # and finds column name)',
18
89
  defaultValue: '',
90
+ advanced: true,
19
91
  },
20
92
  }, {
21
93
  explicitlyTyped: true,
22
- preProcessSnapshot: snap => {
23
- return snap.uri
24
- ? {
25
- ...snap,
26
- location: {
27
- uri: snap.uri,
28
- baseUri: snap.baseUri,
29
- },
30
- }
31
- : snap;
32
- },
94
+ /**
95
+ * #preProcessSnapshot
96
+ *
97
+ *
98
+ * preprocessor to allow minimal config:
99
+ * ```json
100
+ * {
101
+ * "type": "RefNameAliasAdapter",
102
+ * "uri": "yourfile.chromAlias.txt"
103
+ * }
104
+ * ```
105
+ */
106
+ preProcessSnapshot: normalizeSnapshot,
33
107
  });
34
108
  export default RefNameAliasAdapter;