@vitessce/comparative 0.0.1 → 3.9.4

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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -18
  3. package/dist/OrbitControls-DWelGoKt.js +6202 -0
  4. package/dist/ReactNeuroglancer-BXqSFHUD.js +43478 -0
  5. package/dist/blosc-DKW2fp0s.js +716 -0
  6. package/dist/chunk-INHXZS53-DiyuLb3Z.js +14 -0
  7. package/dist/deflate-DYtYzuI-.js +10 -0
  8. package/dist/higlass-BBW7WDEo.js +92988 -0
  9. package/dist/index-CMozjas4.js +6178 -0
  10. package/dist/index-Ce5JOk5t.js +283191 -0
  11. package/dist/index-Dmp8XDxB.js +3100 -0
  12. package/dist/index.min.js +43 -0
  13. package/dist/jpeg-BCnMyPcM.js +533 -0
  14. package/dist/lerc-IcvUBGkp.js +1032 -0
  15. package/dist/lz4-D5NbssRf.js +640 -0
  16. package/dist/lzw-BuqKQps7.js +84 -0
  17. package/dist/packbits-D-hnPOOn.js +24 -0
  18. package/dist/pako.esm-D68R8YXe.js +1071 -0
  19. package/dist/raw-CjTblrBX.js +9 -0
  20. package/dist/troika-three-text.esm-DZiaLX4L.js +4192 -0
  21. package/dist/webimage-CAVBEZTP.js +19 -0
  22. package/dist/zstd-DoGJTjDa.js +603 -0
  23. package/dist-tsc/BiomarkerSelect.d.ts +2 -0
  24. package/dist-tsc/BiomarkerSelect.d.ts.map +1 -0
  25. package/dist-tsc/BiomarkerSelect.js +65 -0
  26. package/dist-tsc/ComparativeConfig.d.ts +12 -0
  27. package/dist-tsc/ComparativeConfig.d.ts.map +1 -0
  28. package/dist-tsc/ComparativeConfig.js +326 -0
  29. package/dist-tsc/ControlledComparative.d.ts +30 -0
  30. package/dist-tsc/ControlledComparative.d.ts.map +1 -0
  31. package/dist-tsc/ControlledComparative.js +95 -0
  32. package/dist-tsc/UncontrolledComparative.d.ts +10 -0
  33. package/dist-tsc/UncontrolledComparative.d.ts.map +1 -0
  34. package/dist-tsc/UncontrolledComparative.js +50 -0
  35. package/dist-tsc/index.d.ts +7 -0
  36. package/dist-tsc/index.d.ts.map +1 -0
  37. package/dist-tsc/index.js +14 -0
  38. package/package.json +53 -16
  39. package/src/BiomarkerSelect.jsx +107 -0
  40. package/src/ComparativeConfig.jsx +562 -0
  41. package/src/ControlledComparative.jsx +140 -0
  42. package/src/UncontrolledComparative.jsx +88 -0
  43. package/src/index.js +18 -0
  44. package/dist/index.d.ts +0 -4
  45. package/dist/index.js +0 -9
