@vitessce/comparative 4.1.2 → 4.2.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 (55) hide show
  1. package/dist/{GeometryAndMeshXR-CMf0dkQy.js → GeometryAndMeshXR-CYO2tqUV.js} +1 -1
  2. package/dist/ReactNeuroglancer-pk3hhe45.js +68657 -0
  3. package/dist/{XREnterButton-DpxW774d.js → XREnterButton-BdEVWrV7.js} +1 -1
  4. package/dist/{XRSceneComponents-C-VbCXlG.js → XRSceneComponents-DYeS3CwE.js} +1 -1
  5. package/dist/{XRWrapper-CoSbWhS_.js → XRWrapper-DbheKuSQ.js} +2 -2
  6. package/dist/{deflate-SFB4ekzB.js → deflate-D76idIbp.js} +1 -1
  7. package/dist/{higlass-D5qxYkfx.js → higlass-HE5ijNPv.js} +1 -1
  8. package/dist/{index-Dhz9cE6Y.js → index-CSfNzXQa.js} +126748 -124747
  9. package/dist/index-DOITJzp5.js +30089 -0
  10. package/dist/{index-iUzEaM0X.js → index-DeGz6Kci.js} +1 -1
  11. package/dist/{index-CPs7SJQa.js → index-YJLqH5aL.js} +4 -4
  12. package/dist/index.min.js +20 -20
  13. package/dist/{jpeg-X9rWVd_G.js → jpeg-CtV9axAi.js} +1 -1
  14. package/dist/{lerc-C1sD5A4o.js → lerc-C2iyBV3P.js} +1 -1
  15. package/dist/{lzw-8I9_xt6F.js → lzw-BDK3wuTu.js} +1 -1
  16. package/dist/{packbits-C2cIjHBj.js → packbits-BmhmFJpE.js} +1 -1
  17. package/dist/{raw-D7AJ-PIv.js → raw-AV6N1HZT.js} +1 -1
  18. package/dist/{webimage-DmbCXIUf.js → webimage-D8fd9G2X.js} +1 -1
  19. package/dist/{xrStore-CHRZYO3f.js → xrStore-B_SjnbWm.js} +1 -1
  20. package/dist-tsc/BiomarkerSelect.d.ts +19 -1
  21. package/dist-tsc/BiomarkerSelect.d.ts.map +1 -1
  22. package/dist-tsc/BiomarkerSelect.js +46 -39
  23. package/dist-tsc/BiomarkerSelect.js.map +1 -1
  24. package/dist-tsc/ComparativeConfig.d.ts +112 -3
  25. package/dist-tsc/ComparativeConfig.d.ts.map +1 -1
  26. package/dist-tsc/ComparativeConfig.js +255 -13
  27. package/dist-tsc/ComparativeConfig.js.map +1 -1
  28. package/dist-tsc/ComparativeConfig.test.d.ts +2 -0
  29. package/dist-tsc/ComparativeConfig.test.d.ts.map +1 -0
  30. package/dist-tsc/ComparativeConfig.test.js +119 -0
  31. package/dist-tsc/ComparativeConfig.test.js.map +1 -0
  32. package/dist-tsc/ControlledComparative.d.ts +13 -3
  33. package/dist-tsc/ControlledComparative.d.ts.map +1 -1
  34. package/dist-tsc/ControlledComparative.js +32 -14
  35. package/dist-tsc/ControlledComparative.js.map +1 -1
  36. package/dist-tsc/UncontrolledComparative.d.ts.map +1 -1
  37. package/dist-tsc/UncontrolledComparative.js +39 -12
  38. package/dist-tsc/UncontrolledComparative.js.map +1 -1
  39. package/dist-tsc/url-params.d.ts +24 -0
  40. package/dist-tsc/url-params.d.ts.map +1 -0
  41. package/dist-tsc/url-params.js +32 -0
  42. package/dist-tsc/url-params.js.map +1 -0
  43. package/dist-tsc/url-params.test.d.ts +2 -0
  44. package/dist-tsc/url-params.test.d.ts.map +1 -0
  45. package/dist-tsc/url-params.test.js +18 -0
  46. package/dist-tsc/url-params.test.js.map +1 -0
  47. package/package.json +15 -13
  48. package/src/BiomarkerSelect.jsx +70 -45
  49. package/src/ComparativeConfig.jsx +295 -13
  50. package/src/ComparativeConfig.test.jsx +151 -0
  51. package/src/ControlledComparative.jsx +47 -13
  52. package/src/UncontrolledComparative.jsx +62 -16
  53. package/src/url-params.js +34 -0
  54. package/src/url-params.test.js +20 -0
  55. package/dist/ReactNeuroglancer-DzBGJFIe.js +0 -43644
@@ -1,49 +1,87 @@
1
1
  /* eslint-disable max-len */
2
2
  /* eslint-disable react-refresh/only-export-components */
3
- import React, { useState } from 'react';
3
+ import React, { useState, useCallback } from 'react';
4
4
  // eslint-disable-next-line import/no-unresolved
