@czi-sds/data-viz 2.1.1 → 2.3.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.
@@ -2,6 +2,7 @@
2
2
  import { HTMLAttributes } from "react";
3
3
  import { DatasetComponentOption, ECharts, EChartsOption, ScatterSeriesOption } from "echarts";
4
4
  import { DiscreteColorGeneratorOptions, TooltipProps, TooltipTableContentProps } from "@czi-sds/components";
5
+ import { PluginUISpec } from "molstar/lib/mol-plugin-ui/spec";
5
6
  //#region src/common/colorScales.d.ts
6
7
  /** RGB triplet with each channel in the range 0-255. */
7
8
  type Rgb = [number, number, number];
@@ -295,14 +296,102 @@ interface ResidueRef {
295
296
  /** Insertion code, or `""` when the residue has none. */
296
297
  insCode: string;
297
298
  }
299
+ /**
300
+ * A chain the viewer found in the structure it loaded, reported through
301
+ * `onChainsChange` so a consumer can label, color or hide chains by name
302
+ * without parsing the structure itself.
303
+ *
304
+ * `chainId` is the file's own name for the chain, the same one `ResidueRef`
305
+ * reports, and the key every chain-keyed prop takes. A chain carrying several
306
+ * symmetry operators appears once, under the first.
307
+ *
308
+ * Describes the chain's polymer. The ligands and ions sitting on it are drawn
309
+ * and are hidden and selected with it, but are not counted here or spanned by
310
+ * the range below - they are no part of the sequence. A chain holding nothing
311
+ * but heteroatoms is left out altogether, having no sequence to describe.
312
+ */
313
+ interface ChainRef {
314
+ /** Chain as named in the file (`auth_asym_id`), e.g. `"A"`. */
315
+ chainId: string;
316
+ /** Chain as the sequence panel captions it. */
317
+ label: string;
318
+ /** Lowest 0-based residue index of the chain's polymer. */
319
+ startIndex: number;
320
+ /** Highest 0-based residue index of the chain's polymer. */
321
+ endIndex: number;
322
+ /** Polymer residues the chain holds. */
323
+ residueCount: number;
324
+ }
325
+ /**
326
+ * What is selected, in the two ways a caller might say it. `null` selects
327
+ * nothing.
328
+ *
329
+ * The two combine: `{ chains: ["A"], residues: [150] }` takes all of chain A
330
+ * plus one residue elsewhere. `chains` is kept as named rather than expanded
331
+ * into indices, so a whole-chain selection survives a round trip through a
332
+ * consumer's state at its original size.
333
+ */
334
+ interface StructureSelection {
335
+ /**
336
+ * 0-based residue indices, counting residues in file order across the whole
337
+ * structure - the same index `plddt` and `residueOverlay` are keyed by.
338
+ */
339
+ residues?: number[];
340
+ /** Whole chains by `chainId`, each standing for every residue on it. */
341
+ chains?: string[];
342
+ }
343
+ /**
344
+ * How large a downloaded image is, in pixels.
345
+ *
346
+ * Named rather than given as dimensions because the aspect is Mol*'s to
347
+ * choose: each of these is one of its own presets, and a size picked here
348
+ * would have to be reconciled with the canvas the image is rendered from.
349
+ */
350
+ type DownloadResolution = "low" | "medium" | "high" | "maximum";
351
+ /** Pixel dimensions each resolution produces, for documentation and labels. */
352
+ declare const DOWNLOAD_RESOLUTIONS: Record<DownloadResolution, string>;
353
+ /**
354
+ * Turns on the capture button under the reset-camera control, and says what it
355
+ * should produce. Omit it and no button is drawn.
356
+ *
357
+ * The image is rendered fresh at the size asked for rather than scaled up from
358
+ * the canvas, so a high resolution costs time rather than sharpness - which is
359
+ * why the default sits in the middle rather than at the top.
360
+ */
361
+ interface StructureDownload {
362
+ /**
363
+ * Size of the image. See `DOWNLOAD_RESOLUTIONS` for the pixel dimensions.
364
+ * @default "medium"
365
+ */
366
+ resolution?: DownloadResolution;
367
+ /**
368
+ * Background behind the structure, as `#RRGGBB`. Omit for a transparent
369
+ * one, which is what a figure usually wants - the viewer's own canvas color
370
+ * is deliberately not inherited, since a screenshot tends to outlive the
371
+ * theme it was taken under.
372
+ */
373
+ backgroundColor?: string;
374
+ /**
375
+ * Draw the orientation axes into the image. Independent of `showAxes`, which
376
+ * is about the view rather than the capture: the widget orients a reader who
377
+ * can turn the structure, and earns its place less in a still.
378
+ * @default false
379
+ */
380
+ showAxes?: boolean;
381
+ /**
382
+ * Name for the downloaded file, without an extension. Defaults to the one
383
+ * Mol* derives from the loaded structure.
384
+ */
385
+ filename?: string;
386
+ }
298
387
  /** A whole-structure statistic shown along the bottom of the viewer. */
