@vitessce/biomarker-select 4.1.3 → 4.2.1

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 (38) hide show
  1. package/dist/index.js +237 -73
  2. package/dist-tsc/BiomarkerSelectAlt.d.ts.map +1 -1
  3. package/dist-tsc/BiomarkerSelectAlt.js +11 -3
  4. package/dist-tsc/BiomarkerSelectAlt.js.map +1 -1
  5. package/dist-tsc/BiomarkerSelectAlt.test.js +26 -14
  6. package/dist-tsc/BiomarkerSelectAlt.test.js.map +1 -1
  7. package/dist-tsc/BiomarkerSelectAltDatasetSelect.d.ts +18 -0
  8. package/dist-tsc/BiomarkerSelectAltDatasetSelect.d.ts.map +1 -0
  9. package/dist-tsc/BiomarkerSelectAltDatasetSelect.js +23 -0
  10. package/dist-tsc/BiomarkerSelectAltDatasetSelect.js.map +1 -0
  11. package/dist-tsc/BiomarkerSelectAltDatasetSelect.test.d.ts +2 -0
  12. package/dist-tsc/BiomarkerSelectAltDatasetSelect.test.d.ts.map +1 -0
  13. package/dist-tsc/BiomarkerSelectAltDatasetSelect.test.js +25 -0
  14. package/dist-tsc/BiomarkerSelectAltDatasetSelect.test.js.map +1 -0
  15. package/dist-tsc/BiomarkerSelectAltGeneAutocomplete.d.ts +26 -1
  16. package/dist-tsc/BiomarkerSelectAltGeneAutocomplete.d.ts.map +1 -1
  17. package/dist-tsc/BiomarkerSelectAltGeneAutocomplete.js +60 -22
  18. package/dist-tsc/BiomarkerSelectAltGeneAutocomplete.js.map +1 -1
  19. package/dist-tsc/BiomarkerSelectAltSampleGroups.d.ts.map +1 -1
  20. package/dist-tsc/BiomarkerSelectAltSampleGroups.js +14 -7
  21. package/dist-tsc/BiomarkerSelectAltSampleGroups.js.map +1 -1
  22. package/dist-tsc/BiomarkerSelectAltSampleGroups.test.d.ts +2 -0
  23. package/dist-tsc/BiomarkerSelectAltSampleGroups.test.d.ts.map +1 -0
  24. package/dist-tsc/BiomarkerSelectAltSampleGroups.test.js +81 -0
  25. package/dist-tsc/BiomarkerSelectAltSampleGroups.test.js.map +1 -0
  26. package/dist-tsc/BiomarkerSelectAltSubscriber.d.ts +9 -6
  27. package/dist-tsc/BiomarkerSelectAltSubscriber.d.ts.map +1 -1
  28. package/dist-tsc/BiomarkerSelectAltSubscriber.js +50 -45
  29. package/dist-tsc/BiomarkerSelectAltSubscriber.js.map +1 -1
  30. package/package.json +5 -5
  31. package/src/BiomarkerSelectAlt.js +34 -8
  32. package/src/BiomarkerSelectAlt.test.jsx +56 -20
  33. package/src/BiomarkerSelectAltDatasetSelect.js +48 -0
  34. package/src/BiomarkerSelectAltDatasetSelect.test.jsx +39 -0
  35. package/src/BiomarkerSelectAltGeneAutocomplete.js +73 -36
  36. package/src/BiomarkerSelectAltSampleGroups.js +17 -10
  37. package/src/BiomarkerSelectAltSampleGroups.test.jsx +98 -0
  38. package/src/BiomarkerSelectAltSubscriber.js +62 -53
