Skip to content

Commit a367098

Browse files
committed
make step numbers available to notebook cells
1 parent d9c30ce commit a367098

File tree

6 files changed

+48
-52
lines changed

6 files changed

+48
-52
lines changed

packages/libs/eda/src/lib/notebook/ComputeNotebookCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export function ComputeNotebookCell(
229229
isDisabled={isSubCellDisabled}
230230
wdkState={wdkState}
231231
computeJobStatus={jobStatus}
232-
stepNumber={stepNumbers?.get(subCell)}
232+
stepNumber={stepNumbers?.get(subCell.id)}
233233
stepNumbers={stepNumbers}
234234
/>
235235
);

packages/libs/eda/src/lib/notebook/EdaNotebookAnalysis.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ export function EdaNotebookAnalysis(props: Props) {
140140
// Uses a depth-first walk so nested cells (e.g. volcano inside DE compute)
141141
// get sequential numbers. The Map is stable across partial re-renders.
142142
const stepNumbers = useMemo(() => {
143-
const map = new Map<NotebookCellDescriptor, number>();
143+
const map = new Map<string, number>();
144144
let n = 0;
145145
(function walk(cells: NotebookCellDescriptor[]) {
146146
for (const cell of cells) {
147-
if (cell.numberedHeader) map.set(cell, ++n);
147+
if (cell.numberedHeader) map.set(cell.id, ++n);
148148
if ('cells' in cell && cell.cells) walk(cell.cells);
149149
}
150150
})(notebookPreset.cells);
@@ -170,6 +170,7 @@ export function EdaNotebookAnalysis(props: Props) {
170170
typeof notebookPreset.header === 'function'
171171
? notebookPreset.header({
172172
submitButtonText: wdkState.submitButtonText,
173+
stepNumbers,
173174
})
174175
: notebookPreset.header
175176
}
@@ -184,7 +185,7 @@ export function EdaNotebookAnalysis(props: Props) {
184185
wdkState={wdkState}
185186
cell={cell}
186187
projectId={projectId}
187-
stepNumber={stepNumbers.get(cell)}
188+
stepNumber={stepNumbers.get(cell.id)}
188189
stepNumbers={stepNumbers}
189190
/>
190191
))

packages/libs/eda/src/lib/notebook/NotebookCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface NotebookCellProps<T extends NotebookCellDescriptor> {
1717
projectId?: string; // Project ID, ex: PlasmoDB, MicrobiomeDB, etc.
1818
computeJobStatus?: JobStatus; // Optional status of the compute job, useful for displaying progress or errors.
1919
stepNumber?: number; // Auto-computed step number for NumberedHeader display.
20-
stepNumbers?: Map<NotebookCellDescriptor, number>; // Map of all cell descriptors to their step numbers (for forwarding to nested cells).
20+
stepNumbers?: Map<string, number>; // Map of cell IDs to their step numbers (for forwarding to nested cells).
2121
}
2222

2323
/**

packages/libs/eda/src/lib/notebook/NotebookPresets.tsx

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type NotebookCellDescriptor =
2727
| WdkParamCellDescriptor;
2828

2929
export interface NotebookCellDescriptorBase<T extends string> {
30+
id: string; // Unique identifier for this cell. Used as key in stepNumbers map.
3031
type: T;
3132
title: string;
3233
cells?: NotebookCellDescriptor[];
@@ -44,7 +45,8 @@ export interface VisualizationCellDescriptor
4445
// Useful for adding interactivity between the viz and other notebook cells.
4546
getVizPluginOptions?: (
4647
wdkState: WdkState,
47-
enqueueSnackbar: EnqueueSnackbar
48+
enqueueSnackbar: EnqueueSnackbar,
49+
stepNumbers?: Map<string, number>
4850
) => Partial<BipartiteNetworkOptions> | Partial<VolcanoPlotOptions>; // We'll define this function custom for each notebook, so can expand output types as needed.
4951
}
5052

@@ -61,6 +63,7 @@ export interface ComputeCellDescriptor
6163
export interface TextCellContext {
6264
analysisState: AnalysisState;
6365
wdkState?: WdkState;
66+
stepNumbers?: Map<string, number>;
6467
}
6568

6669
export interface TextCellDescriptor extends NotebookCellDescriptorBase<'text'> {
@@ -85,7 +88,12 @@ type PresetNotebook = {
8588
displayName: string;
8689
projects: string[];
8790
cells: NotebookCellDescriptor[];
88-
header?: string | ((context: { submitButtonText: string }) => string); // Optional header text for the notebook, to be displayed above the cells.
91+
header?:
92+
| string
93+
| ((context: {
94+
submitButtonText: string;
95+
stepNumbers: Map<string, number>;
96+
}) => string); // Optional header text for the notebook, to be displayed above the cells.
8997
isReady?: (context: ReadinessContext) => boolean;
9098
};
9199

@@ -114,6 +122,7 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
114122
],
115123
cells: [
116124
{
125+
id: 'de_subset',
117126
type: 'subset',
118127
title: 'Select samples (optional)',
119128
numberedHeader: true,
@@ -122,6 +131,7 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
122131
),
123132
},
124133
{
134+
id: 'de_pca_compute',
125135
type: 'compute',
126136
title: 'PCA',
127137
computationName: 'dimensionalityreduction',
@@ -135,6 +145,7 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
135145
),
136146
cells: [
137147
{
148+
id: 'de_pca_plot',
138149
type: 'visualization',
139150
title: 'PCA Plot',
140151
visualizationName: 'scatterplot',
@@ -150,6 +161,7 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
150161
],
151162
},
152163
{
164+
id: 'de_deseq2_compute',
153165
type: 'compute',
154166
title: 'Setup DESeq2 Computation',
155167
computationName: 'differentialexpression',
@@ -165,45 +177,11 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
165177
),
166178
cells: [
167179
{
180+
id: 'de_volcano',
168181
type: 'visualization',
169182
title: 'Examine DESeq2 Results with Volcano Plot',
170183
visualizationName: 'volcanoplot',
171184
visualizationId: 'volcano_1',
172-
getVizPluginOptions: (
173-
wdkState: WdkState,
174-
enqueueSnackbar: EnqueueSnackbar
175-
) => {
176-
return {
177-
// When user changes viz config, show snackbar with updated params
178-
inputSnackbar: <K extends keyof VolcanoPlotConfig>(
179-
enqueueSnackbar: EnqueueSnackbar,
180-
vizConfigParameter: K,
181-
newValue: VolcanoPlotConfig[K]
182-
) => {
183-
let paramText = '';
184-
// The only two parameters we want to alert the user about are numbers.
185-
if (typeof newValue === 'number') {
186-
switch (vizConfigParameter) {
187-
case 'effectSizeThreshold':
188-
paramText = 'Absolute effect size';
189-
break;
190-
case 'significanceThreshold':
191-
paramText = 'Unadjusted P-value';
192-
break;
193-
default:
194-
paramText = 'Unknown parameter';
195-
}
196-
enqueueSnackbar(
197-
<span>
198-
Updated <strong>{paramText}</strong> search parameter
199-
to: <strong>{newValue}</strong>
200-
</span>,
201-
{ variant: 'info' }
202-
);
203-
}
204-
},
205-
};
206-
},
207185
numberedHeader: true,
208186
helperText: (
209187
<span>
@@ -214,6 +192,7 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
214192
),
215193
},
216194
{
195+
id: 'de_review',
217196
type: 'text',
218197
title: 'Review and run search',
219198
numberedHeader: true,
@@ -314,11 +293,14 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
314293
wgcnaCorrelationNotebook: {
315294
name: 'wgcnacorrelation',
316295
displayName: 'WGCNA Correlation Notebook',
317-
header: ({ submitButtonText }) =>
318-
`Use steps 1-3 to find a module of interest, then click '${submitButtonText}' to retrieve a list of genes.`,
296+
header: ({ submitButtonText, stepNumbers }) =>
297+
`Use steps 1-${
298+
stepNumbers.get('wgcna_params') ?? '?'
299+
} to find a module of interest, then click '${submitButtonText}' to retrieve a list of genes.`,
319300
projects: ['PlasmoDB', 'HostDB', 'UniDB'],
320301
cells: [
321302
{
303+
id: 'wgcna_correlation_compute',
322304
type: 'compute',
323305
title: 'Correlation computation',
324306
computationName: 'correlation',
@@ -346,6 +328,7 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
346328
},
347329
cells: [
348330
{
331+
id: 'wgcna_bipartite',
349332
type: 'visualization',
350333
title: 'Network visualization of correlation results',
351334
visualizationName: 'bipartitenetwork',
@@ -359,7 +342,8 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
359342
),
360343
getVizPluginOptions: (
361344
wdkState: WdkState,
362-
enqueueSnackbar: EnqueueSnackbar
345+
enqueueSnackbar: EnqueueSnackbar,
346+
stepNumbers?: Map<string, number>
363347
) => {
364348
return {
365349
additionalOnNodeClickAction: (node: NodeData) => {
@@ -411,10 +395,11 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
411395
wdkState.updateParamValue(param, moduleName);
412396

413397
// Open snackbar
398+
const paramStep = stepNumbers?.get('wgcna_params') ?? '?';
414399
enqueueSnackbar(
415400
<span>
416-
Updated WGNCA module search parameter in step 3 to:{' '}
417-
<strong>{moduleName}</strong>
401+
Updated WGCNA module search parameter in step {paramStep}{' '}
402+
to: <strong>{moduleName}</strong>
418403
</span>,
419404
{ variant: 'info' }
420405
);
@@ -425,6 +410,7 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
425410
],
426411
},
427412
{
413+
id: 'wgcna_params',
428414
type: 'wdkparam',
429415
title: 'Run gene search',
430416
paramNames: ['wgcnaParam', 'wgcna_correlation_cutoff'],
@@ -453,6 +439,7 @@ export const presetNotebooks: Record<string, PresetNotebook> = {
453439
projects: ['MicrobiomeDB'],
454440
cells: [
455441
{
442+
id: 'boxplot_viz',
456443
type: 'visualization',
457444
title: 'Boxplot Visualization',
458445
visualizationName: 'boxplot',

packages/libs/eda/src/lib/notebook/TextNotebookCell.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { useMemo } from 'react';
55
import { NotebookCellPreHeader } from './NotebookCellPreHeader';
66

77
export function TextNotebookCell(props: NotebookCellProps<TextCellDescriptor>) {
8-
const { cell, isDisabled, analysisState, wdkState, stepNumber } = props;
8+
const { cell, isDisabled, analysisState, wdkState, stepNumber, stepNumbers } =
9+
props;
910

1011
const content = useMemo(
1112
() =>
1213
typeof cell.text === 'function'
13-
? cell.text({ analysisState, wdkState })
14+
? cell.text({ analysisState, wdkState, stepNumbers })
1415
: cell.text,
15-
[cell.text, analysisState, wdkState]
16+
[cell.text, analysisState, wdkState, stepNumbers]
1617
);
1718

1819
return (

packages/libs/eda/src/lib/notebook/VisualizationNotebookCell.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function VisualizationNotebookCell(
2323
wdkState,
2424
computeJobStatus,
2525
stepNumber,
26+
stepNumbers,
2627
} = props;
2728
const { analysis, updateVisualization } = analysisState;
2829
if (analysis == null) throw new Error('Cannot find analysis.');
@@ -95,9 +96,15 @@ export function VisualizationNotebookCell(
9596
const vizOptions = useMemo(
9697
() => ({
9798
...vizPlugin?.options,
98-
...getVizPluginOptions?.(wdkState, enqueueSnackbar),
99+
...getVizPluginOptions?.(wdkState, enqueueSnackbar, stepNumbers),
99100
}),
100-
[wdkState, enqueueSnackbar, getVizPluginOptions, vizPlugin?.options]
101+
[
102+
wdkState,
103+
enqueueSnackbar,
104+
getVizPluginOptions,
105+
vizPlugin?.options,
106+
stepNumbers,
107+
]
101108
);
102109

103110
return visualization ? (

0 commit comments

Comments
 (0)