jbrowse-plugin-protein3d 1.26.0 → 1.26.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 (130) hide show
  1. package/dist/LaunchProteinView/components/PdbSearch.js +14 -3
  2. package/dist/LaunchProteinView/components/StructureSourcePicker.js +7 -4
  3. package/dist/LaunchProteinView/components/UserProvidedStructure.js +7 -3
  4. package/dist/LaunchProteinView/hooks/useAlphaFoldDBSearch.js +1 -1
  5. package/dist/LaunchProteinView/hooks/useAlphaFoldData.js +3 -3
  6. package/dist/LaunchProteinView/resolveGeneLaunch.js +14 -7
  7. package/dist/LaunchProteinViewExtensionPoint/launchProteinView.js +3 -3
  8. package/dist/LaunchProteinViewExtensionPoint/normalizeAnnotationLaunch.js +1 -11
  9. package/dist/LaunchProteinViewExtensionPoint/normalizeLaunch.js +46 -6
  10. package/dist/ProteinView/alignmentSites.js +20 -12
  11. package/dist/ProteinView/applyColorTheme.js +17 -21
  12. package/dist/ProteinView/clinVarSource.js +4 -2
  13. package/dist/ProteinView/colorScale.js +2 -1
  14. package/dist/ProteinView/components/GenomeTrackColorDialog.js +14 -2
  15. package/dist/ProteinView/measurements.js +1 -1
  16. package/dist/ProteinView/model.js +17 -0
  17. package/dist/ProteinView/proteinColor.js +2 -1
  18. package/dist/ProteinView/removeStructure.js +25 -17
  19. package/dist/ProteinView/residueMarks.js +5 -5
  20. package/dist/ProteinView/serialPerPlugin.js +10 -12
  21. package/dist/ProteinView/sessionHighlights.js +18 -18
  22. package/dist/ProteinView/structureCells.js +25 -0
  23. package/dist/ProteinView/structureModel.js +19 -2
  24. package/dist/ProteinView/structurePipeline.js +24 -7
  25. package/dist/ProteinView/structureVisibility.js +13 -8
  26. package/dist/ProteinView/superposeStructures.js +5 -1
  27. package/dist/ProteinView/surface.js +7 -3
  28. package/dist/ProteinView/valueScale.js +14 -3
  29. package/dist/chunks/GenomeTrackColorDialog-WJQNAUV3.js +2 -0
  30. package/dist/chunks/{GenomeTrackColorDialog-FDQKUBYA.js.map → GenomeTrackColorDialog-WJQNAUV3.js.map} +3 -3
  31. package/dist/chunks/LaunchProteinViewDialog-WVFGF2HL.js +2 -0
  32. package/dist/chunks/LaunchProteinViewDialog-WVFGF2HL.js.map +7 -0
  33. package/dist/chunks/{ProteinView-56FHBQSV.js → ProteinView-IYF52HYP.js} +3 -3
  34. package/dist/chunks/{chunk-WHJFF2WE.js → chunk-4QUS35JT.js} +2 -2
  35. package/dist/chunks/chunk-62VIRECC.js +2 -0
  36. package/dist/chunks/chunk-62VIRECC.js.map +7 -0
  37. package/dist/chunks/{chunk-FRK6X72I.js → chunk-GND6AQKJ.js} +2 -2
  38. package/dist/chunks/chunk-HOQSHQW5.js +2 -0
  39. package/dist/chunks/chunk-HOQSHQW5.js.map +7 -0
  40. package/dist/chunks/chunk-LHMM35YG.js +2 -0
  41. package/dist/chunks/chunk-LHMM35YG.js.map +7 -0
  42. package/dist/chunks/{chunk-ZJ4MV3RK.js → chunk-QW32NNHJ.js} +2 -2
  43. package/dist/chunks/{chunk-ZJ4MV3RK.js.map → chunk-QW32NNHJ.js.map} +2 -2
  44. package/dist/chunks/chunk-R4MOJI76.js +2 -0
  45. package/dist/chunks/{chunk-6B7WZJO7.js.map → chunk-R4MOJI76.js.map} +4 -4
  46. package/dist/chunks/chunk-RGQ2CMGW.js +2 -0
  47. package/dist/chunks/chunk-RGQ2CMGW.js.map +7 -0
  48. package/dist/chunks/{chunk-2WSEMZUR.js → chunk-RYRIX2KR.js} +2 -2
  49. package/dist/chunks/{chunk-2WSEMZUR.js.map → chunk-RYRIX2KR.js.map} +3 -3
  50. package/dist/chunks/chunk-TRAGDWEM.js +2 -0
  51. package/dist/chunks/chunk-TRAGDWEM.js.map +7 -0
  52. package/dist/chunks/{clinVarSource-YZSKOR5L.js → clinVarSource-XTPLVQDM.js} +2 -2
  53. package/dist/chunks/launchAnnotationView-2RKNVVHA.js +2 -0
  54. package/dist/chunks/launchAnnotationView-2RKNVVHA.js.map +7 -0
  55. package/dist/chunks/launchProteinView-JW4YPHW7.js +2 -0
  56. package/dist/chunks/launchProteinView-JW4YPHW7.js.map +7 -0
  57. package/dist/chunks/{launchViewUtils-JLW2J4TI.js → launchViewUtils-AVXWFYSV.js} +2 -2
  58. package/dist/chunks/model-G7I4KFGC.js +2 -0
  59. package/dist/chunks/model-G7I4KFGC.js.map +7 -0
  60. package/dist/chunks/{molstarExports-ZC2DCGMF.js → molstarExports-D5CVDS4O.js} +2 -2
  61. package/dist/chunks/{resolveGeneLaunch-NI4BGFX5.js → resolveGeneLaunch-VBVWSDZI.js} +2 -2
  62. package/dist/jbrowse-plugin-protein3d.esm.js +1 -1
  63. package/dist/jbrowse-plugin-protein3d.esm.js.map +1 -1
  64. package/dist/version.js +1 -1
  65. package/package.json +1 -1
  66. package/src/LaunchProteinView/components/PdbSearch.tsx +16 -4
  67. package/src/LaunchProteinView/components/StructureSourcePicker.tsx +6 -1
  68. package/src/LaunchProteinView/components/UserProvidedStructure.tsx +7 -2
  69. package/src/LaunchProteinView/hooks/useAlphaFoldDBSearch.ts +1 -1
  70. package/src/LaunchProteinView/hooks/useAlphaFoldData.ts +4 -1
  71. package/src/LaunchProteinView/resolveGeneLaunch.test.ts +13 -0
  72. package/src/LaunchProteinView/resolveGeneLaunch.ts +16 -4
  73. package/src/LaunchProteinViewExtensionPoint/launchProteinView.ts +11 -13
  74. package/src/LaunchProteinViewExtensionPoint/normalizeAnnotationLaunch.ts +1 -15
  75. package/src/LaunchProteinViewExtensionPoint/normalizeLaunch.test.ts +26 -0
  76. package/src/LaunchProteinViewExtensionPoint/normalizeLaunch.ts +82 -7
  77. package/src/ProteinView/alignmentSites.test.ts +32 -0
  78. package/src/ProteinView/alignmentSites.ts +30 -12
  79. package/src/ProteinView/applyColorTheme.ts +24 -39
  80. package/src/ProteinView/clinVarSource.ts +4 -2
  81. package/src/ProteinView/colorScale.ts +2 -1
  82. package/src/ProteinView/components/GenomeTrackColorDialog.tsx +15 -2
  83. package/src/ProteinView/measurements.ts +1 -1
  84. package/src/ProteinView/model.test.ts +20 -0
  85. package/src/ProteinView/model.ts +21 -0
  86. package/src/ProteinView/proteinColor.test.ts +15 -0
  87. package/src/ProteinView/proteinColor.ts +2 -1
  88. package/src/ProteinView/removeStructure.ts +34 -20
  89. package/src/ProteinView/residueMarks.ts +9 -5
  90. package/src/ProteinView/serialPerPlugin.ts +11 -14
  91. package/src/ProteinView/sessionHighlights.test.ts +90 -0
  92. package/src/ProteinView/sessionHighlights.ts +34 -29
  93. package/src/ProteinView/structureCells.ts +46 -0
  94. package/src/ProteinView/structureModel.test.ts +24 -0
  95. package/src/ProteinView/structureModel.ts +19 -2
  96. package/src/ProteinView/structurePipeline.ts +25 -7
  97. package/src/ProteinView/structureVisibility.test.ts +40 -0
  98. package/src/ProteinView/structureVisibility.ts +17 -12
  99. package/src/ProteinView/superposeStructures.ts +9 -1
  100. package/src/ProteinView/surface.ts +8 -3
  101. package/src/ProteinView/valueScale.test.ts +28 -0
  102. package/src/ProteinView/valueScale.ts +16 -3
  103. package/src/version.ts +1 -1
  104. package/dist/chunks/GenomeTrackColorDialog-FDQKUBYA.js +0 -2
  105. package/dist/chunks/LaunchProteinViewDialog-PC5HYIE3.js +0 -2
  106. package/dist/chunks/LaunchProteinViewDialog-PC5HYIE3.js.map +0 -7
  107. package/dist/chunks/chunk-6B7WZJO7.js +0 -2
  108. package/dist/chunks/chunk-6OAZLCO5.js +0 -2
  109. package/dist/chunks/chunk-6OAZLCO5.js.map +0 -7
  110. package/dist/chunks/chunk-DFLRALX5.js +0 -2
  111. package/dist/chunks/chunk-DFLRALX5.js.map +0 -7
  112. package/dist/chunks/chunk-LK7TA465.js +0 -2
  113. package/dist/chunks/chunk-LK7TA465.js.map +0 -7
  114. package/dist/chunks/chunk-NUJCOEJ3.js +0 -2
  115. package/dist/chunks/chunk-NUJCOEJ3.js.map +0 -7
  116. package/dist/chunks/chunk-RL54DUYZ.js +0 -2
  117. package/dist/chunks/chunk-RL54DUYZ.js.map +0 -7
  118. package/dist/chunks/launchAnnotationView-XEUIILD5.js +0 -2
  119. package/dist/chunks/launchAnnotationView-XEUIILD5.js.map +0 -7
  120. package/dist/chunks/launchProteinView-XUNPJWEY.js +0 -2
  121. package/dist/chunks/launchProteinView-XUNPJWEY.js.map +0 -7
  122. package/dist/chunks/model-QDSVZCTN.js +0 -2
  123. package/dist/chunks/model-QDSVZCTN.js.map +0 -7
  124. /package/dist/chunks/{ProteinView-56FHBQSV.js.map → ProteinView-IYF52HYP.js.map} +0 -0
  125. /package/dist/chunks/{chunk-WHJFF2WE.js.map → chunk-4QUS35JT.js.map} +0 -0
  126. /package/dist/chunks/{chunk-FRK6X72I.js.map → chunk-GND6AQKJ.js.map} +0 -0
  127. /package/dist/chunks/{clinVarSource-YZSKOR5L.js.map → clinVarSource-XTPLVQDM.js.map} +0 -0
  128. /package/dist/chunks/{launchViewUtils-JLW2J4TI.js.map → launchViewUtils-AVXWFYSV.js.map} +0 -0
  129. /package/dist/chunks/{molstarExports-ZC2DCGMF.js.map → molstarExports-D5CVDS4O.js.map} +0 -0
  130. /package/dist/chunks/{resolveGeneLaunch-NI4BGFX5.js.map → resolveGeneLaunch-VBVWSDZI.js.map} +0 -0
