@vitessce/vit-s 2.0.3-beta.0 → 2.0.3

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 (184) hide show
  1. package/dist/index.mjs +84801 -0
  2. package/{dist → dist-tsc}/index.js +2 -2
  3. package/package.json +7 -7
  4. package/src/CallbackPublisher.js +81 -0
  5. package/src/LoadingIndicator.js +34 -0
  6. package/src/TitleInfo.js +240 -0
  7. package/src/VitS.js +180 -0
  8. package/src/VitessceGrid.js +110 -0
  9. package/src/VitessceGrid.test.jsx +48 -0
  10. package/src/Warning.js +62 -0
  11. package/{dist → src}/classNames.js +0 -0
  12. package/src/component-registry.js +21 -0
  13. package/src/data/AbstractLoader.js +46 -0
  14. package/{dist → src}/data/AbstractTwoStepLoader.js +5 -4
  15. package/src/data/LoaderResult.js +8 -0
  16. package/{dist → src}/data/index.js +0 -0
  17. package/src/data/loader-registry.js +19 -0
  18. package/src/data-hook-utils.js +197 -0
  19. package/src/data-hooks.js +354 -0
  20. package/src/errors/AbstractLoaderError.js +14 -0
  21. package/src/errors/DataSourceFetchError.js +15 -0
  22. package/src/errors/DatasetNotFoundError.js +23 -0
  23. package/src/errors/LoaderNotFoundError.js +24 -0
  24. package/src/errors/LoaderValidationError.js +23 -0
  25. package/src/errors/OptionsValidationError.js +25 -0
  26. package/{dist → src}/errors/index.js +0 -0
  27. package/src/file-options-schemas-legacy.js +139 -0
  28. package/src/file-options-schemas-legacy.test.js +138 -0
  29. package/src/file-options-schemas.js +327 -0
  30. package/src/file-options-schemas.test.js +26 -0
  31. package/src/hooks.js +252 -0
  32. package/src/index.js +101 -0
  33. package/src/joint-file-types-legacy.js +298 -0
  34. package/src/joint-file-types-legacy.test.js +412 -0
  35. package/src/joint-file-types.js +171 -0
  36. package/src/joint-file-types.test.js +144 -0
  37. package/{dist/schemas.js → src/json-schemas.js} +6 -1
  38. package/{dist → src}/plugins.js +102 -70
  39. package/src/plugins.test.fixtures.js +78 -0
  40. package/src/plugins.test.js +42 -0
  41. package/src/schemas/config-0.1.0.schema.json +85 -0
  42. package/src/schemas/config-1.0.0.schema.json +733 -0
  43. package/src/schemas/config-1.0.1.schema.json +909 -0
  44. package/src/schemas/config-1.0.10.schema.json +969 -0
  45. package/src/schemas/config-1.0.11.schema.json +990 -0
  46. package/src/schemas/config-1.0.12.schema.json +997 -0
  47. package/src/schemas/config-1.0.13.schema.json +1013 -0
  48. package/src/schemas/config-1.0.14.schema.json +1048 -0
  49. package/src/schemas/config-1.0.15.schema.json +1048 -0
  50. package/src/schemas/config-1.0.16.schema.json +1069 -0
  51. package/src/schemas/config-1.0.16.schema.test.js +32 -0
  52. package/src/schemas/config-1.0.2.schema.json +911 -0
  53. package/src/schemas/config-1.0.3.schema.json +911 -0
  54. package/src/schemas/config-1.0.4.schema.json +949 -0
  55. package/src/schemas/config-1.0.5.schema.json +949 -0
  56. package/src/schemas/config-1.0.6.schema.json +950 -0
  57. package/src/schemas/config-1.0.7.schema.json +950 -0
  58. package/src/schemas/config-1.0.8.schema.json +966 -0
  59. package/src/schemas/config-1.0.9.schema.json +965 -0
  60. package/src/schemas/fixtures/cellSets.good.json +16 -0
  61. package/src/schemas/fixtures/config-1.0.1.bad.json +1 -0
  62. package/src/schemas/fixtures/config-1.0.1.bad.message.json +11 -0
  63. package/src/schemas/fixtures/config-1.0.1.good.json +37 -0
  64. package/src/schemas/fixtures/config-1.0.2.bad.json +1 -0
  65. package/src/schemas/fixtures/config-1.0.2.bad.message.json +11 -0
  66. package/src/schemas/fixtures/config-1.0.2.good.json +38 -0
  67. package/src/schemas/fixtures/config-1.0.3.bad.json +1 -0
  68. package/src/schemas/fixtures/config-1.0.3.bad.message.json +11 -0
  69. package/src/schemas/fixtures/config-1.0.3.good.json +38 -0
  70. package/src/schemas/fixtures/obsSets.bad.json +1 -0
  71. package/src/schemas/fixtures/obsSets.bad.message.json +11 -0
  72. package/src/schemas/fixtures/obsSets.good.json +16 -0
  73. package/src/schemas/fixtures/obsSetsTabular.bad.json +1 -0
  74. package/src/schemas/fixtures/obsSetsTabular.bad.message.json +11 -0
  75. package/src/schemas/fixtures/obsSetsTabular.good.json +26 -0
  76. package/src/schemas/fixtures/raster.bad.json +1 -0
  77. package/src/schemas/fixtures/raster.bad.message.json +11 -0
  78. package/src/schemas/fixtures/raster.good.json +39 -0
  79. package/src/schemas/obsSets.schema.js +195 -0
  80. package/src/schemas/obsSetsTabular.schema.js +39 -0
  81. package/src/schemas/raster.schema.js +121 -0
  82. package/src/schemas/schema-schema.sh +34 -0
  83. package/{dist → src}/schemas/schema.test-old.js +0 -1
  84. package/src/shared-mui/components.js +79 -0
  85. package/src/shared-mui/container.js +212 -0
  86. package/src/shared-mui/styles.js +110 -0
  87. package/src/shared-plot-options/CellColorEncodingOption.js +43 -0
  88. package/src/shared-plot-options/OptionSelect.js +19 -0
  89. package/src/shared-plot-options/OptionsContainer.js +26 -0
  90. package/{dist → src}/shared-plot-options/index.js +0 -0
  91. package/src/shared-plot-options/styles.js +49 -0
  92. package/src/state/hooks.js +633 -0
  93. package/src/view-config-upgraders.js +628 -0
  94. package/src/view-config-utils.js +315 -0
  95. package/src/view-config-utils.test.fixtures.js +893 -0
  96. package/src/view-config-utils.test.js +95 -0
  97. package/src/view-config-versions.js +68 -0
  98. package/src/vitessce-grid-layout/VitessceGridLayout.js +158 -0
  99. package/src/vitessce-grid-layout/VitessceGridLayout.test.jsx +56 -0
  100. package/{dist → src}/vitessce-grid-layout/index.js +0 -0
  101. package/src/vitessce-grid-layout/layout-utils.js +76 -0
  102. package/src/vitessce-grid-layout/layout-utils.test.js +167 -0
  103. package/src/vitessce-grid-utils.js +160 -0
  104. package/dist/CallbackPublisher.js +0 -68
  105. package/dist/LoadingIndicator.js +0 -27
  106. package/dist/TitleInfo.js +0 -151
  107. package/dist/VitS.js +0 -117
  108. package/dist/Vitessce.integration.test.js +0 -36
  109. package/dist/Vitessce.js +0 -101
  110. package/dist/VitessceGrid.js +0 -59
  111. package/dist/VitessceGrid.test.js +0 -36
  112. package/dist/Warning.js +0 -45
  113. package/dist/component-registry.js +0 -16
  114. package/dist/data/AbstractLoader.js +0 -35
  115. package/dist/data/LoaderResult.js +0 -7
  116. package/dist/data/loader-registry.js +0 -15
  117. package/dist/data-hook-utils.js +0 -175
  118. package/dist/data-hooks.js +0 -241
  119. package/dist/errors/AbstractLoaderError.js +0 -13
  120. package/dist/errors/DataSourceFetchError.js +0 -13
  121. package/dist/errors/DatasetNotFoundError.js +0 -17
  122. package/dist/errors/LoaderNotFoundError.js +0 -17
  123. package/dist/errors/LoaderValidationError.js +0 -15
  124. package/dist/errors/OptionsValidationError.js +0 -15
  125. package/dist/export-utils.js +0 -70
  126. package/dist/export-utils.test.js +0 -66
  127. package/dist/file-options-schemas-legacy.js +0 -136
  128. package/dist/file-options-schemas-legacy.test.js +0 -126
  129. package/dist/file-options-schemas.js +0 -322
  130. package/dist/file-options-schemas.test.js +0 -23
  131. package/dist/hooks.js +0 -215
  132. package/dist/joint-file-types-legacy.js +0 -278
  133. package/dist/joint-file-types-legacy.test.js +0 -400
  134. package/dist/joint-file-types.js +0 -148
  135. package/dist/joint-file-types.test.js +0 -139
  136. package/dist/loader-registry.js +0 -98
  137. package/dist/plugins.test.fixtures.js +0 -76
  138. package/dist/plugins.test.js +0 -30
  139. package/dist/schemas/PrettyJsonSchema.js +0 -34
  140. package/dist/schemas/config-0.1.0.schema.json +0 -84
  141. package/dist/schemas/config-1.0.0.schema.json +0 -733
  142. package/dist/schemas/config-1.0.1.schema.json +0 -909
  143. package/dist/schemas/config-1.0.10.schema.json +0 -969
  144. package/dist/schemas/config-1.0.11.schema.json +0 -990
  145. package/dist/schemas/config-1.0.12.schema.json +0 -997
  146. package/dist/schemas/config-1.0.13.schema.json +0 -1013
  147. package/dist/schemas/config-1.0.14.schema.json +0 -1048
  148. package/dist/schemas/config-1.0.15.schema.json +0 -1048
  149. package/dist/schemas/config-1.0.15.schema.test.js +0 -22
  150. package/dist/schemas/config-1.0.16.schema.json +0 -1109
  151. package/dist/schemas/config-1.0.16.schema.test.js +0 -22
  152. package/dist/schemas/config-1.0.2.schema.json +0 -910
  153. package/dist/schemas/config-1.0.3.schema.json +0 -910
  154. package/dist/schemas/config-1.0.4.schema.json +0 -949
  155. package/dist/schemas/config-1.0.5.schema.json +0 -949
  156. package/dist/schemas/config-1.0.6.schema.json +0 -949
  157. package/dist/schemas/config-1.0.7.schema.json +0 -949
  158. package/dist/schemas/config-1.0.8.schema.json +0 -965
  159. package/dist/schemas/config-1.0.9.schema.json +0 -965
  160. package/dist/schemas/obs-sets-tabular.schema.js +0 -37
  161. package/dist/schemas/obs-sets.schema.js +0 -194
  162. package/dist/schemas/obsSets.schema.js +0 -195
  163. package/dist/schemas/obsSetsTabular.schema.js +0 -38
  164. package/dist/schemas/raster.schema.js +0 -120
  165. package/dist/schemas/schema.test.js +0 -46
  166. package/dist/schemas-extra.js +0 -3
  167. package/dist/shared-mui/components.js +0 -35
  168. package/dist/shared-mui/container.js +0 -211
  169. package/dist/shared-mui/styles.js +0 -107
  170. package/dist/shared-plot-options/CellColorEncodingOption.js +0 -18
  171. package/dist/shared-plot-options/OptionSelect.js +0 -12
  172. package/dist/shared-plot-options/OptionsContainer.js +0 -12
  173. package/dist/shared-plot-options/styles.js +0 -48
  174. package/dist/state/hooks.js +0 -549
  175. package/dist/view-config-upgraders.js +0 -525
  176. package/dist/view-config-utils.js +0 -286
  177. package/dist/view-config-utils.test.fixtures.js +0 -765
  178. package/dist/view-config-utils.test.js +0 -66
  179. package/dist/view-config-versions.js +0 -47
  180. package/dist/vitessce-grid-layout/VitessceGridLayout.js +0 -95
  181. package/dist/vitessce-grid-layout/VitessceGridLayout.test.js +0 -40
  182. package/dist/vitessce-grid-layout/layout-utils.js +0 -60
  183. package/dist/vitessce-grid-layout/layout-utils.test.js +0 -146
  184. package/dist/vitessce-grid-utils.js +0 -140