5
5
  import { NuqsAdapter } from 'nuqs/adapters/react';
6
- import { useQueryState, parseAsString, parseAsArrayOf } from 'nuqs';
6
+ import {
7
+ useQueryState, parseAsString, parseAsArrayOf, parseAsStringLiteral,
8
+ } from 'nuqs';
7
9
  import { ControlledComparative } from './ControlledComparative.jsx';
8
10
  import { BiomarkerSelect } from './BiomarkerSelect.jsx';
11
+ import { COMPARATIVE_MODALITIES } from './ComparativeConfig.jsx';
12
+ import { parseAsBiomarker } from './url-params.js';
13
+
14
+ const MODALITY_UIDS = COMPARATIVE_MODALITIES.map(m => m.uid);
9
15
 
10
16
  /**
11
17
  * The UncontrolledComparative component is a wrapper
12
18
  * around the ControlledComparative and BiomarkerSelect components.
13
19
  * @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,
20
+ * At least one of singleCellDatasetUrl or singleNucleusDatasetUrl must be provided.
21
+ * When both are provided, the user can switch between modalities.
22
+ * @param {string} [props.singleCellDatasetUrl] URL of the single-cell
23
+ * dataset to load, which should point to the root of an anndata-zarr store,
24
+ * containing comparative metadata.
25
+ * @param {string} [props.singleNucleusDatasetUrl] URL of the single-nucleus
26
+ * dataset to load, which should point to the root of an anndata-zarr store,
16
27
  * containing comparative metadata.
17
28
  * @param {boolean} props.enableQueryParams Whether to
18
- * sync state to the URL query parameters for gene and
19
- * sample set selection. By default, true.
29
+ * sync state to the URL query parameters for feature (e.g., gene or pathway),
30
+ * sample set, and modality selection. By default, true.
31
+ * The `feature` URL param is formatted like `nodeType:label`,
32
+ * e.g., `?feature=gene:UMOD` or `?feature=pathway:Cell Cycle R-HSA-1640170`.
20
33
  * @returns {JSX.Element}
21
34
  */
