@jbrowse/plugin-data-management 2.8.0 → 2.10.0

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 (85) hide show
  1. package/dist/AddTrackWidget/components/DefaultAddTrackWorkflow.js +4 -8
  2. package/dist/AddTrackWidget/model.d.ts +81 -0
  3. package/dist/AddTrackWidget/model.js +81 -0
  4. package/dist/HierarchicalTrackSelectorWidget/components/ShoppingCart.d.ts +1 -1
  5. package/dist/HierarchicalTrackSelectorWidget/components/ShoppingCart.js +11 -53
  6. package/dist/HierarchicalTrackSelectorWidget/components/faceted/FacetFilter.d.ts +5 -7
  7. package/dist/HierarchicalTrackSelectorWidget/components/faceted/FacetFilter.js +12 -11
  8. package/dist/HierarchicalTrackSelectorWidget/components/faceted/FacetFilters.d.ts +5 -7
  9. package/dist/HierarchicalTrackSelectorWidget/components/faceted/FacetFilters.js +11 -8
  10. package/dist/HierarchicalTrackSelectorWidget/components/faceted/FacetedHeader.d.ts +1 -11
  11. package/dist/HierarchicalTrackSelectorWidget/components/faceted/FacetedHeader.js +9 -7
  12. package/dist/HierarchicalTrackSelectorWidget/components/faceted/FacetedSelector.js +40 -135
  13. package/dist/HierarchicalTrackSelectorWidget/components/tree/DropdownTrackSelector.d.ts +12 -0
  14. package/dist/HierarchicalTrackSelectorWidget/components/tree/DropdownTrackSelector.js +59 -0
  15. package/dist/HierarchicalTrackSelectorWidget/components/tree/FavoriteTracks.d.ts +6 -0
  16. package/dist/HierarchicalTrackSelectorWidget/components/tree/FavoriteTracks.js +45 -0
  17. package/dist/HierarchicalTrackSelectorWidget/components/tree/HamburgerMenu.js +71 -46
  18. package/dist/HierarchicalTrackSelectorWidget/components/tree/HierarchicalHeader.js +5 -34
  19. package/dist/HierarchicalTrackSelectorWidget/components/tree/HierarchicalTree.js +8 -3
  20. package/dist/HierarchicalTrackSelectorWidget/components/tree/RecentlyUsedTracks.d.ts +6 -0
  21. package/dist/HierarchicalTrackSelectorWidget/components/tree/RecentlyUsedTracks.js +42 -0
  22. package/dist/HierarchicalTrackSelectorWidget/components/tree/TrackCategory.js +7 -6
  23. package/dist/HierarchicalTrackSelectorWidget/components/tree/TrackLabel.js +9 -28
  24. package/dist/HierarchicalTrackSelectorWidget/components/tree/TrackLabelMenu.d.ts +12 -0
  25. package/dist/HierarchicalTrackSelectorWidget/components/tree/TrackLabelMenu.js +50 -0
  26. package/dist/HierarchicalTrackSelectorWidget/components/util.d.ts +3 -0
  27. package/dist/HierarchicalTrackSelectorWidget/components/util.js +5 -1
  28. package/dist/HierarchicalTrackSelectorWidget/facetedModel.d.ts +128 -0
  29. package/dist/HierarchicalTrackSelectorWidget/facetedModel.js +206 -0
  30. package/dist/HierarchicalTrackSelectorWidget/facetedUtil.d.ts +2 -0
  31. package/dist/HierarchicalTrackSelectorWidget/{components/faceted/util.js → facetedUtil.js} +5 -1
  32. package/dist/HierarchicalTrackSelectorWidget/generateHierarchy.d.ts +17 -5
  33. package/dist/HierarchicalTrackSelectorWidget/generateHierarchy.js +27 -21
  34. package/dist/HierarchicalTrackSelectorWidget/model.d.ts +193 -15
  35. package/dist/HierarchicalTrackSelectorWidget/model.js +209 -22
  36. package/dist/ucsc-trackhub/doConnect.d.ts +1 -0
  37. package/dist/ucsc-trackhub/doConnect.js +131 -0
  38. package/dist/ucsc-trackhub/model.d.ts +19 -2
  39. package/dist/ucsc-trackhub/model.js +16 -71
  40. package/dist/ucsc-trackhub/ucscTrackHub.d.ts +161 -4
  41. package/dist/ucsc-trackhub/ucscTrackHub.js +49 -166
  42. package/esm/AddTrackWidget/components/DefaultAddTrackWorkflow.js +4 -8
  43. package/esm/AddTrackWidget/model.d.ts +81 -0
  44. package/esm/AddTrackWidget/model.js +81 -0
  45. package/esm/HierarchicalTrackSelectorWidget/components/ShoppingCart.d.ts +1 -1
  46. package/esm/HierarchicalTrackSelectorWidget/components/ShoppingCart.js +12 -31
  47. package/esm/HierarchicalTrackSelectorWidget/components/faceted/FacetFilter.d.ts +5 -7
  48. package/esm/HierarchicalTrackSelectorWidget/components/faceted/FacetFilter.js +13 -11
  49. package/esm/HierarchicalTrackSelectorWidget/components/faceted/FacetFilters.d.ts +5 -7
  50. package/esm/HierarchicalTrackSelectorWidget/components/faceted/FacetFilters.js +12 -8
  51. package/esm/HierarchicalTrackSelectorWidget/components/faceted/FacetedHeader.d.ts +1 -11
  52. package/esm/HierarchicalTrackSelectorWidget/components/faceted/FacetedHeader.js +9 -7
  53. package/esm/HierarchicalTrackSelectorWidget/components/faceted/FacetedSelector.js +41 -113
  54. package/esm/HierarchicalTrackSelectorWidget/components/tree/DropdownTrackSelector.d.ts +12 -0
  55. package/esm/HierarchicalTrackSelectorWidget/components/tree/DropdownTrackSelector.js +31 -0
  56. package/esm/HierarchicalTrackSelectorWidget/components/tree/FavoriteTracks.d.ts +6 -0
  57. package/esm/HierarchicalTrackSelectorWidget/components/tree/FavoriteTracks.js +40 -0
  58. package/esm/HierarchicalTrackSelectorWidget/components/tree/HamburgerMenu.js +71 -46
  59. package/esm/HierarchicalTrackSelectorWidget/components/tree/HierarchicalHeader.js +6 -12
  60. package/esm/HierarchicalTrackSelectorWidget/components/tree/HierarchicalTree.js +8 -3
  61. package/esm/HierarchicalTrackSelectorWidget/components/tree/RecentlyUsedTracks.d.ts +6 -0
  62. package/esm/HierarchicalTrackSelectorWidget/components/tree/RecentlyUsedTracks.js +37 -0
  63. package/esm/HierarchicalTrackSelectorWidget/components/tree/TrackCategory.js +7 -6
  64. package/esm/HierarchicalTrackSelectorWidget/components/tree/TrackLabel.js +8 -27
  65. package/esm/HierarchicalTrackSelectorWidget/components/tree/TrackLabelMenu.d.ts +12 -0
  66. package/esm/HierarchicalTrackSelectorWidget/components/tree/TrackLabelMenu.js +45 -0
  67. package/esm/HierarchicalTrackSelectorWidget/components/util.d.ts +3 -0
  68. package/esm/HierarchicalTrackSelectorWidget/components/util.js +5 -1
  69. package/esm/HierarchicalTrackSelectorWidget/facetedModel.d.ts +128 -0
  70. package/esm/HierarchicalTrackSelectorWidget/facetedModel.js +202 -0
  71. package/esm/HierarchicalTrackSelectorWidget/facetedUtil.d.ts +2 -0
  72. package/esm/HierarchicalTrackSelectorWidget/{components/faceted/util.js → facetedUtil.js} +3 -0
  73. package/esm/HierarchicalTrackSelectorWidget/generateHierarchy.d.ts +17 -5
  74. package/esm/HierarchicalTrackSelectorWidget/generateHierarchy.js +27 -21
  75. package/esm/HierarchicalTrackSelectorWidget/model.d.ts +193 -15
  76. package/esm/HierarchicalTrackSelectorWidget/model.js +211 -24
  77. package/esm/ucsc-trackhub/doConnect.d.ts +1 -0
  78. package/esm/ucsc-trackhub/doConnect.js +127 -0
  79. package/esm/ucsc-trackhub/model.d.ts +19 -2
  80. package/esm/ucsc-trackhub/model.js +17 -72
  81. package/esm/ucsc-trackhub/ucscTrackHub.d.ts +161 -4
  82. package/esm/ucsc-trackhub/ucscTrackHub.js +48 -141
  83. package/package.json +3 -4
  84. package/dist/HierarchicalTrackSelectorWidget/components/faceted/util.d.ts +0 -1
  85. package/esm/HierarchicalTrackSelectorWidget/components/faceted/util.d.ts +0 -1
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const mobx_state_tree_1 = require("mobx-state-tree");
4
+ const mobx_1 = require("mobx");
4
5
  const configuration_1 = require("@jbrowse/core/configuration");