@@ -95,10 +95,16 @@ const PdbSearch = observer(function PdbSearch({ feature, preferredTranscriptId,
95
95
  // whichever entry the table had selected instead
96
96
  const launchWaiting = typedPdbIdInvalid ||
97
97
  (typedIdOverrides ? isoformStatuses.some(Boolean) : isLoading);
98
+ // RCSB answering that it has no such entry, as opposed to failing to
99
+ // answer, means the launch would open a view on a 404
100
+ const typedIdUnknown = typedIdOverrides &&
101
+ entryError instanceof Error &&
102
+ 'status' in entryError &&
103
+ entryError.status === 404;
98
104
  const launchError = typedIdOverrides
99
105
  ? launchWaiting
100
106
  ? undefined
101
- : isoformError
107
+ : (isoformError ?? (typedIdUnknown ? entryError : undefined))
102
108
  : error;
103
109
  // Loading or failed, the lookup can still hold the previous query's
104
110
  // accession, which would name the view and its 1D entry
@@ -112,10 +118,15 @@ const PdbSearch = observer(function PdbSearch({ feature, preferredTranscriptId,
112
118
  React.createElement(UniProtLookupResults, { lookup: lookup }),
113
119
  React.createElement(TextField, { size: "small", label: "PDB ID", placeholder: "e.g. 1TUP", helperText: typedPdbIdInvalid
114
120
  ? 'A PDB ID is four characters beginning with a digit'
115
- : 'Overrides the selection below', error: typedPdbIdInvalid, value: typedPdbId, onChange: event => {
121
+ : typedIdUnknown
122
+ ? `RCSB has no entry ${debouncedTypedPdbId.toUpperCase()}`
123
+ : 'Overrides the selection below', error: typedPdbIdInvalid || typedIdUnknown, value: typedPdbId, onChange: event => {
116
124
  setTypedPdbId(event.target.value);
117
125
  }, slotProps: { inputLabel: { shrink: true } }, sx: { width: 240 } }),
118
- uniprotId && entries && !isPdbLoading ? (entries.length > 0 ? (React.createElement(PdbResultsTable, { entries: entries, selectedPdbId: selectedPdbId, onSelect: setUserPdbId })) : (React.createElement(Typography, null,
126
+ uniprotId && entries && !isPdbLoading ? (entries.length > 0 ? (React.createElement(PdbResultsTable, { entries: entries, selectedPdbId: selectedPdbId, onSelect: pdbId => {
127
+ setUserPdbId(pdbId);
128
+ setTypedPdbId('');
129
+ } })) : (React.createElement(Typography, null,
119
130
  "RCSB lists no experimental structure for",
120
131
  ' ',
121
132
  React.createElement(ExternalLink, { href: uniprotEntryUrl(uniprotId) }, uniprotId),
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { Button, FormControl, FormControlLabel, Radio, RadioGroup, TextField, Typography, } from '@mui/material';
3
3
  import HelpButton from './HelpButton';
4
4
  import { STRUCTURE_FILE_ACCEPT } from '../utils/readStructureFile';
5
- export default function StructureSourcePicker({ choice, setChoice, structureURL, setStructureURL, setFile, }) {
5
+ export default function StructureSourcePicker({ choice, setChoice, structureURL, setStructureURL, file, setFile, }) {
6
6
  return (React.createElement("div", { style: { display: 'flex', margin: 30 } },
7
7
  React.createElement(Typography, null,
8
8
  "Open your structure file ",
@@ -11,8 +11,8 @@ export default function StructureSourcePicker({ choice, setChoice, structureURL,
11
11
  React.createElement(RadioGroup, { value: choice, onChange: event => {
12
12
  setChoice(event.target.value);
13
13
  } },
14
- React.createElement(FormControlLabel, { value: "url", control: React.createElement(Radio, null), label: "URL" }),
15
- React.createElement(FormControlLabel, { value: "file", control: React.createElement(Radio, null), label: "File" }))),
14
+ React.createElement(FormControlLabel, { value: "file", control: React.createElement(Radio, null), label: "File" }),
15
+ React.createElement(FormControlLabel, { value: "url", control: React.createElement(Radio, null), label: "URL" }))),
16
16
  choice === 'url' ? (React.createElement("div", null,
17
17
  React.createElement(Typography, null, "Open a PDB/mmCIF/etc. file from remote URL"),
18
18
  React.createElement(TextField, { label: "URL", value: structureURL, onChange: event => {
@@ -26,5 +26,8 @@ export default function StructureSourcePicker({ choice, setChoice, structureURL,
26
26
  if (f) {
27
27
  setFile(f);
28
28
  }
29
- } }))))));
29
+ // picking the same file again, edited, fires a change
30
+ target.value = '';
31
+ } })),
32
+ file ? React.createElement(Typography, { variant: "body2" }, file.name) : null))));
30
33
  }
@@ -51,7 +51,10 @@ const UserProvidedStructure = observer(function UserProvidedStructure({ feature,
51
51
  structureSequences,
52
52
  preferredTranscriptId,
53
53
  });
54
- const error = isoformError ?? fileError ?? launchError;
54
+ const error = launchError ?? isoformError ?? fileError;
55
+ // a structure that failed to read would open an empty view; an error from
56
+ // the url as it stood before the latest typing does not count
57
+ const readFailed = !!fileError && activeURL === debouncedURL;
55
58
  // Until the structure is read the ranking has none and orders the isoforms
56
59
  // by length, so a launch that takes the ranked default waits. The
57
60
  // right-clicked isoform needs no ranking and launches at once.
@@ -61,6 +64,7 @@ const UserProvidedStructure = observer(function UserProvidedStructure({ feature,
61
64
  !!protein &&
62
65
  !!selectedTranscript &&
63
66
  !awaitsStructure &&
67
+ !readFailed &&
64
68
  !launching;
65
69
  const sequencesDiffer = !!protein?.seq &&
66
70
  !!structureSequence &&
@@ -85,12 +89,12 @@ const UserProvidedStructure = observer(function UserProvidedStructure({ feature,
85
89
  React.createElement(DialogContent, { className: classes.dialogContent },
86
90
  error ? React.createElement(ErrorMessage, { error: error }) : null,
87
91
  React.createElement(HelpText, null),
88
- React.createElement(StructureSourcePicker, { choice: choice, setChoice: setChoice, structureURL: structureURL, setStructureURL: setStructureURL, setFile: setFile }),
92
+ React.createElement(StructureSourcePicker, { choice: choice, setChoice: setChoice, structureURL: structureURL, setStructureURL: setStructureURL, file: file, setFile: setFile }),
89
93
  React.createElement("div", { style: { margin: 20 } },
90
94
  isStructureLoading ? (React.createElement(LoadingEllipses, { variant: "subtitle2", message: "Reading residues from the structure" })) : null,
91
95
  React.createElement(PartialFailureNotice, { message: isoformPartialFailure }),
92
96
  isRanking ? (React.createElement(LoadingEllipses, { variant: "subtitle2", message: "Aligning isoforms to the structure" })) : null,
93
- isoformSequences ? (structureSequence && ranking ? (React.createElement(TranscriptSelector, { val: userSelection, setVal: setUserSelection, structureSequence: structureSequence, isoforms: options, feature: feature, ranking: ranking })) : null) : (React.createElement(LoadingEllipses, { title: "Loading protein sequences", variant: "h6" })))),
97
+ isoformSequences ? (ranking ? (React.createElement(TranscriptSelector, { val: userSelection, setVal: setUserSelection, structureSequence: structureSequence, isoforms: options, feature: feature, ranking: ranking })) : null) : (React.createElement(LoadingEllipses, { title: "Loading protein sequences", variant: "h6" })))),
94
98
  React.createElement(DialogActions, null,
95
99
  sequencesDiffer ? React.createElement(SequenceMismatchNotice, null) : null,
96
100
  React.createElement(Button, { variant: "contained", color: "secondary", onClick: () => {
@@ -4,7 +4,7 @@ import useAlphaFoldData from './useAlphaFoldData';
4
4
  import useTranscriptIsoformSelection from './useTranscriptIsoformSelection';
5
5
  export default function useAlphaFoldDBSearch({ feature, view, lookup, preferredTranscriptId, }) {
6
6
  const { uniprotId, isLookupLoading } = lookup;
7
- const { isLoading: isAlphaFoldLoading, isValidating: isAlphaFoldValidating, modelsUnreachable, model, noModel, } = useAlphaFoldData({ uniprotId, feature, view });
7
+ const { isLoading: isAlphaFoldLoading, isValidating: isAlphaFoldValidating, modelsUnreachable, model, noModel, } = useAlphaFoldData({ uniprotId, feature, view, preferredTranscriptId });
8
8
  // a stable array, or the isoform picker realigns on every render
9
9
  const modelSequence = model?.sequence;
10
10
  const structureSequences = useMemo(() => (modelSequence ? [modelSequence] : undefined), [modelSequence]);
@@ -8,14 +8,14 @@ import { launchAlphaFoldModel } from '../resolveGeneLaunch';
8
8
  * The AlphaFold DB model a launch opens for this gene's accession, the
9
9
  * canonical file when the API does not answer.
10
10
  */
11
- export default function useAlphaFoldData({ uniprotId, feature, view, }) {
11
+ export default function useAlphaFoldData({ uniprotId, feature, view, preferredTranscriptId, }) {
12
12
  const { data, isLoading, isValidating, error } = useSWR(uniprotId ? ['alphafold-models', uniprotId] : null, ([, id]) => fetchAlphaFoldModels(id), { ...STATIC_SWR_OPTIONS, keepPreviousData: true });
13
13
  const { isoformSequences } = useIsoformProteinSequences({ feature, view });
14
14
  // keepPreviousData hands back the last accession's models after an error
15
15
  // and after the accession is cleared, when the key is null
16
16
  const model = useMemo(() => uniprotId && (data || error)
17
- ? launchAlphaFoldModel(uniprotId, error ? undefined : data, isoformSequences)
18
- : undefined, [uniprotId, data, error, isoformSequences]);
17
+ ? launchAlphaFoldModel(uniprotId, error ? undefined : data, isoformSequences, preferredTranscriptId)
18
+ : undefined, [uniprotId, data, error, isoformSequences, preferredTranscriptId]);
19
19
  const modelsUnreachable = uniprotId ? error : undefined;
20
20
  return {
21
21
  isLoading,
@@ -1,5 +1,5 @@
1
1
  import { getConf } from '@jbrowse/core/configuration';
2
- import { fetchAlphaFoldModels, getAlphaFoldStructureUrl, pickAlphaFoldModel, searchUniProtEntries, } from 'p2s_mapper';
2
+ import { fetchAlphaFoldModels, getAlphaFoldStructureUrl, pickAlphaFoldModel, searchUniProtEntries, stripStopCodon, } from 'p2s_mapper';
3
3
  import { codingTranscripts, flaggedTranscriptId } from './codingFeature';
4
4
  import { rankIsoforms, rankedTranscriptId, } from '../AlignTranscriptRpc/isoformRanking';
5
5
  import { fetchTranscriptProteinSeqs } from './utils/translateTranscripts';
@@ -9,12 +9,19 @@ import { alignOffThread } from '../ProteinView/alignOffThread';
9
9
  * The AlphaFold file a launch opens, `models` undefined when the API did not
10
10
  * answer. That says nothing about the accession, so the spelled canonical
11
11
  * filename is worth a try; an API answering with no models has said there is
12
- * nothing to open. The structure loader draws the same line.
12
+ * nothing to open. The structure loader draws the same line. An isoform the
13
+ * user right-clicked opens its own model when AlphaFold DB has one, where the
14
+ * pick over every isoform would take the canonical model first.
13
15
  */
14
- export function launchAlphaFoldModel(uniprotId, models, isoformSequences) {
15
- return models
16
- ? pickAlphaFoldModel(models, isoformSequences)
17
- : { accession: uniprotId, url: getAlphaFoldStructureUrl(uniprotId) };
16
+ export function launchAlphaFoldModel(uniprotId, models, isoformSequences, preferredTranscriptId) {
17
+ if (!models) {
18
+ return { accession: uniprotId, url: getAlphaFoldStructureUrl(uniprotId) };
19
+ }
20
+ const preferred = preferredTranscriptId === undefined
21
+ ? undefined
22
+ : isoformSequences?.[preferredTranscriptId];
23
+ const own = preferred && models.find(m => m.sequence === stripStopCodon(preferred.seq));
24
+ return own ?? pickAlphaFoldModel(models, isoformSequences);
18
25
  }
19
26
  /** Why a resolved gene has no structure to open. */
20
27
  export function describeMissingStructure(geneName, { uniprotId, lookupError }) {
@@ -113,7 +120,7 @@ export async function resolveGeneLaunch({ host, feature, preferredTranscriptId,
113
120
  seq: t.seq,
114
121
  }));
115
122
  const model = uniprotId
116
- ? launchAlphaFoldModel(uniprotId, await host.fetchAlphaFoldModels(uniprotId).catch(() => undefined), Object.fromEntries(isoforms.map(i => [i.id, { seq: i.seq ?? '' }])))
123
+ ? launchAlphaFoldModel(uniprotId, await host.fetchAlphaFoldModels(uniprotId).catch(() => undefined), Object.fromEntries(isoforms.map(i => [i.id, { seq: i.seq ?? '' }])), preferredTranscriptId)
117
124
  : undefined;
118
125
  const url = model?.url;
119
126
  const structureSequences = model?.sequence ? [model.sequence] : [];
@@ -31,8 +31,7 @@ export function launchViewSettings({ alignmentAlgorithm, color, colorScheme, ...
31
31
  * `jb.addView` the launch failed rather than that it opened a genome view.
32
32
  */
33
33
  export async function launchProteinView(args) {
34
- const { session, uniprotId, transcriptId, userProvidedTranscriptSequence, feature, connectedViewId, connectedView: givenConnectedView, gene, sideBySide, } = args;
35
- const { session: _session, ...launch } = args;
34
+ const { session, ...launch } = args;
36
35
  const normalized = normalizeLaunch(launch);
37
36
  for (const warning of normalized.warnings) {
38
37
  console.warn(warning);
@@ -41,7 +40,8 @@ export async function launchProteinView(args) {
41
40
  if ('error' in normalized) {
42
41
  throw new Error(normalized.error);
43
42
  }
44
- const { geneModel } = normalized;
43
+ const { geneModel, linkage } = normalized;
44
+ const { uniprotId, transcriptId, userProvidedTranscriptSequence, feature, connectedViewId, connectedView: givenConnectedView, gene, sideBySide, } = linkage;
45
45
  const settings = launchViewSettings(normalized.settings);
46
46
  // A gene name alone: the host's text search finds the gene, and the
47
47
  // launch dialog's defaults pick its isoform and AlphaFold model. A
@@ -1,4 +1,4 @@
1
- import { isRecord, isString } from './normalizeLaunch';
1
+ import { isConnectedViewSpec, isString } from './normalizeLaunch';
2
2
  const ANNOTATION_KEYS = [
3
3
  'uniprotId',
4
4
  'gene',
@@ -9,16 +9,6 @@ const ANNOTATION_KEYS = [
9
9
  function isAnnotationKey(key) {
10
10
  return ANNOTATION_KEYS.some(k => k === key);
11
11
  }
12
- function isTrackSpec(value) {
13
- return isString(value) || isRecord(value);
14
- }
15
- function isConnectedViewSpec(value) {
16
- return (isRecord(value) &&
17
- (value.loc === undefined || isString(value.loc)) &&
18
- (value.assembly === undefined || isString(value.assembly)) &&
19
- (value.tracks === undefined ||
20
- (Array.isArray(value.tracks) && value.tracks.every(isTrackSpec))));
21
- }
22
12
  /**
23
13
  * A `ProteinAnnotationView` spec out of untyped fields. An unknown key or a
24
14
  * value of the wrong type is reported and left out; only a launch naming no
@@ -72,6 +72,16 @@ export function isPairwiseAlignment(value) {
72
72
  value.alns.length === 2 &&
73
73
  value.alns.every(isAlignmentRow));
74
74
  }
75
+ function isTrackSpec(value) {
76
+ return isString(value) || isRecord(value);
77
+ }
78
+ export function isConnectedViewSpec(value) {
79
+ return (isRecord(value) &&
80
+ (value.loc === undefined || isString(value.loc)) &&
81
+ (value.assembly === undefined || isString(value.assembly)) &&
82
+ (value.tracks === undefined ||
83
+ (Array.isArray(value.tracks) && value.tracks.every(isTrackSpec))));
84
+ }
75
85
  const RANGES = '{ start, end } numbers or an array of them';
76
86
  /**
77
87
  * Launch text comes from a url, and the view model throws on a wrongly typed
@@ -95,6 +105,22 @@ const LAUNCH_KEYS = [
95
105
  'connectedView',
96
106
  'sideBySide',
97
107
  ];
108
+ // `uniprotId` is a structure's source too, which readStructure reports, so
109
+ // a wrongly typed one is left out here without a second warning
110
+ function readLinkage(fields, warnings) {
111
+ const read = fieldReader(fields, key => `\`${key}\``, warnings);
112
+ const uniprotId = fields.get('uniprotId');
113
+ return {
114
+ gene: read('gene', isString, 'a string'),
115
+ transcriptId: read('transcriptId', isString, 'a string'),
116
+ uniprotId: isString(uniprotId) ? uniprotId : undefined,
117
+ connectedView: read('connectedView', isConnectedViewSpec, '{ assembly, loc, tracks }'),
118
+ connectedViewId: read('connectedViewId', isString, 'a string'),
119
+ sideBySide: read('sideBySide', isBoolean, 'true or false'),
120
+ feature: read('feature', isFeature, 'a feature object'),
121
+ userProvidedTranscriptSequence: read('userProvidedTranscriptSequence', isString, 'a string'),
122
+ };
123
+ }
98
124
  function readViewSettings(fields, warnings) {
99
125
  const read = fieldReader(fields, key => `\`${key}\``, warnings);
100
126
  const flag = (key) => read(key, isBoolean, 'true or false');
@@ -155,6 +181,7 @@ export function normalizeLaunch(launch) {
155
181
  const top = new Map(Object.entries(launch));
156
182
  const warnings = [];
157
183
  const settings = readViewSettings(top, warnings);
184
+ const linkage = readLinkage(top, warnings);
158
185
  const known = new Set([
159
186
  ...Object.keys(settings),
160
187
  ...STRUCTURE_KEYS,
@@ -164,8 +191,8 @@ export function normalizeLaunch(launch) {
164
191
  if (unknownKeys.length > 0) {
165
192
  warnings.push(`ignored unknown key(s): ${unknownKeys.join(', ')}`);
166
193
  }
167
- const looksUpGene = !!top.get('gene') && !top.get('userProvidedTranscriptSequence');
168
- const noStructure = top.get('gene')
194
+ const looksUpGene = !!linkage.gene && !linkage.userProvidedTranscriptSequence;
195
+ const noStructure = linkage.gene
169
196
  ? 'the launch names no structure, and `gene` is not looked up beside `userProvidedTranscriptSequence`'
170
197
  : 'No url, data, uniprotId, pdbId or gene provided when launching protein view';
171
198
  const given = top.get('structures');
@@ -179,6 +206,7 @@ export function normalizeLaunch(launch) {
179
206
  return {
180
207
  requested: [withUrl(structure)],
181
208
  settings,
209
+ linkage,
182
210
  warnings,
183
211
  geneModel: looksUpGene &&
184
212
  !!structure.uniprotId &&
@@ -189,7 +217,13 @@ export function normalizeLaunch(launch) {
189
217
  };
190
218
  }
191
219
  return looksUpGene
192
- ? { requested: [structure], settings, warnings, geneModel: 'required' }
220
+ ? {
221
+ requested: [structure],
222
+ settings,
223
+ linkage,
224
+ warnings,
225
+ geneModel: 'required',
226
+ }
193
227
  : { error: noStructure, warnings };
194
228
  }
195
229
  for (const key of STRUCTURE_KEYS) {
@@ -219,12 +253,18 @@ export function normalizeLaunch(launch) {
219
253
  return [withUrl(structure)];
220
254
  });
221
255
  if (requested.length > 0) {
222
- return { requested, settings, warnings };
256
+ return { requested, settings, linkage, warnings };
223
257
  }
224
258
  return looksUpGene
225
- ? { requested: [{}], settings, warnings, geneModel: 'required' }
259
+ ? {
260
+ requested: [{}],
261
+ settings,
262
+ linkage,
263
+ warnings,
264
+ geneModel: 'required',
265
+ }
226
266
  : {
227
- error: top.get('gene')
267
+ error: linkage.gene
228
268
  ? noStructure
229
269
  : 'no entry of `structures` names a url, data, uniprotId or pdbId',
230
270
  warnings,
@@ -11,8 +11,10 @@
11
11
  * from the live state tree, as color and removal read them.
12
12
  */
13
13
  import loadMolstar from './loadMolstar';
14
- import { structureRootCell } from './structureCells';
15
- export const SITES_TAG = 'jbrowse-alignment-sites';
14
+ import { drawnTests } from './residueFilter';
15
+ import { serialPerPlugin } from './serialPerPlugin';
16
+ import { SITES_TAG, drawnUnder, structureRootCell } from './structureCells';
17
+ export { SITES_TAG } from './structureCells';
16
18
  // Over twice the preset's 0.15, so a site's side chains stand out from the
17
19
  // ligand and focus sticks around them
18
20
  export const SITE_STICKS = { sizeFactor: 0.35, sizeAspectRatio: 0.6 };
@@ -21,13 +23,13 @@ let revision = 0;
21
23
  * Make each structure's sticks match its sites: create, update, or remove
22
24
  * them when `sites` is empty or undefined.
23
25
  */
24
- export async function syncSiteSticks({ plugin, structures, }) {
26
+ async function drawSiteSticks({ plugin, structures, }) {
25
27
  const molstar = await loadMolstar();
26
28
  const { MolScriptBuilder: MS, ProteinBackboneAtoms, StateSelection, StateTransforms, createStructureColorThemeParams, createStructureRepresentationParams, registerPlacedValues, } = molstar;
27
29
  revision++;
28
30
  const update = plugin.state.data.build();
29
31
  let changed = false;
30
- for (const { molstarStructure, sites, color } of structures) {
32
+ for (const { molstarStructure, sites, color, chains, filter } of structures) {
31
33
  const root = structureRootCell(plugin, molstar, molstarStructure);
32
34
  if (!root) {
33
35
  continue;
@@ -43,6 +45,11 @@ export async function syncSiteSticks({ plugin, structures, }) {
43
45
  continue;
44
46
  }
45
47
  const atom = (name) => MS.core.rel.eq([MS.ammp('label_atom_id'), name]);
48
+ const { chainTest, residueTest } = drawnTests(MS, { chains, filter });
49
+ const isSite = MS.core.set.has([
50
+ MS.set(...labelSeqIds),
51
+ MS.ammp('label_seq_id'),
52
+ ]);
46
53
  const component = {
47
54
  type: {
48
55
  name: 'expression',
@@ -51,10 +58,10 @@ export async function syncSiteSticks({ plugin, structures, }) {
51
58
  MS.ammp('label_entity_id'),
52
59
  sites.entityId,
53
60
  ]),
54
- 'residue-test': MS.core.set.has([
55
- MS.set(...labelSeqIds),
56
- MS.ammp('label_seq_id'),
57
- ]),
61
+ 'residue-test': residueTest
62
+ ? MS.core.logic.and([isSite, residueTest])
63
+ : isSite,
64
+ ...(chainTest ? { 'chain-test': chainTest } : {}),
58
65
  'atom-test': MS.core.logic.or([
59
66
  MS.core.logic.not([
60
67
  MS.core.set.has([
@@ -90,10 +97,8 @@ export async function syncSiteSticks({ plugin, structures, }) {
90
97
  else {
91
98
  update
92
99
  .to(root)
93
- .apply(StateTransforms.Model.StructureComponent, component, {
94
- tags: [SITES_TAG],
95
- })
96
- .apply(StateTransforms.Representation.StructureRepresentation3D, representation, { tags: [SITES_TAG] });
100
+ .apply(StateTransforms.Model.StructureComponent, component, drawnUnder(root, SITES_TAG))
101
+ .apply(StateTransforms.Representation.StructureRepresentation3D, representation, drawnUnder(root, SITES_TAG));
97
102
  }
98
103
  changed = true;
99
104
  }
@@ -101,3 +106,6 @@ export async function syncSiteSticks({ plugin, structures, }) {
101
106
  await update.commit();
102
107
  }
103
108
  }
109
+ export function syncSiteSticks(args) {
110
+ return serialPerPlugin(args.plugin, () => drawSiteSticks(args));
111
+ }
@@ -1,10 +1,8 @@
1
1
  import { EMPTY_DOMAIN_COLOR, domainMarkOf } from './alignmentDomains';
2
- import { SITES_TAG } from './alignmentSites';
3
2
  import loadMolstar from './loadMolstar';
4
3
  import { molstarThemeOf, resolvedColor } from './proteinColor';
5
- import { RESIDUE_MARKS_TAG } from './residueMarks';
6
- import { SESSION_HIGHLIGHTS_TAG } from './sessionHighlights';
7
- import { structureRootCell } from './structureCells';
4
+ import { serialPerPlugin } from './serialPerPlugin';
5
+ import { structureRepresentations, structureRootCell } from './structureCells';
8
6
  import { VARIANT_EFFECT_SCHEMES } from './variantEffects';
9
7
  /**
10
8
  * The themes that color by values placed on each structure's residues, which
@@ -45,9 +43,9 @@ let revision = 0;
45
43
  * placedValueRegistry), registered for each structure before the update; a
46
44
  * structure without values is drawn grey.
47
45
  */
48
- export async function applyColorTheme({ plugin, color, structures, }) {
46
+ async function recolor({ plugin, color, structures, }) {
49
47
  const molstar = await loadMolstar();
50
- const { StateSelection, StateTransforms, createStructureColorThemeParams, registerPlacedValues, } = molstar;
48
+ const { createStructureColorThemeParams, registerPlacedValues } = molstar;
51
49
  const theme = molstarThemeOf(color);
52
50
  const placed = isPlacedValueScheme(theme);
53
51
  if (placed) {
@@ -64,29 +62,27 @@ export async function applyColorTheme({ plugin, color, structures, }) {
64
62
  }
65
63
  const cell = structureRootCell(plugin, molstar, molstarStructure);
66
64
  const representations = cell
67
- ? plugin.state.data.select(StateSelection.Generators.ofTransformer(StateTransforms.Representation.StructureRepresentation3D, cell.transform.ref))
65
+ ? structureRepresentations(plugin, molstar, cell)
68
66
  : [];
69
67
  for (const representation of representations) {
70
- if (!representation.state.isGhost &&
71
- !representation.transform.tags?.includes(SITES_TAG) &&
72
- !representation.transform.tags?.includes(SESSION_HIGHLIGHTS_TAG) &&
73
- !representation.transform.tags?.includes(RESIDUE_MARKS_TAG)) {
74
- update.to(representation).update(prev => {
75
- prev.colorTheme = createStructureColorThemeParams(plugin, molstarStructure, prev.type.name, theme, themeParams(color, {
76
- entityId,
77
- domainColor,
78
- revision,
79
- representationType: prev.type.name,
80
- }));
81
- });
82
- recolored++;
83
- }
68
+ update.to(representation).update(prev => {
69
+ prev.colorTheme = createStructureColorThemeParams(plugin, molstarStructure, prev.type.name, theme, themeParams(color, {
70
+ entityId,
71
+ domainColor,
72
+ revision,
73
+ representationType: prev.type.name,
74
+ }));
75
+ });
76
+ recolored++;
84
77
  }
85
78
  }
86
79
  if (recolored > 0) {
87
80
  await update.commit();
88
81
  }
89
82
  }
83
+ export function applyColorTheme(args) {
84
+ return serialPerPlugin(args.plugin, () => recolor(args));
85
+ }
90
86
  /**
91
87
  * The key Mol* itself would show for a color, which its viewport never draws
92
88
  * and its hidden-by-default controls panel buries. Built on one structure, so a
@@ -47,8 +47,10 @@ export async function placeClinVarOnTranscript({ build, feature, assemblyName, s
47
47
  if (positions.length === 0) {
48
48
  throw new Error('the transcript has no coding sequence');
49
49
  }
50
- const start = Math.min(...positions);
51
- const end = Math.max(...positions) + 1;
50
+ // reduced, not spread: TTN's 100k coding bases pass JavaScriptCore's
51
+ // argument limit
52
+ const start = positions.reduce((a, b) => Math.min(a, b));
53
+ const end = positions.reduce((a, b) => Math.max(a, b)) + 1;
52
54
  const assembly = await session.assemblyManager.waitForAssembly(assemblyName);
53
55
  const [variants, genome] = await Promise.all([
54
56
  readMissense(build, [refName, ...(assembly?.getAliasesForRefName(refName) ?? [])], start, end, signal),
@@ -25,7 +25,8 @@ function rampPosition(color, value) {
25
25
  : 0.5 +
26
26
  (value - domainMid) /
27
27
  (2 * Math.max(domainMid - domainMin, domainMax - domainMid));
28
- return Math.max(0, Math.min(1, p));
28
+ // a zero-width domain gives NaN, which would index no stop
29
+ return Number.isNaN(p) ? 0 : Math.max(0, Math.min(1, p));
29
30
  }
30
31
  function rampRgb(color) {
31
32
  const stops = color.range.map(rgbOf);
@@ -67,16 +67,28 @@ const GenomeTrackColorDialog = observer(function GenomeTrackColorDialog({ model,
67
67
  React.createElement(DialogActions, null,
68
68
  React.createElement(Button, { onClick: handleClose }, "Cancel"),
69
69
  React.createElement(Button, { variant: "contained", disabled: !trackId || cutsInvalid, onClick: () => {
70
+ // the same track on the same scale keeps what a session wrote
71
+ // beside it: its palette, labels, title and domain
72
+ const kept = color.field === 'track' &&
73
+ color.trackId === trackId &&
74
+ (color.scale === 'threshold') === (scale === 'threshold')
75
+ ? color
76
+ : undefined;
77
+ const sameBands = kept?.range?.length === (cuts?.length ?? 0) + 1;
70
78
  model.setColor(scale === 'threshold' && cuts
71
79
  ? {
80
+ ...kept,
72
81
  field: 'track',
73
82
  trackId,
74
83
  stat,
75
84
  scale,
76
85
  domain: cuts,
77
- range: thresholdRange(cuts.length + 1),
86
+ range: sameBands
87
+ ? kept.range
88
+ : thresholdRange(cuts.length + 1),
89
+ labels: sameBands ? kept.labels : undefined,
78
90
  }
79
- : { field: 'track', trackId, stat });
91
+ : { ...kept, field: 'track', trackId, stat });
80
92
  handleClose();
81
93
  } }, "Color"))));
82
94
  });
@@ -73,7 +73,7 @@ function keyOf(structure, m) {
73
73
  * Mol*'s own tool carry no tag and are left alone.
74
74
  */
75
75
  export function syncMeasurements({ plugin, structures, measurements, labels = true, }) {
76
- return serialPerPlugin(plugin, MEASUREMENT_TAG, async () => {
76
+ return serialPerPlugin(plugin, async () => {
77
77
  const molstar = await loadMolstar();
78
78
  const { Color, StateSelection, StateTransforms } = molstar;
79
79
  const existing = plugin.state.data.select(StateSelection.Generators.root
@@ -33,6 +33,18 @@ import { syncSurfaces } from './surface';
33
33
  import { isValueField, paintedColor, valueDomain } from './valueScale';
34
34
  import { attachViewInteractions } from './viewInteractions';
35
35
  const MIN_HEIGHT = 100;
36
+ // the entries a removal leaves, addressing the same structures in the shorter
37
+ // list; an entry with no `structure` addresses the first
38
+ function withoutStructure(entries, removed) {
39
+ return entries.flatMap(entry => {
40
+ const index = entry.structure ?? 0;
41
+ return index === removed
42
+ ? []
43
+ : index > removed
44
+ ? [{ ...entry, structure: index - 1 }]
45
+ : [entry];
46
+ });
47
+ }
36
48
  // Queued on the session rather than mounted in the view's body, which is not
37
49
  // there while Mol* loads, after it fails, or while the view is minimized
38
50
  const AddStructureDialog = lazy(() => import('./components/AddStructureDialog'));
@@ -345,6 +357,9 @@ function stateModelFactory() {
345
357
  self.alignmentStructureIndex =
346
358
  removed === open ? undefined : removed < open ? open - 1 : open;
347
359
  }
360
+ self.marks = self.marks && withoutStructure(self.marks, removed);
361
+ self.distances =
362
+ self.distances && withoutStructure(self.distances, removed);
348
363
  self.structures.remove(structure);
349
364
  self.setSuperposedCount(0);
350
365
  if (plugin) {
@@ -471,6 +486,8 @@ function stateModelFactory() {
471
486
  molstarStructure,
472
487
  sites: s.alignmentDomainStatus?.placedSites,
473
488
  color: s.alignmentDomainStatus?.domains?.color,
489
+ chains: s.chains,
490
+ filter: s.filter,
474
491
  }))
475
492
  : []);
476
493
  if (plugin && structures.length > 0) {
@@ -150,7 +150,8 @@ export function colorProblems(color) {
150
150
  return ["color is an object, such as { field: 'alphaMissense' }"];
151
151
  }
152
152
  const { field, ...members } = color;
153
- const named = Object.keys(members);
153
+ // an undefined member names nothing, as a snapshot, which drops it, agrees
154
+ const named = Object.keys(members).filter(key => members[key] !== undefined);
154
155
  if (field === undefined) {
155
156
  return named.length > 0
156
157
  ? [`color names no field, so ${named.join(', ')} paints nothing`]
@@ -1,4 +1,5 @@
1
1
  import loadMolstar from './loadMolstar';
2
+ import { serialPerPlugin } from './serialPerPlugin';
2
3
  import { structureRootCell } from './structureCells';
3
4
  /**
4
5
  * Take one load out of Mol*, by the trajectory it came from: removing the
@@ -9,21 +10,28 @@ import { structureRootCell } from './structureCells';
9
10
  * structure a superposition has transformed, or one that finished loading an
10
11
  * instant ago, is still found.
11
12
  */
12
- export async function removeMolstarStructure({ plugin, molstarStructure, }) {
13
- if (!molstarStructure) {
14
- return;
15
- }
16
- const molstar = await loadMolstar();
17
- const { PluginCommands, PluginStateObject } = molstar;
18
- const cell = structureRootCell(plugin, molstar, molstarStructure);
19
- const trajectory = cell &&
20
- plugin.state.data.selectQ(q => q.byValue(cell).ancestorOfType(PluginStateObject.Molecule.Trajectory))[0];
21
- const target = trajectory ?? cell;
22
- if (target) {
23
- await PluginCommands.State.RemoveObject(plugin, {
24
- state: plugin.state.data,
25
- ref: target.transform.ref,
26
- removeParentGhosts: true,
27
- });
28
- }
13
+ export function removeMolstarStructure({ plugin, molstarStructure, }) {
14
+ return serialPerPlugin(plugin, async () => {
15
+ if (!molstarStructure) {
16
+ return;
17
+ }
18
+ const molstar = await loadMolstar();
19
+ const { PluginStateObject } = molstar;
20
+ const cell = structureRootCell(plugin, molstar, molstarStructure);
21
+ const trajectory = cell &&
22
+ plugin.state.data.selectQ(q => q.byValue(cell).ancestorOfType(PluginStateObject.Molecule.Trajectory))[0];
23
+ const target = trajectory ?? cell;
24
+ if (target) {
25
+ await removeWithGhosts(plugin, molstar, target.transform.ref);
26
+ }
27
+ });
28
+ }
29
+ /** Remove a cell and the ghost nodes above it, the download or pasted text
30
+ * and its parse. Unserialized, for a task already in the plugin's lane. */
31
+ export async function removeWithGhosts(plugin, molstar, ref) {
32
+ await molstar.PluginCommands.State.RemoveObject(plugin, {
33
+ state: plugin.state.data,
34
+ ref,
35
+ removeParentGhosts: true,
36
+ });
29
37
  }