299
388
  interface StructureStat {
300
389
  value: string;
301
390
  label: string;
302
391
  }
303
392
  interface ProteinStructureViewerProps extends Omit<HTMLAttributes<HTMLDivElement>, "onSelect"> {
304
- /** Structure to render, as raw PDB text. */
305
- pdb: string;
393
+ /** Structure to render, as raw PDB or mmCIF (PDBx) text. */
394
+ structure: string;
306
395
  /**
307
396
  * Per-residue pLDDT confidence on a 0-1 scale, ordered by residue. When
308
397
  * supplied the structure is colored by pLDDT unless `residueOverlay` takes
@@ -324,6 +413,11 @@ interface ProteinStructureViewerProps extends Omit<HTMLAttributes<HTMLDivElement
324
413
  * @default true
325
414
  */
326
415
  showAxes?: boolean;
416
+ /**
417
+ * Adds a capture button beneath the reset-camera control, which downloads a
418
+ * PNG of the structure as it currently stands. Omit for no button.
419
+ */
420
+ download?: StructureDownload | null;
327
421
  /**
328
422
  * Show the sequence panel pinned along the bottom of the viewer.
329
423
  * @default true
@@ -337,11 +431,64 @@ interface ProteinStructureViewerProps extends Omit<HTMLAttributes<HTMLDivElement
337
431
  /** Per-residue values that override pLDDT coloring while set. */
338
432
  residueOverlay?: ResidueValueOverlay | null;
339
433
  /**
340
- * 0-based index of the selected residue, or null when none is selected.
341
- * Controlled: selecting a residue zooms the camera in on it, and clearing the
342
- * selection zooms back out to the default view.
434
+ * What is selected, or null when nothing is. Controlled: the camera frames
435
+ * whatever the selection covers, and clearing it zooms back out to the
436
+ * default view.
437
+ *
438
+ * Residues are drawn in ball-and-stick over the cartoon; whole chains are
439
+ * left as they are and the chains around them dim, the same as hovering a
440
+ * chain's name.
441
+ */
442
+ selection?: StructureSelection | null;
443
+ /**
444
+ * Chains hidden from the 3D view, by `chainId`. Leave undefined to let the
445
+ * viewer own visibility itself, which is what the chain legend's toggles
446
+ * drive; passing it takes that over, and the toggles then only report.
343
447
  */
344
- selectedResidue?: number | null;
448
+ hiddenChains?: string[];
449
+ /**
450
+ * Color per chain, by `chainId`, as `#RRGGBB`. Chains left out fall back to
451
+ * the viewer's palette. Only visible while chain coloring is what is on
452
+ * screen, which is when neither `plddt` nor `residueOverlay` is set.
453
+ */
454
+ chainColors?: Record<string, string>;
455
+ /**
456
+ * Show the chain legend, which lists each chain with its color and a
457
+ * visibility toggle. Ignored on a single-chain structure, where there is
458
+ * nothing to tell apart or hide.
459
+ * @default true
460
+ */
461
+ showChainLegend?: boolean;
462
+ /**
463
+ * Stop other chains from dimming in the 3D view while a chain's name is
464
+ * pointed at, in the legend or above its grid in the sequence panel.
465
+ *
466
+ * The dim is on by default, since on a complex it is how a reader finds out
467
+ * which chain is which. Turn it off where the movement is more distracting
468
+ * than the answer is useful - a grid of viewers a pointer crosses on its way
469
+ * somewhere else, or a page driving its own highlighting through `selection`.
470
+ * @default false
471
+ */
472
+ disableChainHighlightOnHover?: boolean;
473
+ /**
474
+ * Mol* plugin spec laid over the viewer's own, which is how the whole of
475
+ * Mol*'s configuration is reachable without a prop here for each setting.
476
+ * Anything named here wins, so `canvas3d.postprocessing`, a `PluginConfig`
477
+ * item, or `layout.initial` can all be set to something other than the
478
+ * default the viewer picked.
479
+ *
480
+ * List-valued keys - `behaviors`, `config`, `actions`, `animations`,
481
+ * `customFormats`, `customParamEditors` - are appended to rather than
482
+ * replaced. For `config` that is what lets an entry override the viewer's,
483
+ * since Mol* reads the list in order. It also means a behavior cannot be
484
+ * taken away: the ones the viewer drops stay dropped, and the ones it keeps
485
+ * cannot be removed from here.
486
+ *
487
+ * Read once, when the plugin is created, except for `canvas3d`, which is
488
+ * re-applied whenever it changes. Creating the plugin throws away the camera,
489
+ * so the rest is deliberately not reactive.
490
+ */
491
+ molstarSpec?: Partial<PluginUISpec>;
345
492
  /**
346
493
  * Up to three whole-structure stats shown along the bottom. A null entry
347
494
  * reserves its column without rendering anything, so the columns never shift
@@ -355,25 +502,74 @@ interface ProteinStructureViewerProps extends Omit<HTMLAttributes<HTMLDivElement
355
502
  * the structure.
356
503
  */
357
504
  onResidueHover?: (residue: ResidueRef | null) => void;
358
- /** Called when the user clicks empty space, clearing the selection. */
359
- onSelectionClear?: () => void;
505
+ /**
506
+ * Called with the new selection whenever the user makes one - clicking a
507
+ * residue, dragging across the sequence, clicking a chain caption - and with
508
+ * `null` when they click empty space to clear it.
509
+ *
510
+ * A whole-chain selection arrives as `{ chains: [id] }` rather than as every
511
+ * index on it, so echoing it straight back into `selection` costs nothing.
512
+ */
513
+ onSelectionChange?: (selection: StructureSelection | null) => void;
514
+ /**
515
+ * Called with the chains found in the structure, whenever a structure is
516
+ * loaded. Fires with `[]` when the structure holds none.
517
+ */
518
+ onChainsChange?: (chains: ChainRef[]) => void;
519
+ /**
520
+ * Called with the chains now hidden when a visibility toggle is used. Fires
521
+ * whether or not `hiddenChains` is controlled, so a consumer can follow the
522
+ * viewer's own state without owning it.
523
+ */
524
+ onChainVisibilityChange?: (hiddenChains: string[]) => void;
360
525
  }
