@vitessce/biomarker-select 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 (38) hide show
  1. package/dist/index.js +260 -75
  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
@@ -1,33 +1,51 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /* eslint-disable max-len */
3
3
  /* eslint-disable no-unused-vars */
4
- import React, { useState, useCallback, useMemo } from 'react';
4
+ import React, { useCallback, useMemo, useEffect } from 'react';
5
+ import { useQuery } from '@tanstack/react-query';
6
+ import { uniqBy } from 'lodash-es';
5
7
  import { useAsyncFunction, useViewConfigStoreApi, useSetViewConfig, useViewConfig, useCoordination, useLoaders, useComparisonMetadata, useMatchingLoader, useColumnNameMapping, useCoordinationScopes, } from '@vitessce/vit-s';
6
8
  import { AsyncFunctionType, ViewType, COMPONENT_COORDINATION_TYPES, DataType } from '@vitessce/constants-internal';
7
9
  import { BiomarkerSelectAlt } from './BiomarkerSelectAlt.js';
8
10
  /**
9
11
  * Alternative biomarker select UI.
10
12
  * @param {object} props
11
- * @param {{ name: string, stratificationType: string, sampleSets: [string[], string[]]}[]} props.stratificationOptions
13
+ * @param {string} props.uuid The view uid.
14
+ * @param {{ label: string, nodeType: string } | null} [props.biomarkerSelection] The selected
15
+ * modality-agnostic item (e.g., a gene or pathway), stored in the view config `props` of this view.
16
+ * Internally, it is transformed into the list of genes for the featureSelection coordination value.
12
17
  * @returns
13
18
  */
14
19
  export function BiomarkerSelectAltSubscriber(props) {
15
- const { coordinationScopes: coordinationScopesRaw, } = props;
20
+ const { uuid, coordinationScopes: coordinationScopesRaw, biomarkerSelection = null, } = props;
16
21
  const loaders = useLoaders();
17
22
  const coordinationScopes = useCoordinationScopes(coordinationScopesRaw);
18
- const [{ dataset, obsType, sampleType, sampleSetFilter, sampleSetSelection, featureSelection, }, { setSampleSetFilter, setSampleSetSelection, setFeatureSelection, }] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.BIOMARKER_SELECT], coordinationScopes);
23
+ const [{ dataset, obsType, sampleType, sampleSetFilter, sampleSetSelection, featureSelection, }, { setDataset, setSampleSetFilter, setSampleSetSelection, setFeatureSelection, }] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.BIOMARKER_SELECT], coordinationScopes);
19
24
  const viewConfigStoreApi = useViewConfigStoreApi();
20
25
  const viewConfig = useViewConfig();
21
26
  const setViewConfig = useSetViewConfig(viewConfigStoreApi);
27
+ // Update the biomarkerSelection value in the view config props of this view.
28
+ const setBiomarkerSelection = useCallback((newBiomarkerSelection) => {
29
+ const { viewConfig: currentViewConfig } = viewConfigStoreApi.getState();
30
+ setViewConfig({
31
+ ...currentViewConfig,
32
+ layout: currentViewConfig.layout.map(v => (v.uid === uuid
33
+ ? { ...v, props: { ...v.props, biomarkerSelection: newBiomarkerSelection } }
34
+ : v)),
35
+ });
36
+ }, [viewConfigStoreApi, setViewConfig, uuid]);
37
+ // Options for the dropdown used to switch between datasets
38
+ // (e.g., single-cell vs. single-nucleus data modalities).
39
+ // Only rendered when multiple datasets are present in the config.
40
+ const datasetOptions = useMemo(() => (viewConfig?.datasets ?? []).map(d => ({
41
+ uid: d.uid,
42
+ name: d.name,
43
+ })), [viewConfig?.datasets]);
22
44
  // Need obsSets and sampleSets options to obtain mapping between
23
45
  // group names and column names.
24
46
  const obsSetsLoader = useMatchingLoader(loaders, dataset, DataType.OBS_SETS, { obsType });
25
47
  const sampleSetsLoader = useMatchingLoader(loaders, dataset, DataType.SAMPLE_SETS, { sampleType });