5
6
  const util_1 = require("@jbrowse/core/util");
6
7
  const mst_1 = require("@jbrowse/core/util/types/mst");
@@ -8,6 +9,23 @@ const mst_1 = require("@jbrowse/core/util/types/mst");
8
9
  const filterTracks_1 = require("./filterTracks");
9
10
  const generateHierarchy_1 = require("./generateHierarchy");
10
11
  const util_2 = require("./util");
12
+ const facetedModel_1 = require("./facetedModel");
13
+ // for settings that are config dependent
14
+ function postNoConfigF() {
15
+ return typeof window !== undefined
16
+ ? [window.location.host, window.location.pathname].join('-')
17
+ : 'empty';
18
+ }
19
+ // for settings that are not config dependent
20
+ function postF() {
21
+ return typeof window !== undefined
22
+ ? [
23
+ postNoConfigF(),
24
+ new URLSearchParams(window.location.search).get('config'),
25
+ ].join('-')
26
+ : 'empty';
27
+ }
28
+ const MAX_RECENTLY_USED = 10;
11
29
  /**
12
30
  * #stateModel HierarchicalTrackSelectorWidget
13
31
  */
@@ -42,10 +60,38 @@ function stateTreeFactory(pluginManager) {
42
60
  * #property
43
61
  */
44
62
  view: mobx_state_tree_1.types.safeReference(pluginManager.pluggableMstType('view', 'stateModel')),
63
+ /**
64
+ * #property
65
+ */
66
+ faceted: mobx_state_tree_1.types.optional((0, facetedModel_1.facetedStateTreeF)(), {}),
45
67
  })