361
526
  /**
362
- * Per-residue readout that replaces the whole-structure stats while a residue
363
- * is hovered or selected.
527
+ * Readout that replaces the whole-structure stats while something is hovered
528
+ * or selected. Covers one residue or many: a drag across the sequence and a
529
+ * whole-chain selection report through this too, as a mean over what they
530
+ * cover.
364
531
  */
365
532
  interface ResidueReadout {
366
- /** e.g. "PHE 17" */
533
+ /** e.g. "PHE 17", "Chain A", or "24 residues". */
367
534
  label: string;
368
- /** Residue pLDDT on a 0-1 scale, or null when unavailable. */
535
+ /**
536
+ * pLDDT on a 0-1 scale, or null when unavailable. The mean across the
537
+ * residues covered when there is more than one, ignoring those without a
538
+ * score.
539
+ */
369
540
  plddt: number | null;
370
541
  /**
371
- * Residue overlay value, or null when the overlay holds none for it - which
372
- * is also what a structure paints neutral - or when no overlay is set.
542
+ * Overlay value, or null when the overlay holds none - which is also what a
543
+ * structure paints neutral - or when no overlay is set. The mean across the
544
+ * residues covered when there is more than one, ignoring those the overlay
545
+ * says nothing about.
373
546
  */
374
547
  value: number | null;
548
+ /**
549
+ * Residues the readout covers, which is what makes the numbers above means
550
+ * rather than readings. 1 for a single residue.
551
+ */
552
+ residueCount: number;
375
553
  }
376
554
  //#endregion