package/src/hooks.js ADDED
@@ -0,0 +1,252 @@
1
+ import {
2
+ useRef, useState, useEffect, useCallback, useMemo,
3
+ } from 'react';
4
+ import debounce from 'lodash/debounce';
5
+ import every from 'lodash/every';
6
+ import { capitalize, fromEntries } from '@vitessce/utils';
7
+ import { useGridResize, useEmitGridResize } from './state/hooks';
8
+ import { VITESSCE_CONTAINER } from './classNames';
9
+
10
+ function getWindowDimensions() {
11
+ const { innerWidth: width, innerHeight: height } = window;
12
+ return {
13
+ width,
14
+ height,
15
+ };
16
+ }
17
+
18
+ export function useVitessceContainer(ref) {
19
+ return useCallback(() => {
20
+ if (ref.current) {
21
+ return ref.current.closest(`.${VITESSCE_CONTAINER}`);
22
+ }
23
+ return null;
24
+ }, [ref]);
25
+ }
26
+
27
+ /**
28
+ * Custom hook, gets the full window dimensions.
29
+ * @returns {array} `[width, height]` where width and height
30
+ * are numbers.
31
+ */
32
+ export function useWindowDimensions() {
33
+ const [windowDimensions, setWindowDimensions] = useState(
34
+ getWindowDimensions(),
35
+ );
36
+
37
+ useEffect(() => {
38
+ function handleResize() {
39
+ setWindowDimensions(getWindowDimensions());
40
+ }
41
+ const onResizeDebounced = debounce(handleResize, 100, { trailing: true });
42
+
43
+ window.addEventListener('resize', onResizeDebounced);
44
+ return () => window.removeEventListener('resize', onResizeDebounced);
45
+ }, []);
46
+
47
+ return windowDimensions;
48
+ }
49
+
50
+ /**
51
+ * Custom hook, subscribes to GRID_RESIZE and window resize events.
52
+ * @returns {array} `[width, height, containerRef]` where width and height
53
+ * are numbers and containerRef is a React ref.
54
+ */
55
+ export function useGridItemSize() {
56
+ const containerRef = useRef();
57
+
58
+ const [height, setHeight] = useState();
59
+ const [width, setWidth] = useState();
60
+
61
+ const resizeCount = useGridResize();
62
+ const incrementResizeCount = useEmitGridResize();
63
+
64
+ // On window resize events, increment the grid resize count.
65
+ useEffect(() => {
66
+ function onWindowResize() {
67
+ incrementResizeCount();
68
+ }
69
+ const onResizeDebounced = debounce(onWindowResize, 100, { trailing: true });
70
+ window.addEventListener('resize', onResizeDebounced);
71
+ onWindowResize();
72
+ return () => {
73
+ window.removeEventListener('resize', onResizeDebounced);
74
+ };
75
+ }, [incrementResizeCount]);
76
+
77
+ // On new grid resize counts, re-compute the component
78
+ // width/height.
79
+ useEffect(() => {
80
+ if (!containerRef.current) return;
81
+ const container = containerRef.current;
82
+ const containerRect = container.getBoundingClientRect();
83
+ setHeight(containerRect.height);
84
+ setWidth(containerRect.width);
85
+ }, [resizeCount]);
86
+
87
+ return [width, height, containerRef];
88
+ }
89
+
90
+ /**
91
+ * Custom hook, subscribes to GRID_RESIZE and window resize events.
92
+ * @returns {array} `[width, height, deckRef]` where width and height
93
+ * are numbers and deckRef is a React ref to be used with
94
+ * a <DeckGL/> element (or a forwardRef to one).
95
+ */
96
+ export function useDeckCanvasSize() {
97
+ const deckRef = useRef();
98
+
99
+ const [height, setHeight] = useState();
100
+ const [width, setWidth] = useState();
101
+
102
+ const resizeCount = useGridResize();
103
+ const incrementResizeCount = useEmitGridResize();
104
+
105
+ // On window resize events, increment the grid resize count.
106
+ useEffect(() => {
107
+ function onWindowResize() {
108
+ incrementResizeCount();
109
+ }
110
+ const onResizeDebounced = debounce(onWindowResize, 100, { trailing: true });
111
+ window.addEventListener('resize', onResizeDebounced);
112
+ onWindowResize();
113
+ return () => {
114
+ window.removeEventListener('resize', onResizeDebounced);
115
+ };
116
+ }, [incrementResizeCount]);
117
+
118
+ // On new grid resize counts, re-compute the DeckGL canvas
119
+ // width/height.
120
+ useEffect(() => {
121
+ if (!deckRef.current) return;
122
+ const { canvas } = deckRef.current.deck;
123
+ const canvasRect = canvas.getBoundingClientRect();
124
+ setHeight(canvasRect.height);
125
+ setWidth(canvasRect.width);
126
+ }, [resizeCount]);
127
+
128
+ return [width, height, deckRef];
129
+ }
130
+
131
+ /**
132
+ * This hook handles a boolean isReady value,
133
+ * which only returns true once every item in the
134
+ * input list has been marked as "ready".
135
+ * @param {string[]} statusValues The items to wait on.
136
+ * @returns {boolean} Whether the status values are all success.
137
+ */
138
+ export function useReady(statusValues) {
139
+ return useMemo(() => every(
140
+ statusValues, val => val === 'success',
141
+ // eslint-disable-next-line react-hooks/exhaustive-deps
142
+ ), statusValues);
143
+ }
144
+
145
+ /**
146
+ * This hook helps manage a list of URLs.
147
+ * @param {object} loaders The loaders dependency.
148
+ * @param {string} dataset The dataset UID dependency.
149
+ * @returns {array} An array
150
+ * [urls, addUrl]
151
+ * where urls is the array of URL objects,
152
+ * and addUrl is a function for adding a URL to the array.
153
+ */
154
+ export function useUrls(loaders, dataset) {
155
+ const [urls, setUrls] = useState([]);
156
+
157
+ const addUrl = useCallback((url, name) => {
158
+ if (url) {
159
+ setUrls(prev => ([...prev, { url, name }]));
160
+ }
161
+ }, [setUrls]);
162
+
163
+ useEffect(() => {
164
+ setUrls([]);
165
+ }, [loaders, dataset]);
166
+
167
+ return [urls, addUrl];
168
+ }
169
+
170
+ /**
171
+ * Custom hook, subscribes to the width and height of the closest .vitessce-container
172
+ * element and updates upon window resize events.
173
+ * @param {Ref} ref A React ref object within the `.vitessce-container`.
174
+ * @returns {array} `[width, height]` where width and height
175
+ * are numbers.
176
+ */
177
+ export function useClosestVitessceContainerSize(ref) {
178
+ const [height, setHeight] = useState();
179
+ const [width, setWidth] = useState();
180
+
181
+ useEffect(() => {
182
+ function onWindowResize() {
183
+ if (ref.current) {
184
+ const {
185
+ clientHeight: componentHeight, clientWidth: componentWidth,
186
+ } = ref.current.closest(`.${VITESSCE_CONTAINER}`);
187
+ setWidth(componentWidth);
188
+ setHeight(componentHeight);
189
+ }
190
+ }
191
+ const onResizeDebounced = debounce(onWindowResize, 100, { trailing: true });
192
+ window.addEventListener('resize', onResizeDebounced);
193
+ onWindowResize();
194
+ return () => {
195
+ window.removeEventListener('resize', onResizeDebounced);
196
+ };
197
+ }, [ref]);
198
+
199
+ return [width, height];
200
+ }
201
+
202
+ export function useExpressionValueGetter({ instanceObsIndex, matrixObsIndex, expressionData }) {
203
+ // Get a mapping from cell ID to row index in the gene expression matrix.
204
+ // Since the two obsIndices (instanceObsIndex = the obsIndex from obsEmbedding)
205
+ // may be ordered differently (matrixObsIndex = the obsIndex from obsFeatureMatrix),
206
+ // we need a way to look up an obsFeatureMatrix obsIndex index
207
+ // given an obsEmbedding obsIndex index.
208
+ const toMatrixIndexMap = useMemo(() => {
209
+ if (instanceObsIndex && matrixObsIndex) {
210
+ const matrixIndexMap = new Map(matrixObsIndex.map((key, i) => ([key, i])));
211
+ return instanceObsIndex.map(key => matrixIndexMap.get(key));
212
+ }
213
+ return null;
214
+ }, [instanceObsIndex, matrixObsIndex]);
215
+
216
+ // Set up a getter function for gene expression values, to be used
217
+ // by the DeckGL layer to obtain values for instanced attributes.
218
+ const getExpressionValue = useCallback((entry, { index: instanceIndex }) => {
219
+ if (toMatrixIndexMap && expressionData && expressionData[0]) {
220
+ const rowIndex = toMatrixIndexMap[instanceIndex];
221
+ const val = expressionData[0][rowIndex];
222
+ return val;
223
+ }
224
+ return 0;
225
+ }, [toMatrixIndexMap, expressionData]);
226
+ return getExpressionValue;
227
+ }
228
+
229
+ export function useGetObsInfo(obsType, obsLabelsTypes, obsLabelsData, obsSetsMembership) {
230
+ return useCallback((obsId) => {
231
+ if (obsId) {
232
+ const obsMembership = obsSetsMembership?.get(obsId) || [];
233
+ return {
234
+ [`${capitalize(obsType)} ID`]: obsId,
235
+ ...fromEntries(obsMembership.flatMap(path => path.slice(1).map((pathEl, elLevel) => ([
236
+ `${path[0]}${path.length > 2 ? ` L${elLevel + 1}` : ''}`,
237
+ pathEl,
238
+ ])))),
239
+ ...fromEntries(Object.entries(obsLabelsTypes).map(([scopeKey, obsLabelsType]) => ([
240
+ obsLabelsType,
241
+ obsLabelsData?.[scopeKey]?.obsLabels?.[
242
+ // TODO: Maybe all loaders that return obsIndex should also return an obsIndexMap
243
+ // with keys: obsId, values: obsIdx
244
+ // which would avoid the indexOf calls.
245
+ obsLabelsData?.[scopeKey]?.obsIndex?.indexOf(obsId)
246
+ ],
247
+ ])).filter(([obsLabelsType]) => Boolean(obsLabelsType))),
248
+ };
249
+ }
250
+ return null;
251
+ }, [obsType, obsLabelsTypes, obsLabelsData, obsSetsMembership]);
252
+ }
package/src/index.js ADDED
@@ -0,0 +1,101 @@
1
+ export { VitS } from './VitS';
2
+ export { TitleInfo } from './TitleInfo';
3
+ export { PopperMenu } from './shared-mui/components';
4
+ export {
5
+ registerPluginViewType,
6
+ registerPluginCoordinationType,
7
+ registerPluginFileType,
8
+ registerPluginJointFileType,
9
+ } from './plugins';
10
+ // For plugin view types:
11
+ export {
12
+ useReady, useUrls,
13
+ useVitessceContainer, useDeckCanvasSize,
14
+ useExpressionValueGetter, useGetObsInfo,
15
+ useClosestVitessceContainerSize, useWindowDimensions,
16
+ useGridItemSize,
17
+ } from './hooks';
18
+ export {
19
+ useCoordination,
20
+ useComplexCoordination,
21
+ useMultiCoordinationValues,
22
+ useMultiDatasetCoordination,
23
+ useDatasetUids,
24
+ useLoaders,
25
+ useMatchingLoader,
26
+ useViewConfigStore,
27
+ useViewConfigStoreApi,
28
+ useComponentHover,
29
+ useSetComponentHover,
30
+ useComponentViewInfo,
31
+ useSetComponentViewInfo,
32
+ useWarning,
33
+ useSetWarning,
34
+ useAuxiliaryCoordination,
35
+ useComponentLayout,
36
+ } from './state/hooks';
37
+ export {
38
+ useDescription,
39
+ useImageData,
40
+ useObsSetsData,
41
+ useObsEmbeddingData,
42
+ useFeatureSelection,
43
+ useObsFeatureMatrixIndices,
44
+ useMultiObsLabels,
45
+
46
+ useObsLocationsData,
47
+ useObsSegmentationsData,
48
+ useNeighborhoodsData,
49
+ useObsLabelsData,
50
+
51
+ useObsFeatureMatrixData,
52
+ useFeatureLabelsData,
53
+ useGenomicProfilesData,
54
+ } from './data-hooks';
55
+ export {
56
+ useHasLoader,
57
+ } from './data-hook-utils';
58
+ export {
59
+ AbstractLoader,
60
+ AbstractTwoStepLoader,
61
+ LoaderResult,
62
+ } from './data/index';
63
+ export {
64
+ AbstractLoaderError,
65
+ DatasetNotFoundError,
66
+ LoaderNotFoundError,
67
+ LoaderValidationError,
68
+ OptionsValidationError,
69
+ DataSourceFetchError,
70
+ } from './errors/index';
71
+ export {
72
+ // TODO(monorepo): should these be in here? or within file-types/
73
+ obsEmbeddingAnndataSchema,
74
+ obsLocationsAnndataSchema,
75
+ obsSegmentationsAnndataSchema,
76
+ obsSetsAnndataSchema,
77
+ obsFeatureMatrixAnndataSchema,
78
+ obsLabelsAnndataSchema,
79
+ featureLabelsAnndataSchema,
80
+ obsEmbeddingCsvSchema,
81
+ obsLocationsCsvSchema,
82
+ obsLabelsCsvSchema,
83
+ featureLabelsCsvSchema,
84
+ obsSetsCsvSchema,
85
+ anndataZarrSchema,
86
+ emptySchema,
87
+ } from './file-options-schemas';
88
+ export {
89
+ SCHEMA_HANDLERS,
90
+ LATEST_VERSION,
91
+ } from './view-config-versions';
92
+ export {
93
+ upgradeAndValidate,
94
+ } from './view-config-utils';
95
+ export {
96
+ CellColorEncodingOption,
97
+ OptionsContainer,
98
+ OptionSelect,
99
+ usePlotOptionsStyles,
100
+ } from './shared-plot-options';
101
+ export * from './json-schemas';
@@ -0,0 +1,298 @@
1
+ import { FileType } from '@vitessce/constants-internal';
2
+ import {
3
+ validateOptions,
4
+ emptySchema,
5
+ } from './file-options-schemas';
6
+ import {
7
+ cellsJsonSchema,
8
+ anndataCellsZarrSchema,
9
+ anndataCellSetsZarrSchema,
10
+ anndataExpressionMatrixZarrSchema,
11
+ } from './file-options-schemas-legacy';
12
+
13
+ export function expandMoleculesJson(fileDef) {
14
+ validateOptions(emptySchema, fileDef.options);
15
+ const baseFileDef = {
16
+ ...fileDef,
17
+ coordinationValues: {
18
+ obsType: fileDef.coordinationValues?.obsType || 'molecule',
19
+ },
20
+ };
21
+ delete baseFileDef.type;
22
+ return [
23
+ {
24
+ ...baseFileDef,
25
+ fileType: FileType.OBS_LOCATIONS_MOLECULES_JSON,
26
+ },
27
+ {
28
+ ...baseFileDef,
29
+ fileType: FileType.OBS_LABELS_MOLECULES_JSON,
30
+ },
31
+ ];
32
+ }
33
+
34
+ export function expandExpressionMatrixZarr(fileDef) {
35
+ validateOptions(emptySchema, fileDef.options);
36
+ const baseFileDef = {
37
+ ...fileDef,
38
+ coordinationValues: {
39
+ obsType: fileDef.coordinationValues?.obsType || 'cell',
40
+ featureType: fileDef.coordinationValues?.featureType || 'gene',
41
+ featureValueType: fileDef.coordinationValues?.featureValueType || 'expression',
42
+ },
43
+ };
44
+ delete baseFileDef.type;
45
+ return [
46
+ {
47
+ ...baseFileDef,
48
+ fileType: FileType.OBS_FEATURE_MATRIX_EXPRESSION_MATRIX_ZARR,
49
+ },
50
+ ];
51
+ }
52
+
53
+ export function expandRasterJson(fileDef) {
54
+ // Validation already happens in the RasterJsonLoader.
55
+ const baseFileDef = { ...fileDef };
56
+ delete baseFileDef.type;
57
+ return [
58
+ {
59
+ ...baseFileDef,
60
+ fileType: FileType.IMAGE_RASTER_JSON,
61
+ },
62
+ {
63
+ ...baseFileDef,
64
+ fileType: FileType.OBS_SEGMENTATIONS_RASTER_JSON,
65
+ coordinationValues: {
66
+ obsType: baseFileDef.coordinationValues?.obsType || 'cell',
67
+ },
68
+ },
69
+ ];
70
+ }
71
+
72
+ export function expandRasterOmeZarr(fileDef) {
73
+ validateOptions(emptySchema, fileDef.options);
74
+ const baseFileDef = { ...fileDef };
75
+ delete baseFileDef.type;
76
+ return [
77
+ {
78
+ ...baseFileDef,
79
+ fileType: FileType.IMAGE_OME_ZARR,
80
+ },
81
+ ];
82
+ }
83
+
84
+ export function expandCellSetsJson(fileDef) {
85
+ validateOptions(emptySchema, fileDef.options);
86
+ const baseFileDef = { ...fileDef };
87
+ delete baseFileDef.type;
88
+ return [
89
+ {
90
+ ...baseFileDef,
91
+ fileType: FileType.OBS_SETS_CELL_SETS_JSON,
92
+ coordinationValues: {
93
+ obsType: baseFileDef.coordinationValues?.obsType || 'cell',
94
+ },
95
+ },
96
+ ];
97
+ }
98
+
99
+ export function expandCellsJson(fileDef) {
100
+ validateOptions(cellsJsonSchema, fileDef.options);
101
+ const baseFileDef = {
102
+ ...fileDef,
103
+ coordinationValues: {
104
+ obsType: fileDef.coordinationValues?.obsType || 'cell',
105
+ featureType: fileDef.coordinationValues?.featureType || 'gene',
106
+ },
107
+ };
108
+ delete baseFileDef.type;
109
+ delete baseFileDef.options;
110
+ return [
111
+ {
112
+ ...baseFileDef,
113
+ fileType: FileType.OBS_SEGMENTATIONS_CELLS_JSON,
114
+ coordinationValues: {
115
+ obsType: baseFileDef.coordinationValues.obsType,
116
+ },
117
+ },
118
+ {
119
+ ...baseFileDef,
120
+ fileType: FileType.OBS_LOCATIONS_CELLS_JSON,
121
+ coordinationValues: {
122
+ obsType: baseFileDef.coordinationValues.obsType,
123
+ },
124
+ },
125
+ ...(fileDef.options?.embeddingTypes ? fileDef.options.embeddingTypes.map(et => ({
126
+ ...baseFileDef,
127
+ fileType: FileType.OBS_EMBEDDING_CELLS_JSON,
128
+ coordinationValues: {
129
+ obsType: baseFileDef.coordinationValues.obsType,
130
+ embeddingType: et,
131
+ },
132
+ })) : []),
133
+ ...(fileDef.options?.obsLabelsTypes ? fileDef.options.obsLabelsTypes.map(key => ({
134
+ ...baseFileDef,
135
+ fileType: FileType.OBS_LABELS_CELLS_JSON,
136
+ coordinationValues: {
137
+ obsType: baseFileDef.coordinationValues.obsType,
138
+ obsLabelsType: key,
139
+ },
140
+ })) : []),
141
+ ];
142
+ }
143
+
144
+ export function expandClustersJson(fileDef) {
145
+ validateOptions(emptySchema, fileDef.options);
146
+ const baseFileDef = {
147
+ ...fileDef,
148
+ coordinationValues: {
149
+ obsType: fileDef.coordinationValues?.obsType || 'cell',
150
+ featureType: fileDef.coordinationValues?.featureType || 'gene',
151
+ featureValueType: fileDef.coordinationValues?.featureValueType || 'expression',
152
+ },
153
+ };
154
+ delete baseFileDef.type;
155
+ return [
156
+ {
157
+ ...baseFileDef,
158
+ fileType: FileType.OBS_FEATURE_MATRIX_CLUSTERS_JSON,
159
+ },
160
+ ];
161
+ }
162
+
163
+ export function expandGenesJson(fileDef) {
164
+ validateOptions(emptySchema, fileDef.options);
165
+ const baseFileDef = {
166
+ ...fileDef,
167
+ coordinationValues: {
168
+ obsType: fileDef.coordinationValues?.obsType || 'cell',
169
+ featureType: fileDef.coordinationValues?.featureType || 'gene',
170
+ featureValueType: fileDef.coordinationValues?.featureValueType || 'expression',
171
+ },
172
+ };
173
+ delete baseFileDef.type;
174
+ return [
175
+ {
176
+ ...baseFileDef,
177
+ fileType: FileType.OBS_FEATURE_MATRIX_GENES_JSON,
178
+ },
179
+ ];
180
+ }
181
+
182
+ function getAnndataBaseFileDef(fileDef) {
183
+ return {
184
+ url: fileDef.url,
185
+ requestInit: fileDef.requestInit,
186
+ coordinationValues: {
187
+ ...fileDef.coordinationValues,
188
+ obsType: fileDef.coordinationValues?.obsType || 'cell',
189
+ featureType: fileDef.coordinationValues?.featureType || 'gene',
190
+ featureValueType: fileDef.coordinationValues?.featureValueType || 'expression',
191
+ },
192
+ };
193
+ }
194
+
195
+ export function expandAnndataCellsZarr(fileDef) {
196
+ validateOptions(anndataCellsZarrSchema, fileDef.options);
197
+ const baseFileDef = getAnndataBaseFileDef(fileDef);
198
+ const { options = {} } = fileDef;
199
+ const embeddingTypes = options.mappings ? Object.keys(options.mappings) : [];
200
+ const obsLabelsTypes = options.factors ? options.factors : [];
201
+ return [
202
+ ...(options.poly ? [{
203
+ ...baseFileDef,
204
+ fileType: FileType.OBS_SEGMENTATIONS_ANNDATA_ZARR,
205
+ options: {
206
+ path: options.poly,
207
+ },
208
+ coordinationValues: {
209
+ obsType: baseFileDef.coordinationValues.obsType,
210
+ },
211
+ }] : []),
212
+ ...(options.xy ? [{
213
+ ...baseFileDef,
214
+ fileType: FileType.OBS_LOCATIONS_ANNDATA_ZARR,
215
+ options: {
216
+ path: options.xy,
217
+ },
218
+ coordinationValues: {
219
+ obsType: baseFileDef.coordinationValues.obsType,
220
+ },
221
+ }] : []),
222
+ ...embeddingTypes.map(et => ({
223
+ ...baseFileDef,
224
+ fileType: FileType.OBS_EMBEDDING_ANNDATA_ZARR,
225
+ options: {
226
+ path: options.mappings[et].key,
227
+ dims: options.mappings[et].dims,
228
+ },
229
+ coordinationValues: {
230
+ obsType: baseFileDef.coordinationValues.obsType,
231
+ embeddingType: et,
232
+ },
233
+ })),
234
+ ...obsLabelsTypes.map(olt => ({
235
+ ...baseFileDef,
236
+ fileType: FileType.OBS_LABELS_ANNDATA_ZARR,
237
+ options: {
238
+ path: olt,
239
+ },
240
+ coordinationValues: {
241
+ obsType: baseFileDef.coordinationValues.obsType,
242
+ obsLabelsType: olt.split('/').at(-1),
243
+ },
244
+ })),
245
+ ];
246
+ }
247
+
248
+ export function expandAnndataCellSetsZarr(fileDef) {
249
+ validateOptions(anndataCellSetsZarrSchema, fileDef.options);
250
+ const baseFileDef = getAnndataBaseFileDef(fileDef);
251
+ const { options = [] } = fileDef;
252
+ return [
253
+ {
254
+ ...baseFileDef,
255
+ fileType: FileType.OBS_SETS_ANNDATA_ZARR,
256
+ options: options.map(option => ({
257
+ name: option.groupName,
258
+ path: option.setName,
259
+ scorePath: option.scoreName,
260
+ })),
261
+ coordinationValues: {
262
+ obsType: baseFileDef.coordinationValues.obsType,
263
+ },
264
+ },
265
+ ];
266
+ }
267
+
268
+ export function expandAnndataExpressionMatrixZarr(fileDef) {
269
+ validateOptions(anndataExpressionMatrixZarrSchema, fileDef.options);
270
+ const baseFileDef = getAnndataBaseFileDef(fileDef);
271
+ const { options = {} } = fileDef;
272
+ return [
273
+ ...(options.geneAlias ? [{
274
+ ...baseFileDef,
275
+ fileType: FileType.FEATURE_LABELS_ANNDATA_ZARR,
276
+ options: {
277
+ path: options.geneAlias,
278
+ },
279
+ coordinationValues: {
280
+ featureType: baseFileDef.coordinationValues.featureType,
281
+ },
282
+ }] : []),
283
+ {
284
+ ...baseFileDef,
285
+ fileType: FileType.OBS_FEATURE_MATRIX_ANNDATA_ZARR,
286
+ options: {
287
+ path: options.matrix,
288
+ featureFilterPath: options.geneFilter,
289
+ initialFeatureFilterPath: options.matrixGeneFilter,
290
+ },
291
+ coordinationValues: {
292
+ obsType: baseFileDef.coordinationValues.obsType,
293
+ featureType: baseFileDef.coordinationValues.featureType,
294
+ featureValueType: baseFileDef.coordinationValues.featureValueType,
295
+ },
296
+ },
297
+ ];
298
+ }