22
35
  function UncontrolledComparativeInner(props) {
23
36
  const {
24
- datasetUrl,
37
+ singleCellDatasetUrl,
38
+ singleNucleusDatasetUrl,
25
39
  enableQueryParams = true,
26
40
  } = props;
27
41
 
28
- const [geneSelectionViaUrl, setGeneSelectionViaUrl] = useQueryState(
29
- 'gene',
30
- parseAsArrayOf(parseAsString),
42
+ const [biomarkerSelectionViaUrl, setBiomarkerSelectionViaUrl] = useQueryState(
43
+ 'feature',
44
+ parseAsBiomarker,
31
45
  );
32
46
  const [sampleSetSelectionViaUrl, setSampleSetSelectionViaUrl] = useQueryState(
33
47
  'groups',
34
48
  parseAsArrayOf(parseAsArrayOf(parseAsString)),
35
49
  );
50
+ const [modalitySelectionViaUrl, setModalitySelectionViaUrl] = useQueryState(
51
+ 'modality',
52
+ parseAsStringLiteral(MODALITY_UIDS),
53
+ );
36
54
 
37
- const [geneSelectionNonUrl, setGeneSelectionNonUrl] = useState([]);
55
+ const [biomarkerSelectionNonUrl, setBiomarkerSelectionNonUrl] = useState(null);
38
56
  const [sampleSetSelectionNonUrl, setSampleSetSelectionNonUrl] = useState([]);
57
+ const [modalitySelectionNonUrl, setModalitySelectionNonUrl] = useState(null);
39
58
 
40
59
  // Depending on the value of enableQueryParams,
41
60
  // we either use the state that is synced to the URL query parameters,
42
61
  // or we use local state that is not synced to the URL.
43
- const geneSelection = enableQueryParams ? geneSelectionViaUrl : geneSelectionNonUrl;
44
- const setGeneSelection = enableQueryParams ? setGeneSelectionViaUrl : setGeneSelectionNonUrl;
62
+ const biomarkerSelection = enableQueryParams ? biomarkerSelectionViaUrl : biomarkerSelectionNonUrl;
63
+ const setBiomarkerSelection = enableQueryParams ? setBiomarkerSelectionViaUrl : setBiomarkerSelectionNonUrl;
45
64
  const sampleSetSelection = enableQueryParams ? sampleSetSelectionViaUrl : sampleSetSelectionNonUrl;
46
65
  const setSampleSetSelection = enableQueryParams ? setSampleSetSelectionViaUrl : setSampleSetSelectionNonUrl;
66
+ const selectedModality = enableQueryParams ? modalitySelectionViaUrl : modalitySelectionNonUrl;
67
+ const setSelectedModality = enableQueryParams ? setModalitySelectionViaUrl : setModalitySelectionNonUrl;
68
+
69
+ // The gene selection is not synced to the URL, since it is derived
70
+ // from the biomarker selection (e.g., the member genes of a selected pathway)
71
+ // by the biomarkerSelectAlt view.
72
+ const [geneSelection, setGeneSelection] = useState(null);
73
+
74
+ // When genes are selected from inside the comparative views
75
+ // (e.g., by clicking a point in the volcano plot), update the biomarker selection accordingly.
76
+ const setGeneSelectionFromComparative = useCallback((newGeneSelection) => {
77
+ setGeneSelection(newGeneSelection);
78
+ setBiomarkerSelection(
79
+ Array.isArray(newGeneSelection) && newGeneSelection.length === 1
80
+ ? { label: newGeneSelection[0], nodeType: 'gene' }
81
+ // Multiple genes cannot be represented by a single biomarker selection.
82
+ : null,
83
+ );
84
+ }, [setBiomarkerSelection]);
47
85
 
48
86
  if (Array.isArray(sampleSetSelection) && sampleSetSelection.length > 2) {
49
87
  throw new Error('groups query param array can have at most two entries.');
@@ -52,16 +90,24 @@ function UncontrolledComparativeInner(props) {
52
90
  return (
53
91
  <div>
54
92
  <BiomarkerSelect
55
- datasetUrl={datasetUrl}
93
+ singleCellDatasetUrl={singleCellDatasetUrl}
94
+ singleNucleusDatasetUrl={singleNucleusDatasetUrl}
95
+ selectedModality={selectedModality}
96
+ setSelectedModality={setSelectedModality}
97
+ biomarkerSelection={biomarkerSelection}
98
+ setBiomarkerSelection={setBiomarkerSelection}
56
99
  geneSelection={geneSelection}
57
100
  setGeneSelection={setGeneSelection}
58
101
  sampleSetSelection={sampleSetSelection}
59
102
  setSampleSetSelection={setSampleSetSelection}
60
103
  />
61
104
  <ControlledComparative
62
- datasetUrl={datasetUrl}
105
+ singleCellDatasetUrl={singleCellDatasetUrl}
106
+ singleNucleusDatasetUrl={singleNucleusDatasetUrl}
107
+ selectedModality={selectedModality}
108
+ setSelectedModality={setSelectedModality}
63
109
  geneSelection={geneSelection}
64
- setGeneSelection={setGeneSelection}
110
+ setGeneSelection={setGeneSelectionFromComparative}
65
111
  sampleSetSelection={sampleSetSelection}
66
112
  setSampleSetSelection={setSampleSetSelection}
67
113
  />
@@ -0,0 +1,34 @@
1
+ import { createParser } from 'nuqs';
2
+
3
+ /**
4
+ * Parse the value of the `feature` URL param,
5
+ * formatted like `nodeType:label` (e.g., `gene:UMOD` or `pathway:Cell Cycle R-HSA-1640170`).
6
+ * @param {string} value
7
+ * @returns {{ label: string, nodeType: string } | null}
8
+ */
9
+ export function parseBiomarkerParam(value) {
10
+ // Split at the first colon, since the label may contain colons.
11
+ const separatorIndex = value.indexOf(':');
12
+ if (separatorIndex <= 0 || separatorIndex === value.length - 1) {
13
+ return null;
14
+ }
15
+ return {
16
+ nodeType: value.slice(0, separatorIndex),
17
+ label: value.slice(separatorIndex + 1),
18
+ };
19
+ }
20
+
21
+ /**
22
+ * Serialize a biomarker selection to the `feature` URL param format.
23
+ * @param {{ label: string, nodeType: string }} value
24
+ * @returns {string}
25
+ */
26
+ export function serializeBiomarkerParam(value) {
27
+ return `${value.nodeType}:${value.label}`;
28
+ }
29
+
30
+ export const parseAsBiomarker = createParser({
31
+ parse: parseBiomarkerParam,
32
+ serialize: serializeBiomarkerParam,
33
+ eq: (a, b) => a.label === b.label && a.nodeType === b.nodeType,
34
+ });
@@ -0,0 +1,20 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { parseBiomarkerParam, serializeBiomarkerParam } from './url-params.js';
3
+
4
+ describe('feature URL param', () => {
5
+ it('parses and serializes genes and pathways', () => {
6
+ expect(parseBiomarkerParam('gene:UMOD')).toEqual({ nodeType: 'gene', label: 'UMOD' });
7
+ const pathway = { nodeType: 'pathway', label: 'Cell Cycle R-HSA-1640170' };
8
+ expect(parseBiomarkerParam(serializeBiomarkerParam(pathway))).toEqual(pathway);
9
+ });
10
+
11
+ it('splits at the first colon, since labels may contain colons', () => {
12
+ expect(parseBiomarkerParam('pathway:A: B')).toEqual({ nodeType: 'pathway', label: 'A: B' });
13
+ });
14
+
15
+ it('returns null for malformed values', () => {
16
+ expect(parseBiomarkerParam('UMOD')).toBeNull();
17
+ expect(parseBiomarkerParam(':UMOD')).toBeNull();
18
+ expect(parseBiomarkerParam('gene:')).toBeNull();
19
+ });
20
+ });