46
68
  .volatile(() => ({
69
+ favorites: [],
70
+ recentlyUsed: [],
47
71
  selection: [],
48
72
  filterText: '',
73
+ recentlyUsedCounter: 0,
74
+ favoritesCounter: 0,
75
+ }))
76
+ .views(self => ({
77
+ /**
78
+ * #getter
79
+ */
80
+ get selectionSet() {
81
+ return new Set(self.selection);
82
+ },
83
+ /**
84
+ * #getter
85
+ */
86
+ get favoritesSet() {
87
+ return new Set(self.favorites);
88
+ },
89
+ /**
90
+ * #getter
91
+ */
92
+ get recentlyUsedSet() {
93
+ return new Set(self.recentlyUsed);
94
+ },
49
95
  }))
50
96
  .actions(self => ({
51
97
  /**
@@ -76,7 +122,8 @@ function stateTreeFactory(pluginManager) {
76
122
  * #action
77
123
  */
78
124
  removeFromSelection(elt) {
79
- self.selection = self.selection.filter(f => !elt.includes(f));
125
+ const s = new Set(elt);
126
+ self.selection = self.selection.filter(f => !s.has(f));
80
127
  },
81
128
  /**
82
129
  * #action
@@ -84,6 +131,67 @@ function stateTreeFactory(pluginManager) {
84
131
  clearSelection() {
85
132
  self.selection = [];
86
133
  },
134
+ /**
135
+ * #action
136
+ */
137
+ addToFavorites(trackId) {
138
+ self.favoritesCounter += 1;
139
+ self.favorites = [...self.favorites, trackId];
140
+ },
141
+ /**
142
+ * #action
143
+ */
144
+ removeFromFavorites(trackId) {
145
+ self.favorites = self.favorites.filter(f => f !== trackId);
146
+ },
147
+ /**
148
+ * #action
149
+ */
150
+ clearFavorites() {
151
+ self.favorites = [];
152
+ },
153
+ /**
154
+ * #action
155
+ */
156
+ setRecentlyUsedCounter(val) {
157
+ self.recentlyUsedCounter = val;
158
+ },
159
+ /**
160
+ * #action
161
+ */
162
+ setRecentlyUsed(str) {
163
+ self.recentlyUsed = str;
164
+ },
165
+ /**
166
+ * #action
167
+ */
168
+ setFavorites(str) {
169
+ self.favorites = str;
170
+ },
171
+ /**
172
+ * #action
173
+ */
174
+ setFavoritesCounter(val) {
175
+ self.favoritesCounter = val;
176
+ },
177
+ /**
178
+ * #action
179
+ */
180
+ addToRecentlyUsed(id) {
181
+ if (!self.recentlyUsed.includes(id)) {
182
+ self.recentlyUsedCounter = Math.min(self.recentlyUsedCounter + 1, MAX_RECENTLY_USED);
183
+ self.recentlyUsed =
184
+ self.recentlyUsed.length >= MAX_RECENTLY_USED
185
+ ? [...self.recentlyUsed.slice(1), id]
186
+ : [...self.recentlyUsed, id];
187
+ }
188
+ },
189
+ /**
190
+ * #action
191
+ */
192
+ clearRecentlyUsed() {
193
+ self.recentlyUsed = [];
194
+ },
87
195
  /**
88
196
  * #action
89
197
  */
@@ -122,6 +230,24 @@ function stateTreeFactory(pluginManager) {
122
230
  },
123
231
  }))