@@ -0,0 +1,140 @@
1
+ /* eslint-disable max-len */
2
+ /* eslint-disable no-underscore-dangle */
3
+ import React, { useMemo, useState, useCallback } from 'react';
4
+ import { Vitessce } from '@vitessce/all';
5
+ import { isEqual } from 'lodash-es';
6
+ import { ComparativePageComponent, generateComparativeConfig } from './ComparativeConfig.jsx';
7
+
8
+ /**
9
+ * A controlled component for comparative visualization that synchronizes
10
+ * gene selection and sample set selection state with its parent.
11
+ * @param {object} props
12
+ * @param {string} props.datasetUrl - URL to the comparative AnnData-Zarr
13
+ * store.
14
+ * @param {string[]} props.geneSelection - Array of selected gene names.
15
+ * @param {Function} props.setGeneSelection - Setter function
16
+ * called when the gene selection has been updated from inside.
17
+ * @param {string[][]} props.sampleSetSelection - Array of sample set
18
+ * selections, where each element is an array of sample identifiers,
19
+ * like [["Enrollment Category", "CKD"], ["Enrollment Category", "AKI"]].
20
+ * @param {Function} props.setSampleSetSelection - Setter function
21
+ * called when the sample set selection has been updated from inside.
22
+ * @param {string} [props.theme='light2'] - Theme name.
23
+ * @param {boolean} [props.debugMode=false] - Enable debug mode.
24
+ * @param {string} props.logLevel - Log level.
25
+ * @returns {React.ReactElement} The comparative visualization component.
26
+ */
27
+ export function ControlledComparative(props) {
28
+ const {
29
+ datasetUrl = 'https://data-2.vitessce.io/kpmp-atlas-v2/sn-rna-seq/processed/kpmp-aug-2025.adata.zarr',
30
+ geneSelection,
31
+ setGeneSelection,
32
+ sampleSetSelection,
33
+ setSampleSetSelection,
34
+ theme = 'light2',
35
+ debugMode = false,
36
+ logLevel = undefined,
37
+ } = props;
38
+
39
+ const initialConfig = useMemo(() => generateComparativeConfig(datasetUrl, false), [datasetUrl]);
40
+ const [currentConfig, setCurrentConfig] = useState(null);
41
+ // Merge currentConfig with geneSelection and sampleSetSelection,
42
+ // which may have been updated from outside Vitessce (e.g., from URL params).
43
+ const mergedConfig = useMemo(() => {
44
+ if (!currentConfig) {
45
+ return initialConfig;
46
+ }
47
+ // Merge currentConfig with geneSelection and sampleSetSelection.
48
+ const isValidGeneSelection = Array.isArray(geneSelection) && geneSelection.every(g => typeof g === 'string');
49
+ const isValidSampleSetSelection = Array.isArray(sampleSetSelection) && sampleSetSelection.every(s => Array.isArray(s) && s.every(t => typeof t === 'string'));
50
+
51
+ // Check if geneSelection or sampleSetSelection have changed before specifying a different config.uid value.
52
+ const prevGeneSelection = currentConfig.coordinationSpace?.featureSelection?.__comparison__;
53
+ const prevSampleSetSelection = currentConfig.coordinationSpace?.sampleSetSelection?.__comparison__;
54
+ if (isEqual(prevGeneSelection, geneSelection)
55
+ && isEqual(prevSampleSetSelection, sampleSetSelection)
56
+ ) {
57
+ return currentConfig;
58
+ }
59
+
60
+ const newConfig = {
61
+ ...currentConfig,
62
+ // Note: this forces Vitessce to re-initialize the coordination space for featureSelection and sampleSetSelection,
63
+ // but it also causes the data to be re-loaded.
64
+ uid: `controlled-comparative-${Date.now()}`,
65
+ coordinationSpace: {
66
+ ...currentConfig.coordinationSpace,
67
+ featureSelection: {
68
+ ...currentConfig.coordinationSpace?.featureSelection,
69
+ __comparison__: (isValidGeneSelection
70
+ ? geneSelection
71
+ : currentConfig.coordinationSpace?.featureSelection?.__comparison__
72
+ ),
73
+ },
74
+ sampleSetSelection: {
75
+ ...currentConfig.coordinationSpace?.sampleSetSelection,
76
+ __comparison__: (
77
+ isValidSampleSetSelection
78
+ ? sampleSetSelection
79
+ : currentConfig.coordinationSpace?.sampleSetSelection?.__comparison__
80
+ ),
81
+ },
82
+ },
83
+ };
84
+
85
+ // console.log(geneSelection, isValidGeneSelection, newConfig);
86
+ return newConfig;
87
+ }, [initialConfig, currentConfig, geneSelection, sampleSetSelection]);
88
+
89
+
90
+ const onConfigChange = useCallback((newConfig) => {
91
+ // Listen for changes to the config from inside vITESSCE
92
+ setCurrentConfig(newConfig);
93
+
94
+ // Listen for changes to featureSelection and sampleSetSelection in the coordination space.
95
+ const newFeatureSelection = newConfig.coordinationSpace?.featureSelection?.__comparison__;
96
+ const newSampleSetSelection = newConfig.coordinationSpace?.sampleSetSelection?.__comparison__;
97
+
98
+ // Was there a new selection made from inside Vitessce?
99
+ // Note: this will prevent from CLEARING the selections from inside Vitessce
100
+ // (any clearing will need to be done from the BiomarkerSelect UI).
101
+ const hasNewGeneSelection = (
102
+ Array.isArray(newFeatureSelection)
103
+ && newFeatureSelection.length > 0
104
+ && !isEqual(newFeatureSelection, geneSelection)
105
+ );
106
+ const hasNewSampleSetSelection = (
107
+ Array.isArray(newSampleSetSelection)
108
+ && newSampleSetSelection.length > 0
109
+ && !isEqual(newSampleSetSelection, sampleSetSelection)
110
+ );
111
+
112
+ if (hasNewGeneSelection) {
113
+ setGeneSelection(newFeatureSelection);
114
+ }
115
+ if (hasNewSampleSetSelection) {
116
+ setSampleSetSelection(newSampleSetSelection);
117
+ }
118
+ }, [geneSelection, sampleSetSelection]);
119
+
120
+ const didFirstValidation = currentConfig !== null;
121
+
122
+ return (
123
+ <div>
124
+ <Vitessce
125
+ config={mergedConfig}
126
+ onConfigChange={onConfigChange}
127
+ remountOnUidChange={false}
128
+ validateConfig={!didFirstValidation}
129
+ validateOnConfigChange={false}
130
+ rowHeight={null}
131
+ theme={theme}
132
+ pageMode
133
+ debugMode={debugMode}
134
+ logLevel={logLevel}
135
+ >
136
+ <ComparativePageComponent />
137
+ </Vitessce>
138
+ </div>
139
+ );
140
+ }
@@ -0,0 +1,88 @@
1
+ /* eslint-disable max-len */
2
+ /* eslint-disable react-refresh/only-export-components */
3
+ import React, { useState } from 'react';
4
+ // eslint-disable-next-line import/no-unresolved
5
+ import { NuqsAdapter } from 'nuqs/adapters/react';
6
+ import { useQueryState, parseAsString, parseAsArrayOf } from 'nuqs';
7
+ import { ControlledComparative } from './ControlledComparative.jsx';
8
+ import { BiomarkerSelect } from './BiomarkerSelect.jsx';
9
+
10
+ /**
11
+ * The UncontrolledComparative component is a wrapper
12
+ * around the ControlledComparative and BiomarkerSelect components.
13
+ * @param {object} props
14
+ * @param {string} props.datasetUrl URL of the dataset to load,
15
+ * which should point to the root of an anndata-zarr store,
16
+ * containing comparative metadata.
17
+ * @param {boolean} props.enableQueryParams Whether to
18
+ * sync state to the URL query parameters for gene and
19
+ * sample set selection. By default, true.
20
+ * @returns {JSX.Element}
21
+ */
22
+ function UncontrolledComparativeInner(props) {
23
+ const {
24
+ datasetUrl,
25
+ enableQueryParams = true,
26
+ } = props;
27
+
28
+ const [geneSelectionViaUrl, setGeneSelectionViaUrl] = useQueryState(
29
+ 'gene',
30
+ parseAsArrayOf(parseAsString),
31
+ );
32
+ const [sampleSetSelectionViaUrl, setSampleSetSelectionViaUrl] = useQueryState(
33
+ 'groups',
34
+ parseAsArrayOf(parseAsArrayOf(parseAsString)),
35
+ );
36
+
37
+ const [geneSelectionNonUrl, setGeneSelectionNonUrl] = useState([]);
38
+ const [sampleSetSelectionNonUrl, setSampleSetSelectionNonUrl] = useState([]);
39
+
40
+ // Depending on the value of enableQueryParams,
41
+ // we either use the state that is synced to the URL query parameters,
42
+ // or we use local state that is not synced to the URL.
43
+ const geneSelection = enableQueryParams ? geneSelectionViaUrl : geneSelectionNonUrl;
44
+ const setGeneSelection = enableQueryParams ? setGeneSelectionViaUrl : setGeneSelectionNonUrl;
45
+ const sampleSetSelection = enableQueryParams ? sampleSetSelectionViaUrl : sampleSetSelectionNonUrl;
46
+ const setSampleSetSelection = enableQueryParams ? setSampleSetSelectionViaUrl : setSampleSetSelectionNonUrl;
47
+
48
+ if (Array.isArray(sampleSetSelection) && sampleSetSelection.length > 2) {
49
+ throw new Error('groups query param array can have at most two entries.');
50
+ }
51
+
52
+ return (
53
+ <div>
54
+ <BiomarkerSelect
55
+ datasetUrl={datasetUrl}
56
+ geneSelection={geneSelection}
57
+ setGeneSelection={setGeneSelection}
58
+ sampleSetSelection={sampleSetSelection}
59
+ setSampleSetSelection={setSampleSetSelection}
60
+ />
61
+ <ControlledComparative
62
+ datasetUrl={datasetUrl}
63
+ geneSelection={geneSelection}
64
+ setGeneSelection={setGeneSelection}
65
+ sampleSetSelection={sampleSetSelection}
66
+ setSampleSetSelection={setSampleSetSelection}
67
+ />
68
+ </div>
69
+ );
70
+ }
71
+
72
+ /**
73
+ * The UncontrolledComparative component is a Provider component
74
+ * that wraps the UncontrolledComparativeInner component.
75
+ * See the UncontrolledComparativeInner component documentation
76
+ * for details on the props (all props are simply passed through).
77
+ * @param {*} props
78
+ * @returns
79
+ */
80
+ export function UncontrolledComparative(props) {
81
+ return (
82
+ <NuqsAdapter>
83
+ <UncontrolledComparativeInner
84
+ {...props}
85
+ />
86
+ </NuqsAdapter>
87
+ );
88
+ }
package/src/index.js ADDED
@@ -0,0 +1,18 @@
1
+ // Copied from packages/main/prod/src/index.js
2
+ // @ts-check
3
+ // eslint-disable-next-line react-refresh/only-export-components
4
+ export * from '@vitessce/constants';
5
+ // eslint-disable-next-line react-refresh/only-export-components
6
+ export * from '@vitessce/config';
7
+ // eslint-disable-next-line react-refresh/only-export-components
8
+ export * from '@vitessce/all';
9
+ export {
10
+ encodeConfInUrl,
11
+ decodeURLParamsToConf,
12
+ } from '@vitessce/export-utils';
13
+
14
+ // Comparative-specific exports below
15
+ // eslint-disable-next-line react-refresh/only-export-components
16
+ export * from './ControlledComparative.jsx';
17
+ // eslint-disable-next-line react-refresh/only-export-components
18
+ export * from './UncontrolledComparative.jsx';
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * Hello world function.
3
- */
4
- export declare function hello(): string;
package/dist/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hello = hello;
4
- /**
5
- * Hello world function.
6
- */
7
- function hello() {
8
- return "Hello world!";
9
- }