@@ -0,0 +1,98 @@
1
+ import React from 'react';
2
+ import { describe, it, expect, vi } from 'vitest';
3
+ import { fireEvent, render, screen } from '@testing-library/react';
4
+ import { BiomarkerSelectAltSampleGroups } from './BiomarkerSelectAltSampleGroups.js';
5
+
6
+ vi.mock('@vitessce/styles', () => ({
7
+ Grid: ({ children }) => <div>{children}</div>,
8
+ NativeSelect: ({ children, value, onChange }) => (
9
+ <select value={value} onChange={onChange}>{children}</select>
10
+ ),
11
+ }));
12
+
13
+ const stratifications = [
14
+ {
15
+ stratificationId: 'ec_hr-vs-aki',
16
+ name: 'Enrollment Category: Healthy Reference vs. AKI',
17
+ stratificationType: 'sampleSet',
18
+ sampleSets: [
19
+ ['Enrollment Category', 'Healthy Reference'],
20
+ ['Enrollment Category', 'AKI'],
21
+ ],
22
+ },
23
+ {
24
+ stratificationId: 'ec_hr-vs-ckd',
25
+ name: 'Enrollment Category: Healthy Reference vs. CKD',
26
+ stratificationType: 'sampleSet',
27
+ sampleSets: [
28
+ ['Enrollment Category', 'Healthy Reference'],
29
+ ['Enrollment Category', 'CKD'],
30
+ ],
31
+ },
32
+ ];
33
+
34
+ function renderSampleGroups(sampleSetSelection) {
35
+ const setSampleSetFilter = vi.fn();
36
+ const setSampleSetSelection = vi.fn();
37
+ render(
38
+ <BiomarkerSelectAltSampleGroups
39
+ setSampleSetFilter={setSampleSetFilter}
40
+ setSampleSetSelection={setSampleSetSelection}
41
+ sampleSetSelection={sampleSetSelection}
42
+ stratifications={stratifications}
43
+ />,
44
+ );
45
+ const [lhsSelect, rhsSelect] = screen.getAllByRole('combobox');
46
+ return {
47
+ lhsSelect, rhsSelect, setSampleSetFilter, setSampleSetSelection,
48
+ };
49
+ }
50
+
51
+ describe('BiomarkerSelectAltSampleGroups', () => {
52
+ it('defaults to All/None when there is no sampleSetSelection', () => {
53
+ const { lhsSelect, rhsSelect } = renderSampleGroups(null);
54
+ expect(lhsSelect.value).toEqual('__all__');
55
+ expect(rhsSelect.value).toEqual('__none__');
56
+ });
57
+
58
+ it('reflects an initial sampleSetSelection with two groups', () => {
59
+ const { lhsSelect, rhsSelect } = renderSampleGroups([
60
+ ['Enrollment Category', 'Healthy Reference'],
61
+ ['Enrollment Category', 'CKD'],
62
+ ]);
63
+ expect(lhsSelect.value).toEqual('Enrollment Category: Healthy Reference');
64
+ expect(rhsSelect.value).toEqual('Enrollment Category: CKD');
65
+ });
66
+
67
+ it('reflects an initial sampleSetSelection with one group', () => {
68
+ const { lhsSelect, rhsSelect } = renderSampleGroups([
69
+ ['Enrollment Category', 'Healthy Reference'],
70
+ ]);
71
+ expect(lhsSelect.value).toEqual('Enrollment Category: Healthy Reference');
72
+ expect(rhsSelect.value).toEqual('__none__');
73
+ });
74
+
75
+ it('falls back to All/None when the sampleSetSelection does not match an option', () => {
76
+ const { lhsSelect, rhsSelect } = renderSampleGroups([
77
+ ['Enrollment Category', 'Unknown'],
78
+ ['Enrollment Category', 'CKD'],
79
+ ]);
80
+ expect(lhsSelect.value).toEqual('__all__');
81
+ expect(rhsSelect.value).toEqual('__none__');
82
+ });
83
+
84
+ it('calls the setters upon selecting a second group', () => {
85
+ const {
86
+ rhsSelect, setSampleSetFilter, setSampleSetSelection,
87
+ } = renderSampleGroups([
88
+ ['Enrollment Category', 'Healthy Reference'],
89
+ ]);
90
+ fireEvent.change(rhsSelect, { target: { value: 'Enrollment Category: AKI' } });
91
+ const expected = [
92
+ ['Enrollment Category', 'Healthy Reference'],
93
+ ['Enrollment Category', 'AKI'],
94
+ ];
95
+ expect(setSampleSetFilter).toHaveBeenCalledWith(expected);
96
+ expect(setSampleSetSelection).toHaveBeenCalledWith(expected);
97
+ });
98
+ });
@@ -1,6 +1,8 @@
1
1
  /* eslint-disable max-len */
2
2
  /* eslint-disable no-unused-vars */