124
232
  .views(self => ({
233
+ /**
234
+ * #method
235
+ */
236
+ isSelected(track) {
237
+ return self.selectionSet.has(track);
238
+ },
239
+ /**
240
+ * #method
241
+ */
242
+ isFavorite(trackId) {
243
+ return self.favoritesSet.has(trackId);
244
+ },
245
+ /**
246
+ * #method
247
+ */
248
+ isRecentlyUsed(trackId) {
249
+ return self.recentlyUsedSet.has(trackId);
250
+ },
125
251
  /**
126
252
  * #method
127
253
  */
@@ -151,6 +277,22 @@ function stateTreeFactory(pluginManager) {
151
277
  },
152
278
  }))
153
279
  .views(self => ({
280
+ /**
281
+ * #getter
282
+ */
283
+ get recentlyUsedLocalStorageKey() {
284
+ return `recentlyUsedTracks-${[postF(), self.assemblyNames.join(',')]
285
+ .filter(f => !!f)
286
+ .join('-')}`;
287
+ },
288
+ /**
289
+ * #getter
290
+ */
291
+ get favoritesLocalStorageKey() {
292
+ // this has a extra } at the end because that's how it was initially
293
+ // released
294
+ return `favoriteTracks-${postF()}}`;
295
+ },
154
296
  /**
155
297
  * #getter
156
298
  */
@@ -165,47 +307,71 @@ function stateTreeFactory(pluginManager) {
165
307
  var _a;
166
308
  return ((_a = self.sortCategories) !== null && _a !== void 0 ? _a : (0, configuration_1.getConf)((0, util_1.getSession)(self), ['hierarchical', 'sort', 'categories']));
167
309
  },
168
- /**
169
- * #method
170
- * filter out tracks that don't match the current display types
171
- */
172
- connectionTrackConfigurations(connection) {
173
- return (0, filterTracks_1.filterTracks)(connection.tracks, self);
174
- },
175
310
  /**
176
311
  * #getter
177
312
  * filter out tracks that don't match the current assembly/display types
178
313
  */
179
- get trackConfigurations() {
314
+ get configAndSessionTrackConfigurations() {
180
315
  return [
181
316
  ...self.assemblyNames.map(a => self.getRefSeqTrackConf(a)),
182
317
  ...(0, filterTracks_1.filterTracks)((0, util_1.getSession)(self).tracks, self),
183
318
  ].filter(util_1.notEmpty);
184
319
  },
320
+ /**
321
+ * #getter
322
+ */
323
+ get allTrackConfigurations() {
324
+ const { connectionInstances = [] } = (0, util_1.getSession)(self);
325
+ return [
326
+ ...this.configAndSessionTrackConfigurations,
327
+ ...connectionInstances === null || connectionInstances === void 0 ? void 0 : connectionInstances.flatMap(c => c.tracks),
328
+ ];
329
+ },
330
+ /**
331
+ * #getter
332
+ */
333
+ get allTrackConfigurationTrackIdSet() {
334
+ return new Map(this.allTrackConfigurations.map(t => [t.trackId, t]));
335
+ },
185
336
  }))
186
337
  .views(self => ({
187
338
  /**
188
- * #method
339
+ * #getter
340
+ * filters out tracks that are not in the favorites group
341
+ */
342
+ get favoriteTracks() {
343
+ return self.favorites
344
+ .filter(t => self.allTrackConfigurationTrackIdSet.has(t))
345
+ .map(t => self.allTrackConfigurationTrackIdSet.get(t));
346
+ },
347
+ /**
348
+ * #getter
349
+ * filters out tracks that are not in the recently used group
189
350
  */
190
- connectionHierarchy(connection) {
191
- return (0, generateHierarchy_1.generateHierarchy)({
192
- model: self,
193
- trackConfs: self.connectionTrackConfigurations(connection),
194
- extra: connection.name,
195
- });
351
+ get recentlyUsedTracks() {
352
+ return self.recentlyUsed
353
+ .filter(t => self.allTrackConfigurationTrackIdSet.has(t))
354
+ .map(t => self.allTrackConfigurationTrackIdSet.get(t));
196
355
  },
197
356
  }))
198
357
  .views(self => ({
358
+ /**
359
+ * #getter
360
+ */
199
361
  get allTracks() {
200
362
  const { connectionInstances = [] } = (0, util_1.getSession)(self);
201
363
  return [
202
364
  {
203
365
  group: 'Tracks',
204
- tracks: self.trackConfigurations,
366
+ tracks: self.configAndSessionTrackConfigurations,
367
+ noCategories: false,
368
+ menuItems: [],
205
369
  },
206
370
  ...connectionInstances.flatMap(c => ({
207
371
  group: (0, configuration_1.getConf)(c, 'name'),
208
372
  tracks: c.tracks,
373
+ noCategories: false,
374
+ menuItems: [],
209
375
  })),
210
376
  ];
211
377
  },
@@ -218,17 +384,21 @@ function stateTreeFactory(pluginManager) {
218
384
  return {
219
385
  name: 'Root',
220
386
  id: 'Root',
221
- children: self.allTracks
222
- .map(s => ({
387
+ isOpenByDefault: true,
388
+ type: 'category',
389
+ children: self.allTracks.map(s => ({
223
390
  name: s.group,
224
391
  id: s.group,
392
+ type: 'category',
393
+ isOpenByDefault: !self.collapsed.get(s.group),
394
+ menuItems: s.menuItems,
225
395
  children: (0, generateHierarchy_1.generateHierarchy)({
226
396
  model: self,
227
397
  trackConfs: s.tracks,
398
+ extra: s.group,
399
+ noCategories: s.noCategories,
228
400
  }),
229
- }))
230
- // always keep the Tracks entry at idx 0
231
- .filter((f, idx) => idx === 0 || !!f.children.length),
401
+ })),
232
402
  };
233
403
  },
234
404
  }))
@@ -288,9 +458,26 @@ function stateTreeFactory(pluginManager) {
288
458
  },
289
459
  }))