26
48
  const sampleSetsColumnNameMappingReversed = useColumnNameMapping(sampleSetsLoader, true);
27
- const [mode] = useState(null);
28
- const [currentModalityAgnosticSelection, setCurrentModalityAgnosticSelection] = useState(null);
29
- const [currentModalitySpecificSelection, setCurrentModalitySpecificSelection] = useState(null);
30
- const [currentStratificationSelection, setCurrentStratificationSelection] = useState(null);
31
49
  const autocompleteFeature = useAsyncFunction(AsyncFunctionType.AUTOCOMPLETE_FEATURE);
32
50
  const transformFeature = useAsyncFunction(AsyncFunctionType.TRANSFORM_FEATURE);
33
51
  const autocompleteNode = useCallback(async (inputValue) => {
@@ -38,6 +56,29 @@ export function BiomarkerSelectAltSubscriber(props) {
38
56
  }));
39
57
  }, [autocompleteFeature]);
40
58
  const getEdges = useCallback(async (node, targetModality) => transformFeature(node, targetModality), [transformFeature]);
59
+ // The biomarkerSelection only contains the label and nodeType
60
+ // (e.g., when provided via URL params), so we look up the full knowledge graph node
61
+ // (containing the kgId and ontology term) and its corresponding genes.
62
+ const { data: resolvedBiomarker } = useQuery({
63
+ queryKey: ['biomarkerSelectAlt', 'resolveBiomarker', biomarkerSelection?.label, biomarkerSelection?.nodeType],
64
+ enabled: Boolean(biomarkerSelection),
65
+ staleTime: Infinity,
66
+ queryFn: async () => {
67
+ const { label, nodeType } = biomarkerSelection;
68
+ const matches = await autocompleteFeature(label);
69
+ const node = matches.find(n => n.label === label && n.nodeType === nodeType) ?? null;
70
+ const genes = node ? uniqBy(await transformFeature(node, 'gene'), 'label') : [];
71
+ return { node, genes };
72
+ },
73
+ });
74
+ // Initialize the featureSelection based on the biomarkerSelection,
75
+ // in the case that only the biomarkerSelection has been provided
76
+ // (e.g., upon initial page load with a pathway specified in the URL params).
77
+ useEffect(() => {
78
+ if (resolvedBiomarker && biomarkerSelection && featureSelection == null) {
79
+ setFeatureSelection(resolvedBiomarker.genes.map(d => d.label));
80
+ }
81
+ }, [resolvedBiomarker, biomarkerSelection, featureSelection, setFeatureSelection]);
41
82
  const [{ comparisonMetadata }, cmpMetadataStatus, cmpMetadataUrls] = useComparisonMetadata(loaders, dataset, false, {}, {}, { obsType, sampleType });