3
- import React, { useState, useCallback, useMemo } from 'react';
3
+ import React, { useCallback, useMemo, useEffect } from 'react';
4
+ import { useQuery } from '@tanstack/react-query';
5
+ import { uniqBy } from 'lodash-es';
4
6
  import {
5
7
  useAsyncFunction,
6
8
  useViewConfigStoreApi,
@@ -19,12 +21,17 @@ import { BiomarkerSelectAlt } from './BiomarkerSelectAlt.js';
19
21
  /**
20
22
  * Alternative biomarker select UI.
21
23
  * @param {object} props
22
- * @param {{ name: string, stratificationType: string, sampleSets: [string[], string[]]}[]} props.stratificationOptions
24
+ * @param {string} props.uuid The view uid.
25
+ * @param {{ label: string, nodeType: string } | null} [props.biomarkerSelection] The selected
26
+ * modality-agnostic item (e.g., a gene or pathway), stored in the view config `props` of this view.
27
+ * Internally, it is transformed into the list of genes for the featureSelection coordination value.
23
28
  * @returns
24
29
  */
25
30
  export function BiomarkerSelectAltSubscriber(props) {
26
31
  const {
32
+ uuid,
27
33
  coordinationScopes: coordinationScopesRaw,
34
+ biomarkerSelection = null,
28
35
  } = props;
29
36
 
30
37
  const loaders = useLoaders();
@@ -38,6 +45,7 @@ export function BiomarkerSelectAltSubscriber(props) {
38
45
  sampleSetSelection,
39
46
  featureSelection,
40
47
  }, {
48
+ setDataset,
41
49
  setSampleSetFilter,
42
50
  setSampleSetSelection,
43
51
  setFeatureSelection,
@@ -50,6 +58,26 @@ export function BiomarkerSelectAltSubscriber(props) {
50
58
  const viewConfig = useViewConfig();
51
59
  const setViewConfig = useSetViewConfig(viewConfigStoreApi);
52
60
 
61
+ // Update the biomarkerSelection value in the view config props of this view.
62
+ const setBiomarkerSelection = useCallback((newBiomarkerSelection) => {
63
+ const { viewConfig: currentViewConfig } = viewConfigStoreApi.getState();
64
+ setViewConfig({
65
+ ...currentViewConfig,
66
+ layout: currentViewConfig.layout.map(v => (v.uid === uuid
67
+ ? { ...v, props: { ...v.props, biomarkerSelection: newBiomarkerSelection } }
68
+ : v
69
+ )),
70
+ });
71
+ }, [viewConfigStoreApi, setViewConfig, uuid]);
72
+
73
+ // Options for the dropdown used to switch between datasets
74
+ // (e.g., single-cell vs. single-nucleus data modalities).
75
+ // Only rendered when multiple datasets are present in the config.
76
+ const datasetOptions = useMemo(() => (viewConfig?.datasets ?? []).map(d => ({
77
+ uid: d.uid,
78
+ name: d.name,
79
+ })), [viewConfig?.datasets]);
80
+
53
81
 
54
82
  // Need obsSets and sampleSets options to obtain mapping between
55
83
  // group names and column names.
@@ -61,11 +89,6 @@ export function BiomarkerSelectAltSubscriber(props) {
61
89
  );
62
90
  const sampleSetsColumnNameMappingReversed = useColumnNameMapping(sampleSetsLoader, true);
63
91
 
64
- const [mode] = useState(null);
65
- const [currentModalityAgnosticSelection, setCurrentModalityAgnosticSelection] = useState(null);
66
- const [currentModalitySpecificSelection, setCurrentModalitySpecificSelection] = useState(null);
67
- const [currentStratificationSelection, setCurrentStratificationSelection] = useState(null);
68
-
69
92
  const autocompleteFeature = useAsyncFunction(AsyncFunctionType.AUTOCOMPLETE_FEATURE);
70
93
  const transformFeature = useAsyncFunction(AsyncFunctionType.TRANSFORM_FEATURE);
71
94
 
@@ -81,6 +104,31 @@ export function BiomarkerSelectAltSubscriber(props) {
81
104
  [transformFeature],
82
105
  );
83
106
 
107
+ // The biomarkerSelection only contains the label and nodeType
108
+ // (e.g., when provided via URL params), so we look up the full knowledge graph node
109
+ // (containing the kgId and ontology term) and its corresponding genes.
110
+ const { data: resolvedBiomarker } = useQuery({
111
+ queryKey: ['biomarkerSelectAlt', 'resolveBiomarker', biomarkerSelection?.label, biomarkerSelection?.nodeType],
112
+ enabled: Boolean(biomarkerSelection),
113
+ staleTime: Infinity,
114
+ queryFn: async () => {
115
+ const { label, nodeType } = biomarkerSelection;
116
+ const matches = await autocompleteFeature(label);
117
+ const node = matches.find(n => n.label === label && n.nodeType === nodeType) ?? null;
118
+ const genes = node ? uniqBy(await transformFeature(node, 'gene'), 'label') : [];
119
+ return { node, genes };
120
+ },
121
+ });
122
+
123
+ // Initialize the featureSelection based on the biomarkerSelection,
124
+ // in the case that only the biomarkerSelection has been provided
125
+ // (e.g., upon initial page load with a pathway specified in the URL params).
126
+ useEffect(() => {
127
+ if (resolvedBiomarker && biomarkerSelection && featureSelection == null) {
128
+ setFeatureSelection(resolvedBiomarker.genes.map(d => d.label));
129
+ }
130
+ }, [resolvedBiomarker, biomarkerSelection, featureSelection, setFeatureSelection]);
131
+
84
132
  const [{ comparisonMetadata }, cmpMetadataStatus, cmpMetadataUrls] = useComparisonMetadata(
85
133
  loaders, dataset, false, {}, {}, { obsType, sampleType },
86
134
  );
@@ -118,61 +166,22 @@ export function BiomarkerSelectAltSubscriber(props) {
118
166
  return null;
119
167
  }, [comparisonMetadata, sampleSetsColumnNameMappingReversed]);
120
168
 
121
- // TODO: Remove mode/step logic
122
- // TODO: remove currentModalityAgnostic/SpecificSelection and use featureSelection + sampleSetSelection as the source of truth.
123
- // Get rid of the local state within the children components and pass down the coordination values and setters directly
124
- // so that everything stays in sync.
125
- // E.g., if a user selects a gene from the volcano plot, the autocomplete input should reflect that selection
126
- // and allow the user to view the corresponding gene info / gene card.
127
-
128
169
  return (
129
170
  <>
130
171
  <BiomarkerSelectAlt
131
172
  setFeatureSelection={setFeatureSelection}
132
173
  setSampleSetFilter={setSampleSetFilter}
133
174
  setSampleSetSelection={setSampleSetSelection}
134
- currentModalityAgnosticSelection={currentModalityAgnosticSelection}
135
- setCurrentModalityAgnosticSelection={setCurrentModalityAgnosticSelection}
136
- setCurrentModalitySpecificSelection={setCurrentModalitySpecificSelection}
175
+ sampleSetSelection={sampleSetSelection}
176
+ biomarkerSelection={biomarkerSelection}
177
+ setBiomarkerSelection={setBiomarkerSelection}
178
+ resolvedBiomarker={resolvedBiomarker?.node ?? null}
137
179
  autocompleteNode={autocompleteNode}
138
180
  getEdges={getEdges}
139
181
  stratifications={stratificationOptions}
140
-
141
- onFinish={() => {
142
- if (mode === 'exploratory') {
143
- // mode is exploratory, configure accordingly.
144
-
145
- // TODO
146
-
147
- } else {
148
- // mode is confirmatory, configure accordingly.
149
-
150
- // TODO
151
- }
152
-
153
- const newViewConfig = {
154
- ...viewConfig,
155
- coordinationSpace: {
156
- ...viewConfig.coordinationSpace,
157
- sampleSetFilter: {
158
- ...viewConfig.coordinationSpace.sampleSetFilter,
159
- __comparison__: currentStratificationSelection?.sampleSets,
160
- },
161
- sampleSetSelection: {
162
- ...viewConfig.coordinationSpace.sampleSetSelection,
163
- __comparison__: currentStratificationSelection?.sampleSets,
164
- },
165
- featureSelection: {
166
- ...viewConfig.coordinationSpace.featureSelection,
167
- __comparison__: currentModalitySpecificSelection ? currentModalitySpecificSelection.map(d => d.label) : null,
168
- },
169
- },
170
- };
171
-
172
- // TODO: can the normal coordination value setters be used instead?
173
- // (e.g., setFeatureSelection, setSampleSetSelection)
174
- setViewConfig(newViewConfig);
175
- }}
182
+ datasetOptions={datasetOptions}
183
+ dataset={dataset}
184
+ setDataset={setDataset}
176
185
  />
177
186
  </>
178
187
  );