290
460
  .views(self => ({
461
+ /**
462
+ * #getter
463
+ */
291
464
  get hasAnySubcategories() {
292
465
  return self.allTracks.some(group => group.tracks.some(t => { var _a; return ((_a = (0, configuration_1.readConfObject)(t, 'category')) === null || _a === void 0 ? void 0 : _a.length) > 1; }));
293
466
  },
467
+ }))
468
+ .actions(self => ({
469
+ afterAttach() {
470
+ // this should be the first autorun to properly initialize
471
+ (0, mobx_state_tree_1.addDisposer)(self, (0, mobx_1.autorun)(() => {
472
+ self.setRecentlyUsed(JSON.parse((0, util_1.localStorageGetItem)(self.recentlyUsedLocalStorageKey) || '[]'));
473
+ self.setFavorites(JSON.parse((0, util_1.localStorageGetItem)(self.favoritesLocalStorageKey) || '[]'));
474
+ }));
475
+ // this should be the second autorun
476
+ (0, mobx_state_tree_1.addDisposer)(self, (0, mobx_1.autorun)(() => {
477
+ (0, util_1.localStorageSetItem)(self.favoritesLocalStorageKey, JSON.stringify(self.favorites));
478
+ (0, util_1.localStorageSetItem)(self.recentlyUsedLocalStorageKey, JSON.stringify(self.recentlyUsed));
479
+ }));
480
+ },
294
481
  }));
295
482
  }
296
483
  exports.default = stateTreeFactory;