42
83
  const stratificationOptions = useMemo(() => {
43
84
  /*
@@ -72,42 +113,6 @@ export function BiomarkerSelectAltSubscriber(props) {
72
113
  }
73
114
  return null;
74
115
  }, [comparisonMetadata, sampleSetsColumnNameMappingReversed]);
75
- // TODO: Remove mode/step logic
76
- // TODO: remove currentModalityAgnostic/SpecificSelection and use featureSelection + sampleSetSelection as the source of truth.
77
- // Get rid of the local state within the children components and pass down the coordination values and setters directly
78
- // so that everything stays in sync.
79
- // E.g., if a user selects a gene from the volcano plot, the autocomplete input should reflect that selection
80
- // and allow the user to view the corresponding gene info / gene card.
81
- return (_jsx(_Fragment, { children: _jsx(BiomarkerSelectAlt, { setFeatureSelection: setFeatureSelection, setSampleSetFilter: setSampleSetFilter, setSampleSetSelection: setSampleSetSelection, currentModalityAgnosticSelection: currentModalityAgnosticSelection, setCurrentModalityAgnosticSelection: setCurrentModalityAgnosticSelection, setCurrentModalitySpecificSelection: setCurrentModalitySpecificSelection, autocompleteNode: autocompleteNode, getEdges: getEdges, stratifications: stratificationOptions, onFinish: () => {
82
- if (mode === 'exploratory') {
83
- // mode is exploratory, configure accordingly.
84
- // TODO
85
- }
86
- else {
87
- // mode is confirmatory, configure accordingly.
88
- // TODO
89
- }
90
- const newViewConfig = {
91
- ...viewConfig,
92
- coordinationSpace: {
93
- ...viewConfig.coordinationSpace,
94
- sampleSetFilter: {
95
- ...viewConfig.coordinationSpace.sampleSetFilter,
96
- __comparison__: currentStratificationSelection?.sampleSets,
97
- },
98
- sampleSetSelection: {
99
- ...viewConfig.coordinationSpace.sampleSetSelection,
100
- __comparison__: currentStratificationSelection?.sampleSets,
101
- },
102
- featureSelection: {
103
- ...viewConfig.coordinationSpace.featureSelection,
104
- __comparison__: currentModalitySpecificSelection ? currentModalitySpecificSelection.map(d => d.label) : null,
105
- },
106
- },
107
- };
108
- // TODO: can the normal coordination value setters be used instead?
109
- // (e.g., setFeatureSelection, setSampleSetSelection)
110
- setViewConfig(newViewConfig);
111
- } }) }));
116
+ return (_jsx(_Fragment, { children: _jsx(BiomarkerSelectAlt, { setFeatureSelection: setFeatureSelection, setSampleSetFilter: setSampleSetFilter, setSampleSetSelection: setSampleSetSelection, sampleSetSelection: sampleSetSelection, biomarkerSelection: biomarkerSelection, setBiomarkerSelection: setBiomarkerSelection, resolvedBiomarker: resolvedBiomarker?.node ?? null, autocompleteNode: autocompleteNode, getEdges: getEdges, stratifications: stratificationOptions, datasetOptions: datasetOptions, dataset: dataset, setDataset: setDataset }) }));
112
117
  }
113
118
  //# sourceMappingURL=BiomarkerSelectAltSubscriber.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BiomarkerSelectAltSubscriber.js","sourceRoot":"","sources":["../src/BiomarkerSelectAltSubscriber.js"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,mCAAmC;AACnC,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,4BAA4B,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAAC,KAAK;IAChD,MAAM,EACJ,kBAAkB,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AgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,qBAAqB,EACtC,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU,GACtB,GACD,CACJ,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/biomarker-select",
3
- "version": "4.1.2",
3
+ "version": "4.2.0",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -22,10 +22,10 @@
22
22
  "d3-dsv": "^1.1.1",
23
23
  "clsx": "^1.1.1",
24
24
  "lodash-es": "^4.17.21",
25
- "@vitessce/styles": "4.1.2",
26
- "@vitessce/constants-internal": "4.1.2",
27
- "@vitessce/types": "4.1.2",
28
- "@vitessce/vit-s": "4.1.2"
25
+ "@vitessce/styles": "4.2.0",
26
+ "@vitessce/vit-s": "4.2.0",
27
+ "@vitessce/types": "4.2.0",
28
+ "@vitessce/constants-internal": "4.2.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@testing-library/jest-dom": "^6.6.3",
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { Grid } from '@vitessce/styles';
3
3
  import { BiomarkerSelectAltGeneAutocomplete } from './BiomarkerSelectAltGeneAutocomplete.js';
4
4
  import { BiomarkerSelectAltSampleGroups } from './BiomarkerSelectAltSampleGroups.js';
5
+ import { BiomarkerSelectAltDatasetSelect } from './BiomarkerSelectAltDatasetSelect.js';
5
6
  import { useStyles } from './styles.js';
6
7
 
7
8
 
@@ -10,18 +11,23 @@ export function BiomarkerSelectAlt(props) {
10
11
  setFeatureSelection,
11
12
  setSampleSetFilter,
12
13
  setSampleSetSelection,
14
+ sampleSetSelection,
13
15
 
14
- currentModalityAgnosticSelection,
15
- setCurrentModalityAgnosticSelection,
16
- setCurrentModalitySpecificSelection,
16
+ biomarkerSelection,
17
+ setBiomarkerSelection,
18
+ resolvedBiomarker,
17
19
 
18
20
  autocompleteNode,
19
21
  getEdges,
20
22
 
21
23
  stratifications,
24
+
25
+ datasetOptions,
26
+ dataset,
27
+ setDataset,
22
28
  } = props;
23
29
  const { classes } = useStyles();
24
-
30
+ const hasMultipleDatasets = Array.isArray(datasetOptions) && datasetOptions.length > 1;
25
31
 
26
32
  return (
27
33
  <Grid container sx={{ border: '0px solid red' }}>
@@ -38,14 +44,33 @@ export function BiomarkerSelectAlt(props) {
38
44
  autocompleteNode={autocompleteNode}
39
45
  getEdges={getEdges}
40
46
 
41
- currentModalityAgnosticSelection={currentModalityAgnosticSelection}
42
- setCurrentModalityAgnosticSelection={setCurrentModalityAgnosticSelection}
43
- setCurrentModalitySpecificSelection={setCurrentModalitySpecificSelection}
47
+ biomarkerSelection={biomarkerSelection}
48
+ setBiomarkerSelection={setBiomarkerSelection}
49
+ resolvedBiomarker={resolvedBiomarker}
44
50
  />
45
51
  </Grid>
52
+ {hasMultipleDatasets ? (
53
+ <Grid
54
+ container
55
+ size={4}
56
+ sx={{
57
+ justifyContent: 'flex-start',
58
+ flexDirection: 'column',
59
+ minWidth: 0,
60
+ paddingLeft: '8px',
61
+ paddingRight: '8px',
62
+ }}
63
+ >
64
+ <BiomarkerSelectAltDatasetSelect
65
+ datasetOptions={datasetOptions}
66
+ dataset={dataset}
67
+ setDataset={setDataset}
68
+ />
69
+ </Grid>
70
+ ) : null}
46
71
  <Grid
47
72
  container
48
- size={5}
73
+ size={hasMultipleDatasets ? 4 : 5}
49
74
  sx={{
50
75
  justifyContent: 'flex-start',
51
76
  flexDirection: 'column',
@@ -54,6 +79,7 @@ export function BiomarkerSelectAlt(props) {
54
79
  <BiomarkerSelectAltSampleGroups
55
80
  setSampleSetFilter={setSampleSetFilter}
56
81
  setSampleSetSelection={setSampleSetSelection}
82
+ sampleSetSelection={sampleSetSelection}
57
83
 
58
84
  stratifications={stratifications}
59
85
  />
@@ -11,10 +11,16 @@ vi.mock('@vitessce/styles', () => ({
11
11
  Typography: ({ children }) => <span>{children}</span>,
12
12
  Dialog: () => null,
13
13
  Info: () => null,
14
- SimpleAutocomplete: ({ getMatches, onChange }) => (
15
- <button type="button" onClick={async () => onChange((await getMatches('pathway'))[0])}>
16
- Choose result
17
- </button>
14
+ SimpleAutocomplete: ({ getMatches, onChange, value }) => (
15
+ <>
16
+ <span data-testid="autocomplete-value">{value ? `${value.label} (${value.data.nodeType})` : ''}</span>
17
+ <button type="button" onClick={async () => onChange((await getMatches('pathway'))[0])}>
18
+ Choose result
19
+ </button>
20
+ <button type="button" onClick={() => onChange(null)}>
21
+ Clear
22
+ </button>
23
+ </>
18
24
  ),
19
25
  }));
20
26
  vi.mock('./styles.js', () => ({ useStyles: () => ({ classes: {} }) }));
@@ -29,11 +35,10 @@ const otherPathway = { kgId: 'other-pathway', label: 'Other pathway', nodeType:
29
35
 
30
36
  describe('BiomarkerSelectAlt', () => {
31
37
  it.each([
32
- ['pathway members', pathway, [], ['GENE_A', 'GENE_B']],
33
- ['overlapping selections', pathway, [geneA, otherPathway], ['GENE_A', 'GENE_B']],
34
- ['a directly selected gene', geneA, [], ['GENE_A']],
35
- ['a pathway without members', { ...pathway, kgId: 'empty' }, [], []],
36
- ])('selects genes for %s', async (_name, selectedItem, previousSelection, expected) => {
38
+ ['pathway members', pathway, ['GENE_A', 'GENE_B']],
39
+ ['a directly selected gene', geneA, ['GENE_A']],
40
+ ['a pathway without members', { ...pathway, kgId: 'empty' }, []],
41
+ ])('selects genes for %s', async (_name, selectedItem, expected) => {
37
42
  const queryClient = new QueryClient();
38
43
  queryClient.setQueryData(['geneNodes'], [geneA, geneB]);
39
44
  queryClient.setQueryData(['pathwayGeneEdges'], [
@@ -42,16 +47,15 @@ describe('BiomarkerSelectAlt', () => {
42
47
  { source: otherPathway.kgId, target: geneB.kgId },
43
48
  ]);
44
49
  const setFeatureSelection = vi.fn();
45
- const setCurrentModalityAgnosticSelection = vi.fn();
46
- const setCurrentModalitySpecificSelection = vi.fn();
50
+ const setBiomarkerSelection = vi.fn();
47
51
 
48
52
  render(
49
53
  <BiomarkerSelectAlt
50
54
  autocompleteNode={async () => [{ label: selectedItem.label, data: selectedItem }]}
51
55
  getEdges={(node, modality) => transformFeature({ queryClient }, node, modality)}
52
- currentModalityAgnosticSelection={previousSelection}
53
- setCurrentModalityAgnosticSelection={setCurrentModalityAgnosticSelection}
54
- setCurrentModalitySpecificSelection={setCurrentModalitySpecificSelection}
56
+ biomarkerSelection={null}
57
+ setBiomarkerSelection={setBiomarkerSelection}
58
+ resolvedBiomarker={null}
55
59
  setFeatureSelection={setFeatureSelection}
56
60
  />,
57
61
  );
@@ -60,12 +64,44 @@ describe('BiomarkerSelectAlt', () => {
60
64
  fireEvent.click(await screen.findByRole('button', { name: 'Select' }));
61
65
 
62
66
  await waitFor(() => expect(setFeatureSelection).toHaveBeenCalledWith(expected));
63
- expect(setCurrentModalityAgnosticSelection).toHaveBeenCalledWith([
64
- ...previousSelection, selectedItem,
65
- ]);
66
- expect(setCurrentModalitySpecificSelection).toHaveBeenCalledWith(
67
- expected.map(label => [geneA, geneB].find(node => node.label === label)),
68
- );
67
+ expect(setBiomarkerSelection).toHaveBeenCalledWith({
68
+ label: selectedItem.label,
69
+ nodeType: selectedItem.nodeType,
70
+ });
69
71
  queryClient.clear();
70
72
  });
73
+
74
+ it('displays the biomarkerSelection (e.g., from URL params) in the autocomplete', () => {
75
+ render(
76
+ <BiomarkerSelectAlt
77
+ autocompleteNode={async () => []}
78
+ getEdges={async () => []}
79
+ biomarkerSelection={{ label: otherPathway.label, nodeType: 'pathway' }}
80
+ setBiomarkerSelection={vi.fn()}
81
+ resolvedBiomarker={null}
82
+ setFeatureSelection={vi.fn()}
83
+ />,
84
+ );
85
+ expect(screen.getByTestId('autocomplete-value').textContent).toEqual('Other pathway (pathway)');
86
+ // The selection has already been confirmed.
87
+ expect(screen.queryByRole('button', { name: 'Select' })).toBeNull();
88
+ });
89
+
90
+ it('clears the selection when the autocomplete is cleared', () => {
91
+ const setFeatureSelection = vi.fn();
92
+ const setBiomarkerSelection = vi.fn();
93
+ render(
94
+ <BiomarkerSelectAlt
95
+ autocompleteNode={async () => []}
96
+ getEdges={async () => []}
97
+ biomarkerSelection={{ label: geneA.label, nodeType: 'gene' }}
98
+ setBiomarkerSelection={setBiomarkerSelection}
99
+ resolvedBiomarker={geneA}
100
+ setFeatureSelection={setFeatureSelection}
101
+ />,
102
+ );
103
+ fireEvent.click(screen.getByRole('button', { name: 'Clear' }));
104
+ expect(setBiomarkerSelection).toHaveBeenCalledWith(null);
105
+ expect(setFeatureSelection).toHaveBeenCalledWith(null);
106
+ });
71
107
  });
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import { Grid, NativeSelect } from '@vitessce/styles';
3
+
4
+ /**
5
+ * Dropdown for selecting which dataset (e.g., data modality such as
6
+ * single-cell vs. single-nucleus) is currently being viewed.
7
+ * Renders nothing unless there are at least two dataset options.
8
+ * @param {object} props
9
+ * @param {{ uid: string, name: string }[]} props.datasetOptions
10
+ * @param {string} props.dataset The uid of the currently-selected dataset.
11
+ * @param {Function} props.setDataset
12
+ */
13
+ export function BiomarkerSelectAltDatasetSelect(props) {
14
+ const {
15
+ datasetOptions,
16
+ dataset,
17
+ setDataset,
18
+ } = props;
19
+
20
+ if (!Array.isArray(datasetOptions) || datasetOptions.length < 2) {
21
+ return null;
22
+ }
23
+
24
+ function handleChange(event) {
25
+ setDataset(event.target.value);
26
+ }
27
+
28
+ return (
29
+ <Grid container size={12} wrap="nowrap">
30
+ <Grid container size="auto">
31
+ <span style={{ lineHeight: '50px', whiteSpace: 'nowrap' }}>Modality:&nbsp;</span>
32
+ </Grid>
33
+ <Grid container size="grow" sx={{ minWidth: 0 }}>
34
+ <NativeSelect
35
+ onChange={handleChange}
36
+ value={dataset ?? ''}
37
+ variant="standard"
38
+ sx={{ width: '100%' }}
39
+ inputProps={{ 'aria-label': 'Select dataset' }}
40
+ >
41
+ {datasetOptions.map(o => (
42
+ <option key={o.uid} value={o.uid}>{o.name ?? o.uid}</option>
43
+ ))}
44
+ </NativeSelect>
45
+ </Grid>
46
+ </Grid>
47
+ );
48
+ }
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import { describe, it, expect, vi } from 'vitest';
3
+ import { fireEvent, render, screen } from '@testing-library/react';
4
+ import { BiomarkerSelectAltDatasetSelect } from './BiomarkerSelectAltDatasetSelect.js';
5
+
6
+ const datasetOptions = [
7
+ { uid: 'sc-rna-seq', name: 'Single-cell RNA sequencing' },
8
+ { uid: 'sn-rna-seq', name: 'Single-nucleus RNA sequencing' },
9
+ ];
10
+
11
+ describe('BiomarkerSelectAltDatasetSelect', () => {
12
+ it('renders nothing when fewer than two datasets are available', () => {
13
+ const { container } = render(
14
+ <BiomarkerSelectAltDatasetSelect
15
+ datasetOptions={[datasetOptions[0]]}
16
+ dataset="sc-rna-seq"
17
+ setDataset={vi.fn()}
18
+ />,
19
+ );
20
+ expect(container).toBeEmptyDOMElement();
21
+ });
22
+
23
+ it('renders a dropdown to switch between datasets', () => {
24
+ const setDataset = vi.fn();
25
+ render(
26
+ <BiomarkerSelectAltDatasetSelect
27
+ datasetOptions={datasetOptions}
28
+ dataset="sc-rna-seq"
29
+ setDataset={setDataset}
30
+ />,
31
+ );
32
+ const select = screen.getByRole('combobox', { name: 'Select dataset' });
33
+ expect(select).toHaveValue('sc-rna-seq');
34
+ expect(screen.getByRole('option', { name: 'Single-nucleus RNA sequencing' })).toBeInTheDocument();
35
+
36
+ fireEvent.change(select, { target: { value: 'sn-rna-seq' } });
37
+ expect(setDataset).toHaveBeenCalledWith('sn-rna-seq');
38
+ });
39
+ });
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-unused-vars */
2
1
  import React, { useState } from 'react';
3
2
  import { uniqBy } from 'lodash-es';
4
3
  import {
@@ -8,72 +7,110 @@ import {
8
7
  Info as InfoIcon,
9
8
  SimpleAutocomplete,
10
9
  } from '@vitessce/styles';
11
- import { useStyles } from './styles.js';
12
10
 
11
+ /**
12
+ * Check whether a knowledge graph node matches a biomarkerSelection value.
13
+ * @param {{ label: string, nodeType: string } | null} node
14
+ * @param {{ label: string, nodeType: string } | null} biomarkerSelection
15
+ * @returns {boolean}
16
+ */
17
+ function isSameBiomarker(node, biomarkerSelection) {
18
+ return Boolean(node && biomarkerSelection
19
+ && node.label === biomarkerSelection.label
20
+ && node.nodeType === biomarkerSelection.nodeType);
21
+ }
13
22
 
23
+ /**
24
+ * Autocomplete input for selecting a single modality-agnostic
25
+ * item (e.g., a gene or pathway). Upon confirmation of the selection,
26
+ * the item is transformed into the corresponding list of genes,
27
+ * which is used as the featureSelection.
28
+ * @param {object} props
29
+ * @param {Function} props.setFeatureSelection
30
+ * @param {Function} props.autocompleteNode
31
+ * @param {Function} props.getEdges
32
+ * @param {{ label: string, nodeType: string } | null} props.biomarkerSelection
33
+ * The currently-selected item (e.g., from URL params).
34
+ * @param {Function} props.setBiomarkerSelection
35
+ * @param {object|null} props.resolvedBiomarker The full knowledge graph node
36
+ * corresponding to the biomarkerSelection, once looked up.
37
+ */
14
38
  export function BiomarkerSelectAltGeneAutocomplete(props) {
15
39
  const {
16
40
  setFeatureSelection,
17
41
  autocompleteNode,
18
42
  getEdges,
19
- currentModalityAgnosticSelection,
20
- setCurrentModalityAgnosticSelection,
21
- setCurrentModalitySpecificSelection,
43
+ biomarkerSelection,
44
+ setBiomarkerSelection,
45
+ resolvedBiomarker,
22
46
  } = props;
23
- const { classes } = useStyles();
24
47
 
25
- const [selectedItem, setSelectedItem] = useState(null);
48
+ // An item that has been chosen in the autocomplete but not yet confirmed.
49
+ const [pendingItem, setPendingItem] = useState(null);
26
50
 
27
51
  const [biomarkerInfoOpen, setBiomarkerInfoOpen] = useState(false);
28
52
 
53
+ // The confirmed item. Prior to the lookup of the full node,
54
+ // fall back to the label and nodeType (e.g., from URL params).
55
+ const confirmedItem = isSameBiomarker(resolvedBiomarker, biomarkerSelection)
56
+ ? resolvedBiomarker
57
+ : biomarkerSelection;
58
+ const displayedItem = pendingItem ?? confirmedItem ?? null;
59
+ const hasPendingChange = Boolean(pendingItem)
60
+ && !isSameBiomarker(pendingItem, biomarkerSelection);
61
+ // The ontology term is needed to display the info dialog.
62
+ const hasInfo = Boolean(displayedItem?.term);
29
63
 
30
- async function confirmSelectedItem() {
31
- // eslint-disable-next-line max-len
32
- if (selectedItem && !currentModalityAgnosticSelection?.find(item => item.kgId === selectedItem?.kgId)) {
33
- const nextModalityAgnosticSelection = [
34
- ...(currentModalityAgnosticSelection || []),
35
- selectedItem,
36
- ];
37
- const matchingGenes = await Promise.all(
38
- nextModalityAgnosticSelection.map(item => getEdges(item, 'gene')),
39
- );
40
- const nextModalitySpecificSelection = uniqBy(matchingGenes.flat(), 'label');
41
- setCurrentModalityAgnosticSelection(nextModalityAgnosticSelection);
42
- setCurrentModalitySpecificSelection(nextModalitySpecificSelection);
43
- setFeatureSelection(nextModalitySpecificSelection.map(d => d.label));
64
+ async function confirmPendingItem() {
65
+ if (hasPendingChange) {
66
+ const matchingGenes = await getEdges(pendingItem, 'gene');
67
+ const nextFeatureSelection = uniqBy(matchingGenes, 'label').map(d => d.label);
68
+ setBiomarkerSelection({ label: pendingItem.label, nodeType: pendingItem.nodeType });
69
+ setFeatureSelection(nextFeatureSelection);
44
70
  }
71
+ setPendingItem(null);
45
72
  }
46
73
 
47
74
  function clearBiomarkerSelection() {
48
- setCurrentModalityAgnosticSelection([]);
49
- setCurrentModalitySpecificSelection([]);
50
- setFeatureSelection([]);
75
+ setPendingItem(null);
76
+ setBiomarkerSelection(null);
77
+ setFeatureSelection(null);
78
+ }
79
+
80
+ function handleChange(item) {
81
+ if (item) {
82
+ setPendingItem(item.data);
83
+ } else {
84
+ // The autocomplete input was cleared.
85
+ clearBiomarkerSelection();
86
+ }
51
87
  }
52
88
 
53
89
  return (
54
90
  <>
55
91
  <Grid container size={12}>
56
- <Grid size={8}>
92
+ <Grid size={hasPendingChange ? 8 : 12}>
57
93
  <SimpleAutocomplete
94
+ value={displayedItem ? { label: displayedItem.label, data: displayedItem } : null}
58
95
  getMatches={autocompleteNode}
59
- onChange={item => setSelectedItem(item.data)}
96
+ onChange={handleChange}
60
97
  textInputLabel="Enter a gene"
61
98
  getItemLabel={item => `${item.label} (${item.data.nodeType})`}
62
99
  />
63
100
  </Grid>
64
- {selectedItem ? (
101
+ {hasPendingChange ? (
65
102
  <Grid size={4}>
66
103
  &nbsp;
67
104
  <Button
68
105
  variant="contained"
69
- onClick={confirmSelectedItem}
106
+ onClick={confirmPendingItem}
70
107
  >
71
108
  Select
72
109
  </Button>
73
110
  </Grid>
74
111
  ) : null}
75
112
  </Grid>
76
- {selectedItem ? (
113
+ {hasInfo ? (
77
114
  <>
78
115
  <Grid
79
116
  container
@@ -83,21 +120,21 @@ export function BiomarkerSelectAltGeneAutocomplete(props) {
83
120
  }}
84
121
  >
85
122
  <Button onClick={() => setBiomarkerInfoOpen(true)}>
86
- View {selectedItem.nodeType} info
123
+ View {displayedItem.nodeType} info
87
124
  </Button>
88
125
  </Grid>
89
126
  <Dialog open={biomarkerInfoOpen} onClose={() => setBiomarkerInfoOpen(false)} maxWidth="md">
90
- <Typography variant="h4" title={selectedItem.term}>
91
- {selectedItem.label}
127
+ <Typography variant="h4" title={displayedItem.term}>
128
+ {displayedItem.label}
92
129
  </Typography>
93
130
  <Grid container size={12}>
94
131
  <InfoIcon />
95
- <Typography variant="h6">About this {selectedItem.nodeType}</Typography>
132
+ <Typography variant="h6">About this {displayedItem.nodeType}</Typography>
96
133
  </Grid>
97
- <Grid container size={12} key={selectedItem.term} sx={{ width: '800px' }}>
134
+ <Grid container size={12} key={displayedItem.term} sx={{ width: '800px' }}>
98
135
  <iframe
99
- title={`Embedded metadata page for ontology term ${selectedItem.term}`}
100
- src={`https://identifiers.org/${selectedItem.term}`}
136
+ title={`Embedded metadata page for ontology term ${displayedItem.term}`}
137
+ src={`https://identifiers.org/${displayedItem.term}`}
101
138
  width="100%"
102
139
  height="500"
103
140
  style={{ border: 0 }}