555
+ //#region src/core/ProteinStructureViewer/utils/structureFormat.d.ts
556
+ /**
557
+ * Structure text formats Mol* can parse from the viewer's `structure` prop.
558
+ *
559
+ * `"mmcif"` covers both mmCIF and PDBx; they are the same text format, and
560
+ * that is the name Mol*'s trajectory parser uses. Binary CIF (`.bcif`) is not
561
+ * accepted: the prop is a string.
562
+ */
563
+ type StructureFormat = "pdb" | "mmcif";
564
+ /**
565
+ * Infers whether `text` is PDB or mmCIF (PDBx).
566
+ *
567
+ * mmCIF documents start with a `data_` block and name their coordinates
568
+ * `_atom_site.`. PDB never does either, so either marker is enough. A leading
569
+ * comment (`# ...`) before `data_` is still mmCIF.
570
+ */
571
+ declare function detectStructureFormat(text: string): StructureFormat;
572
+ //#endregion
377
573
  //#region src/core/ProteinStructureViewer/utils/plddt.d.ts
378
574
  /**
379
575
  * AlphaFold's pLDDT confidence bands. Thresholds are on the 0-1 scale that
@@ -392,6 +588,23 @@ declare const PLDDT_COLOR_SCALE: ColorScale;
392
588
  * them its neighbour's score.
393
589
  */
394
590
  declare function injectPlddtIntoPdb(pdbData: string, plddtValues: number[]): string;
591
+ /**
592
+ * Rewrites an mmCIF (PDBx) file's `_atom_site.B_iso_or_equiv` column with
593
+ * pLDDT scores so Mol* can read them off the parsed model, the same way
594
+ * `injectPlddtIntoPdb` rewrites the PDB B-factor column. Scores arrive on a
595
+ * 0-1 scale and are stored on the conventional 0-100 one. Residues past the
596
+ * end of `plddtValues` fall back to a mid-confidence 50.
597
+ *
598
+ * If the file has no B-factor column, one is appended to the atom-site loop
599
+ * rather than leaving the scores behind.
600
+ */
601
+ declare function injectPlddtIntoMmcif(mmcifData: string, plddtValues: number[]): string;
602
+ /**
603
+ * Rewrites a structure file's B-factors with pLDDT scores. Dispatches to
604
+ * `injectPlddtIntoPdb` or `injectPlddtIntoMmcif` from `format`, or from
605
+ * detecting the format of `data` when `format` is omitted.
606
+ */
607
+ declare function injectPlddt(data: string, plddtValues: number[], format?: StructureFormat): string;
395
608
  //#endregion
396
609
  //#region src/core/ProteinStructureViewer/index.d.ts
397
610
  declare const _default$1: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<ProteinStructureViewerProps & import("react").RefAttributes<HTMLDivElement>>>;
@@ -557,4 +770,4 @@ interface StackedBarChartProps extends HTMLAttributes<HTMLDivElement> {
557
770
  //#region src/core/StackedBarChart/index.d.ts
558
771
  declare const StackedBarChart: (props: StackedBarChartProps) => JSX.Element;
559
772
  //#endregion
560
- export { type ColorScale, type ContinuousColorStop, _default as HeatmapChart, HeatmapChartProps, PLASMA_COLOR_SCALE, PLDDT_COLOR_SCALE, _default$1 as ProteinStructureViewer, ProteinStructureViewerProps, ResidueReadout, ResidueRef, ResidueValueOverlay, StackedBarChart, type StackedBarChartDataItem, type StackedBarChartProps, type SteppedColorStop, StructureStat, injectPlddtIntoPdb, sampleColorScale, toCssGradient };
773
+ export { ChainRef, type ColorScale, type ContinuousColorStop, DOWNLOAD_RESOLUTIONS, DownloadResolution, _default as HeatmapChart, HeatmapChartProps, PLASMA_COLOR_SCALE, PLDDT_COLOR_SCALE, _default$1 as ProteinStructureViewer, ProteinStructureViewerProps, ResidueReadout, ResidueRef, ResidueValueOverlay, StackedBarChart, type StackedBarChartDataItem, type StackedBarChartProps, type SteppedColorStop, StructureDownload, type StructureFormat, StructureSelection, StructureStat, detectStructureFormat, injectPlddt, injectPlddtIntoMmcif, injectPlddtIntoPdb, sampleColorScale, toCssGradient };