@@ -0,0 +1 @@
1
+ export declare function doConnect(self: any): Promise<void>;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.doConnect = void 0;
4
+ const ucsc_hub_1 = require("@gmod/ucsc-hub");
5
+ const ucscTrackHub_1 = require("./ucscTrackHub");
6
+ const configuration_1 = require("@jbrowse/core/configuration");
7
+ const util_1 = require("@jbrowse/core/util");
8
+ const io_1 = require("@jbrowse/core/util/io");
9
+ const nanoid_1 = require("@jbrowse/core/util/nanoid");
10
+ function resolve(uri, baseUri) {
11
+ return new URL(uri, baseUri).href;
12
+ }
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ async function doConnect(self) {
15
+ var _a;
16
+ const session = (0, util_1.getSession)(self);
17
+ const notLoadedAssemblies = [];
18
+ try {
19
+ const hubFileLocation = (0, configuration_1.getConf)(self, 'hubTxtLocation');
20
+ const hubFileText = await (0, io_1.openLocation)(hubFileLocation).readFile('utf8');
21
+ // @ts-expect-error
22
+ const hubUri = resolve(hubFileLocation.uri, hubFileLocation.baseUri);
23
+ const { assemblyManager } = session;
24
+ if (hubFileText.includes('useOneFile on')) {
25
+ const hub = new ucsc_hub_1.SingleFileHub(hubFileText);
26
+ const { genome, tracks } = hub;
27
+ const genomeName = genome.name;
28
+ const asm = assemblyManager.get(genomeName);
29
+ if (!asm) {
30
+ // @ts-expect-error
31
+ session.addSessionAssembly({
32
+ name: genomeName,
33
+ sequence: {
34
+ type: 'ReferenceSequenceTrack',
35
+ trackId: `${genomeName}-${(0, nanoid_1.nanoid)()}`,
36
+ adapter: {
37
+ type: 'TwoBitAdapter',
38
+ twoBitLocation: {
39
+ uri: resolve(genome.data.twoBitPath, hubUri),
40
+ },
41
+ chromSizesLocation: {
42
+ uri: resolve(genome.data.chromSizes, hubUri),
43
+ },
44
+ },
45
+ },
46
+ });
47
+ }
48
+ const asm2 = assemblyManager.get(genomeName);
49
+ const sequenceAdapter = (0, configuration_1.getConf)(asm2, ['sequence', 'adapter']);
50
+ const tracksNew = (0, ucscTrackHub_1.generateTracks)({
51
+ trackDb: tracks,
52
+ trackDbLoc: hubFileLocation,
53
+ assemblyName: genomeName,
54
+ sequenceAdapter,
55
+ });
56
+ self.addTrackConfs(tracksNew);
57
+ }
58
+ else {
59
+ const hubFile = new ucsc_hub_1.HubFile(hubFileText);
60
+ const genomeFile = hubFile.data.genomesFile;
61
+ if (!genomeFile) {
62
+ throw new Error('genomesFile not found on hub');
63
+ }
64
+ // @ts-expect-error
65
+ const hubUri = resolve(hubFileLocation.uri, hubFileLocation.baseUri);
66
+ const genomesFileLocation = hubUri
67
+ ? {
68
+ uri: resolve(genomeFile, hubUri),
69
+ locationType: 'UriLocation',
70
+ }
71
+ : {
72
+ localPath: genomeFile,
73
+ locationType: 'LocalPathLocation',
74
+ };
75
+ const genomesFile = await (0, ucscTrackHub_1.fetchGenomesFile)(genomesFileLocation);
76
+ const map = {};
77
+ for (const [genomeName, genome] of Object.entries(genomesFile.data)) {
78
+ const assemblyNames = (0, configuration_1.getConf)(self, 'assemblyNames');
79
+ if (assemblyNames.length > 0 && !assemblyNames.includes(genomeName)) {
80
+ continue;
81
+ }
82
+ const asm = assemblyManager.get(genomeName);
83
+ if (!asm) {
84
+ notLoadedAssemblies.push(genomeName);
85
+ continue;
86
+ }
87
+ // @ts-expect-error
88
+ const db = genome.data.trackDb;
89
+ if (!db) {
90
+ throw new Error('genomesFile not found on hub');
91
+ }
92
+ const base = new URL(genomeFile, hubUri);
93
+ const loc = hubUri
94
+ ? {
95
+ uri: new URL(db, base).href,
96
+ locationType: 'UriLocation',
97
+ }
98
+ : {
99
+ localPath: db,
100
+ locationType: 'LocalPathLocation',
101
+ };
102
+ const trackDb = await (0, ucscTrackHub_1.fetchTrackDbFile)(loc);
103
+ const sequenceAdapter = (0, configuration_1.getConf)(asm, ['sequence', 'adapter']);
104
+ const tracks = (0, ucscTrackHub_1.generateTracks)({
105
+ trackDb,
106
+ trackDbLoc: loc,
107
+ assemblyName: genomeName,
108
+ sequenceAdapter,
109
+ });
110
+ self.addTrackConfs(tracks);
111
+ map[genomeName] = tracks.length;
112
+ }
113
+ const loadedAssemblies = Object.entries(map);
114
+ const str1 = loadedAssemblies.length
115
+ ? `Loaded data from these assemblies: ${loadedAssemblies
116
+ .map(([key, val]) => `${key} (${val} tracks)`)
117
+ .join(', ')}`
118
+ : '';
119
+ const str2 = notLoadedAssemblies.length
120
+ ? `Skipped data from these assemblies: ${notLoadedAssemblies.join(', ')}`
121
+ : '';
122
+ session.notify([str1, str2].filter(f => !!f).join('. '), 'success');
123
+ }
124
+ }
125
+ catch (e) {
126
+ console.error(e);
127
+ session.notify(`${(0, configuration_1.getConf)(self, 'name')}: "${e}"`, 'error');
128
+ (_a = session.breakConnection) === null || _a === void 0 ? void 0 : _a.call(session, self.configuration);
129
+ }
130
+ }
131
+ exports.doConnect = doConnect;
@@ -1,4 +1,8 @@
1
1
  import PluginManager from '@jbrowse/core/PluginManager';
2
+ /**
3
+ * #stateModel UCSCTrackHubConnection
4
+ * extends BaseConnectionModel
5
+ */
2
6
  export default function UCSCTrackHubConnection(pluginManager: PluginManager): import("mobx-state-tree").IModelType<{
3
7
  name: import("mobx-state-tree").ISimpleType<string>;
4
8
  tracks: import("mobx-state-tree").IArrayType<import("mobx-state-tree").IAnyModelType>;
@@ -10,11 +14,16 @@ export default function UCSCTrackHubConnection(pluginManager: PluginManager): im
10
14
  };
11
15
  assemblyNames: {
12
16
  type: string;
13
- defaultValue: never[];
17
+ defaultValue: never[]; /**
18
+ * #action
19
+ */
14
20
  description: string;
15
21
  };
16
22
  }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "connectionId">>;
17
23
  } & {
24
+ /**
25
+ * #property
26
+ */
18
27
  configuration: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
19
28
  hubTxtLocation: {
20
29
  type: string;
@@ -25,7 +34,9 @@ export default function UCSCTrackHubConnection(pluginManager: PluginManager): im
25
34
  description: string;
26
35
  };
27
36
  assemblyNames: {
28
- type: string;
37
+ type: string; /**
38
+ * #property
39
+ */
29
40
  defaultValue: never[];
30
41
  description: string;
31
42
  };
@@ -41,6 +52,9 @@ export default function UCSCTrackHubConnection(pluginManager: PluginManager): im
41
52
  description: string;
42
53
  };
43
54
  }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "connectionId">>, undefined>>;
55
+ /**
56
+ * #property
57
+ */
44
58
  type: import("mobx-state-tree").ISimpleType<"UCSCTrackHubConnection">;
45
59
  }, {
46
60
  connect(_arg: {
@@ -67,5 +81,8 @@ export default function UCSCTrackHubConnection(pluginManager: PluginManager): im
67
81
  } & import("mobx-state-tree").IStateTreeNode<import("@jbrowse/core/configuration").AnyConfigurationSchemaType>)[]): import("mobx-state-tree").IMSTArray<import("mobx-state-tree").IAnyModelType> & import("mobx-state-tree").IStateTreeNode<import("mobx-state-tree").IArrayType<import("mobx-state-tree").IAnyModelType>>;
68
82
  clear(): void;
69
83
  } & {
84
+ /**
85
+ * #action
86
+ */
70
87
  connect(): Promise<void>;
71
88
  }, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>;
@@ -28,88 +28,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const models_1 = require("@jbrowse/core/pluggableElementTypes/models");
30
30
  const configuration_1 = require("@jbrowse/core/configuration");
31
- const util_1 = require("@jbrowse/core/util");
32
31
  const mobx_state_tree_1 = require("mobx-state-tree");
33
32
  // locals
34
33
  const configSchema_1 = __importDefault(require("./configSchema"));
34
+ /**
35
+ * #stateModel UCSCTrackHubConnection
36
+ * extends BaseConnectionModel
37
+ */
35
38
  function UCSCTrackHubConnection(pluginManager) {
36
39
  return mobx_state_tree_1.types
37
40
  .compose('UCSCTrackHubConnection', (0, models_1.BaseConnectionModelFactory)(pluginManager), mobx_state_tree_1.types.model({
41
+ /**
42
+ * #property
43
+ */
38
44
  configuration: (0, configuration_1.ConfigurationReference)(configSchema_1.default),
45
+ /**
46
+ * #property
47
+ */
39
48
  type: mobx_state_tree_1.types.literal('UCSCTrackHubConnection'),
40
49
  }))
41
50
  .actions(self => ({
51
+ /**
52
+ * #action
53
+ */
42
54
  async connect() {
43
- var _a, _b;
44
- const session = (0, util_1.getSession)(self);
45
- const notLoadedAssemblies = [];
46
- try {
47
- const hubFileLocation = (0, configuration_1.getConf)(self, 'hubTxtLocation');
48
- const { generateTracks, fetchGenomesFile, fetchTrackDbFile, fetchHubFile, } = await Promise.resolve().then(() => __importStar(require('./ucscTrackHub')));
49
- const hubFile = await fetchHubFile(hubFileLocation);
50
- const genomeFile = hubFile.get('genomesFile');
51
- if (!genomeFile) {
52
- throw new Error('genomesFile not found on hub');
53
- }
54
- const hubUri = new URL(hubFileLocation.uri, hubFileLocation.baseUri);
55
- const genomesFileLocation = hubUri
56
- ? {
57
- uri: new URL(genomeFile, hubUri).href,
58
- locationType: 'UriLocation',
59
- }
60
- : {
61
- localPath: genomeFile,
62
- locationType: 'LocalPathLocation',
63
- };
64
- const genomesFile = await fetchGenomesFile(genomesFileLocation);
65
- const map = {};
66
- for (const [genomeName, genome] of genomesFile) {
67
- const assemblyNames = (0, configuration_1.getConf)(self, 'assemblyNames');
68
- if (assemblyNames.length > 0 &&
69
- !assemblyNames.includes(genomeName)) {
70
- continue;
71
- }
72
- const conf = (_a = session.assemblyManager.get(genomeName)) === null || _a === void 0 ? void 0 : _a.configuration;
73
- if (!conf) {
74
- notLoadedAssemblies.push(genomeName);
75
- continue;
76
- }
77
- const db = genome.get('trackDb');
78
- if (!db) {
79
- throw new Error('genomesFile not found on hub');
80
- }
81
- const base = new URL(genomeFile, hubUri);
82
- const loc = hubUri
83
- ? {
84
- uri: new URL(db, base).href,
85
- locationType: 'UriLocation',
86
- }
87
- : {
88
- localPath: db,
89
- locationType: 'LocalPathLocation',
90
- };
91
- const trackDb = await fetchTrackDbFile(loc);
92
- const seqAdapter = (0, configuration_1.readConfObject)(conf, ['sequence', 'adapter']);
93
- const tracks = generateTracks(trackDb, loc, genomeName, seqAdapter);
94
- self.addTrackConfs(tracks);
95
- map[genomeName] = tracks.length;
96
- }
97
- const loadedAssemblies = Object.entries(map);
98
- const str1 = loadedAssemblies.length
99
- ? `Loaded data from these assemblies: ${loadedAssemblies
100
- .map(([key, val]) => `${key} (${val} tracks)`)
101
- .join(', ')}`
102
- : '';
103
- const str2 = notLoadedAssemblies.length
104
- ? `Skipped data from these assemblies: ${notLoadedAssemblies.join(', ')}`
105
- : '';
106
- session.notify([str1, str2].filter(f => !!f).join('. '), 'success');
107
- }
108
- catch (e) {
109
- console.error(e);
110
- session.notify(`There was a problem connecting to the UCSC Track Hub "${self.configuration.name}". Please make sure you have entered a valid hub.txt file. The error that was thrown is: "${e}"`, 'error');
111
- (_b = session.breakConnection) === null || _b === void 0 ? void 0 : _b.call(session, self.configuration);
112
- }
55
+ const { doConnect } = await Promise.resolve().then(() => __importStar(require('./doConnect')));
56
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
57
+ doConnect(self);
113
58
  },
114
59
  }));
115
60
  }