jbrowse-plugin-protein3d 1.25.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 (146) 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 +53 -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/loadStructureData.js +2 -1
  16. package/dist/ProteinView/markProblems.js +4 -2
  17. package/dist/ProteinView/measurements.js +1 -1
  18. package/dist/ProteinView/model.js +20 -1
  19. package/dist/ProteinView/proteinColor.js +2 -1
  20. package/dist/ProteinView/removeStructure.js +25 -17
  21. package/dist/ProteinView/residueFilter.js +184 -0
  22. package/dist/ProteinView/residueMarks.js +5 -5
  23. package/dist/ProteinView/serialPerPlugin.js +10 -12
  24. package/dist/ProteinView/sessionHighlights.js +29 -31
  25. package/dist/ProteinView/structureCells.js +25 -0
  26. package/dist/ProteinView/structureModel.js +27 -2
  27. package/dist/ProteinView/structurePipeline.js +45 -19
  28. package/dist/ProteinView/structureVisibility.js +13 -8
  29. package/dist/ProteinView/superposeStructures.js +5 -1
  30. package/dist/ProteinView/surface.js +7 -3
  31. package/dist/ProteinView/valueScale.js +14 -3
  32. package/dist/chunks/GenomeTrackColorDialog-WJQNAUV3.js +2 -0
  33. package/dist/chunks/{GenomeTrackColorDialog-FDQKUBYA.js.map → GenomeTrackColorDialog-WJQNAUV3.js.map} +3 -3
  34. package/dist/chunks/LaunchProteinViewDialog-WVFGF2HL.js +2 -0
  35. package/dist/chunks/LaunchProteinViewDialog-WVFGF2HL.js.map +7 -0
  36. package/dist/chunks/{ProteinView-QALYTNTX.js → ProteinView-IYF52HYP.js} +3 -3
  37. package/dist/chunks/{chunk-KZ76WUQW.js → chunk-4QUS35JT.js} +2 -2
  38. package/dist/chunks/chunk-4QUS35JT.js.map +7 -0
  39. package/dist/chunks/chunk-62VIRECC.js +2 -0
  40. package/dist/chunks/chunk-62VIRECC.js.map +7 -0
  41. package/dist/chunks/{chunk-VT5BCVCX.js → chunk-GND6AQKJ.js} +2 -2
  42. package/dist/chunks/chunk-HOQSHQW5.js +2 -0
  43. package/dist/chunks/chunk-HOQSHQW5.js.map +7 -0
  44. package/dist/chunks/chunk-LHMM35YG.js +2 -0
  45. package/dist/chunks/chunk-LHMM35YG.js.map +7 -0
  46. package/dist/chunks/{chunk-ZJ4MV3RK.js → chunk-QW32NNHJ.js} +2 -2
  47. package/dist/chunks/{chunk-ZJ4MV3RK.js.map → chunk-QW32NNHJ.js.map} +2 -2
  48. package/dist/chunks/chunk-R4MOJI76.js +2 -0
  49. package/dist/chunks/chunk-R4MOJI76.js.map +7 -0
  50. package/dist/chunks/chunk-RGQ2CMGW.js +2 -0
  51. package/dist/chunks/chunk-RGQ2CMGW.js.map +7 -0
  52. package/dist/chunks/{chunk-2WSEMZUR.js → chunk-RYRIX2KR.js} +2 -2
  53. package/dist/chunks/{chunk-2WSEMZUR.js.map → chunk-RYRIX2KR.js.map} +3 -3
  54. package/dist/chunks/chunk-TRAGDWEM.js +2 -0
  55. package/dist/chunks/chunk-TRAGDWEM.js.map +7 -0
  56. package/dist/chunks/{clinVarSource-YZSKOR5L.js → clinVarSource-XTPLVQDM.js} +2 -2
  57. package/dist/chunks/launchAnnotationView-2RKNVVHA.js +2 -0
  58. package/dist/chunks/launchAnnotationView-2RKNVVHA.js.map +7 -0
  59. package/dist/chunks/launchProteinView-JW4YPHW7.js +2 -0
  60. package/dist/chunks/launchProteinView-JW4YPHW7.js.map +7 -0
  61. package/dist/chunks/{launchViewUtils-7XTBTFAV.js → launchViewUtils-AVXWFYSV.js} +2 -2
  62. package/dist/chunks/model-G7I4KFGC.js +2 -0
  63. package/dist/chunks/model-G7I4KFGC.js.map +7 -0
  64. package/dist/chunks/{molstarExports-ZC2DCGMF.js → molstarExports-D5CVDS4O.js} +2 -2
  65. package/dist/chunks/{resolveGeneLaunch-NI4BGFX5.js → resolveGeneLaunch-VBVWSDZI.js} +2 -2
  66. package/dist/jbrowse-plugin-protein3d.esm.js +1 -1
  67. package/dist/jbrowse-plugin-protein3d.esm.js.map +1 -1
  68. package/dist/test_data/molstarPlugin.js +2 -0
  69. package/dist/test_data/molstarStructure.js +23 -1
  70. package/dist/version.js +1 -1
  71. package/package.json +1 -1
  72. package/src/LaunchProteinView/components/PdbSearch.tsx +16 -4
  73. package/src/LaunchProteinView/components/StructureSourcePicker.tsx +6 -1
  74. package/src/LaunchProteinView/components/UserProvidedStructure.tsx +7 -2
  75. package/src/LaunchProteinView/hooks/useAlphaFoldDBSearch.ts +1 -1
  76. package/src/LaunchProteinView/hooks/useAlphaFoldData.ts +4 -1
  77. package/src/LaunchProteinView/resolveGeneLaunch.test.ts +13 -0
  78. package/src/LaunchProteinView/resolveGeneLaunch.ts +16 -4
  79. package/src/LaunchProteinViewExtensionPoint/launchProteinView.ts +11 -13
  80. package/src/LaunchProteinViewExtensionPoint/normalizeAnnotationLaunch.ts +1 -15
  81. package/src/LaunchProteinViewExtensionPoint/normalizeLaunch.test.ts +40 -0
  82. package/src/LaunchProteinViewExtensionPoint/normalizeLaunch.ts +95 -7
  83. package/src/ProteinView/alignmentSites.test.ts +32 -0
  84. package/src/ProteinView/alignmentSites.ts +30 -12
  85. package/src/ProteinView/applyColorTheme.ts +24 -39
  86. package/src/ProteinView/clinVarSource.ts +4 -2
  87. package/src/ProteinView/colorScale.ts +2 -1
  88. package/src/ProteinView/components/GenomeTrackColorDialog.tsx +15 -2
  89. package/src/ProteinView/loadStructureData.ts +4 -3
  90. package/src/ProteinView/markProblems.test.ts +8 -0
  91. package/src/ProteinView/markProblems.ts +12 -4
  92. package/src/ProteinView/measurements.ts +1 -1
  93. package/src/ProteinView/model.test.ts +42 -0
  94. package/src/ProteinView/model.ts +27 -1
  95. package/src/ProteinView/proteinColor.test.ts +15 -0
  96. package/src/ProteinView/proteinColor.ts +2 -1
  97. package/src/ProteinView/proteinViewSpec.ts +6 -0
  98. package/src/ProteinView/removeStructure.ts +34 -20
  99. package/src/ProteinView/residueFilter.test.ts +97 -0
  100. package/src/ProteinView/residueFilter.ts +250 -0
  101. package/src/ProteinView/residueMarks.ts +9 -5
  102. package/src/ProteinView/serialPerPlugin.ts +11 -14
  103. package/src/ProteinView/sessionHighlights.test.ts +131 -0
  104. package/src/ProteinView/sessionHighlights.ts +50 -42
  105. package/src/ProteinView/structureCells.ts +46 -0
  106. package/src/ProteinView/structureModel.test.ts +24 -0
  107. package/src/ProteinView/structureModel.ts +28 -2
  108. package/src/ProteinView/structurePipeline.test.ts +100 -1
  109. package/src/ProteinView/structurePipeline.ts +58 -22
  110. package/src/ProteinView/structureVisibility.test.ts +40 -0
  111. package/src/ProteinView/structureVisibility.ts +17 -12
  112. package/src/ProteinView/superposeStructures.ts +9 -1
  113. package/src/ProteinView/surface.ts +8 -3
  114. package/src/ProteinView/valueScale.test.ts +28 -0
  115. package/src/ProteinView/valueScale.ts +16 -3
  116. package/src/test_data/molstarPlugin.ts +11 -1
  117. package/src/test_data/molstarStructure.ts +28 -1
  118. package/src/version.ts +1 -1
  119. package/dist/chunks/GenomeTrackColorDialog-FDQKUBYA.js +0 -2
  120. package/dist/chunks/LaunchProteinViewDialog-GDEANZ6O.js +0 -2
  121. package/dist/chunks/LaunchProteinViewDialog-GDEANZ6O.js.map +0 -7
  122. package/dist/chunks/chunk-AYS6MD64.js +0 -2
  123. package/dist/chunks/chunk-AYS6MD64.js.map +0 -7
  124. package/dist/chunks/chunk-IW33ITI5.js +0 -2
  125. package/dist/chunks/chunk-IW33ITI5.js.map +0 -7
  126. package/dist/chunks/chunk-KZ76WUQW.js.map +0 -7
  127. package/dist/chunks/chunk-LK7TA465.js +0 -2
  128. package/dist/chunks/chunk-LK7TA465.js.map +0 -7
  129. package/dist/chunks/chunk-RL54DUYZ.js +0 -2
  130. package/dist/chunks/chunk-RL54DUYZ.js.map +0 -7
  131. package/dist/chunks/chunk-SR54J2GA.js +0 -2
  132. package/dist/chunks/chunk-SR54J2GA.js.map +0 -7
  133. package/dist/chunks/chunk-UEHBHBLB.js +0 -2
  134. package/dist/chunks/chunk-UEHBHBLB.js.map +0 -7
  135. package/dist/chunks/launchAnnotationView-UFCA3T3G.js +0 -2
  136. package/dist/chunks/launchAnnotationView-UFCA3T3G.js.map +0 -7
  137. package/dist/chunks/launchProteinView-S7VBHQK7.js +0 -2
  138. package/dist/chunks/launchProteinView-S7VBHQK7.js.map +0 -7
  139. package/dist/chunks/model-P2NVES57.js +0 -2
  140. package/dist/chunks/model-P2NVES57.js.map +0 -7
  141. /package/dist/chunks/{ProteinView-QALYTNTX.js.map → ProteinView-IYF52HYP.js.map} +0 -0
  142. /package/dist/chunks/{chunk-VT5BCVCX.js.map → chunk-GND6AQKJ.js.map} +0 -0
  143. /package/dist/chunks/{clinVarSource-YZSKOR5L.js.map → clinVarSource-XTPLVQDM.js.map} +0 -0
  144. /package/dist/chunks/{launchViewUtils-7XTBTFAV.js.map → launchViewUtils-AVXWFYSV.js.map} +0 -0
  145. /package/dist/chunks/{molstarExports-ZC2DCGMF.js.map → molstarExports-D5CVDS4O.js.map} +0 -0
  146. /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
@@ -13,6 +13,7 @@ const STRUCTURE_KEY_ROLES = {
13
13
  hidden: 'setting',
14
14
  assembly: 'setting',
15
15
  chains: 'setting',
16
+ filter: 'setting',
16
17
  feature: 'launchWide',
17
18
  userProvidedTranscriptSequence: 'launchWide',
18
19
  connectedViewId: 'launchWide',
@@ -44,6 +45,11 @@ function isNumber(value) {
44
45
  function isFeature(value) {
45
46
  return isRecord(value);
46
47
  }
48
+ // the shape only: the view model refuses a predicate that does not read, with
49
+ // the reason, as it does a color
50
+ function isPredicateList(value) {
51
+ return Array.isArray(value) && value.every(isRecord);
52
+ }
47
53
  function isResidueRange(value) {
48
54
  return (isRecord(value) &&
49
55
  typeof value.start === 'number' &&
@@ -66,6 +72,16 @@ export function isPairwiseAlignment(value) {
66
72
  value.alns.length === 2 &&
67
73
  value.alns.every(isAlignmentRow));
68
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
+ }
69
85
  const RANGES = '{ start, end } numbers or an array of them';
70
86
  /**
71
87
  * Launch text comes from a url, and the view model throws on a wrongly typed
@@ -89,6 +105,22 @@ const LAUNCH_KEYS = [
89
105
  'connectedView',
90
106
  'sideBySide',
91
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
+ }
92
124
  function readViewSettings(fields, warnings) {
93
125
  const read = fieldReader(fields, key => `\`${key}\``, warnings);
94
126
  const flag = (key) => read(key, isBoolean, 'true or false');
@@ -126,6 +158,7 @@ function readStructure(fields, at, warnings) {
126
158
  hidden: read('hidden', isBoolean, 'true or false'),
127
159
  assembly: read('assembly', isString, 'a string'),
128
160
  chains: read('chains', isStringArray, 'a list of chain ids'),
161
+ filter: read('filter', isPredicateList, "a list of predicates such as [{ field: 'residue', lte: 184 }]"),
129
162
  feature: read('feature', isFeature, 'a feature object'),
130
163
  userProvidedTranscriptSequence: read('userProvidedTranscriptSequence', isString, 'a string'),
131
164
  connectedViewId: read('connectedViewId', isString, 'a string'),
@@ -148,6 +181,7 @@ export function normalizeLaunch(launch) {
148
181
  const top = new Map(Object.entries(launch));
149
182
  const warnings = [];
150
183
  const settings = readViewSettings(top, warnings);
184
+ const linkage = readLinkage(top, warnings);
151
185
  const known = new Set([
152
186
  ...Object.keys(settings),
153
187
  ...STRUCTURE_KEYS,
@@ -157,8 +191,8 @@ export function normalizeLaunch(launch) {
157
191
  if (unknownKeys.length > 0) {
158
192
  warnings.push(`ignored unknown key(s): ${unknownKeys.join(', ')}`);
159
193
  }
160
- const looksUpGene = !!top.get('gene') && !top.get('userProvidedTranscriptSequence');
161
- const noStructure = top.get('gene')
194
+ const looksUpGene = !!linkage.gene && !linkage.userProvidedTranscriptSequence;
195
+ const noStructure = linkage.gene
162
196
  ? 'the launch names no structure, and `gene` is not looked up beside `userProvidedTranscriptSequence`'
163
197
  : 'No url, data, uniprotId, pdbId or gene provided when launching protein view';
164
198
  const given = top.get('structures');
@@ -172,6 +206,7 @@ export function normalizeLaunch(launch) {
172
206
  return {
173
207
  requested: [withUrl(structure)],
174
208
  settings,
209
+ linkage,
175
210
  warnings,
176
211
  geneModel: looksUpGene &&
177
212
  !!structure.uniprotId &&
@@ -182,7 +217,13 @@ export function normalizeLaunch(launch) {
182
217
  };
183
218
  }
184
219
  return looksUpGene
185
- ? { requested: [structure], settings, warnings, geneModel: 'required' }
220
+ ? {
221
+ requested: [structure],
222
+ settings,
223
+ linkage,
224
+ warnings,
225
+ geneModel: 'required',
226
+ }
186
227
  : { error: noStructure, warnings };
187
228
  }
188
229
  for (const key of STRUCTURE_KEYS) {
@@ -212,12 +253,18 @@ export function normalizeLaunch(launch) {
212
253
  return [withUrl(structure)];
213
254
  });
214
255
  if (requested.length > 0) {
215
- return { requested, settings, warnings };
256
+ return { requested, settings, linkage, warnings };
216
257
  }
217
258
  return looksUpGene
218
- ? { requested: [{}], settings, warnings, geneModel: 'required' }
259
+ ? {
260
+ requested: [{}],
261
+ settings,
262
+ linkage,
263
+ warnings,
264
+ geneModel: 'required',
265
+ }
219
266
  : {
220
- error: top.get('gene')
267
+ error: linkage.gene
221
268
  ? noStructure
222
269
  : 'no entry of `structures` names a url, data, uniprotId or pdbId',
223
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
  });
@@ -68,13 +68,14 @@ function structureAssemblies(model, molstar) {
68
68
  * callers own the decision of whether/where to store the result.
69
69
  */
70
70
  export async function loadStructureData({ structure, plugin, }) {
71
- const { data, url, assembly, chains } = structure;
71
+ const { data, url, assembly, chains, filter } = structure;
72
72
  const { model, structures: molstarStructures, modelIds, } = await loadStructure({
73
73
  plugin,
74
74
  data: data || undefined,
75
75
  url,
76
76
  assembly,
77
77
  chains,
78
+ filter,
78
79
  });
79
80
  const molstar = await loadMolstar();
80
81
  // An experimental entry's B-factors are not confidence: read as pLDDT they
@@ -1,3 +1,4 @@
1
+ import { narrowsChains } from './residueFilter';
1
2
  import { parseSite } from './residueSpec';
2
3
  const MARK_TYPES = ['spheres', 'sticks', 'cartoon'];
3
4
  const HEX_COLOR = /^#[0-9a-f]{6}$/i;
@@ -32,8 +33,8 @@ function siteProblems(where, key, site) {
32
33
  /**
33
34
  * Why `marks` would draw something other than what it says: a site or mark
34
35
  * type that does not parse, a color that is not #rrggbb, or a cartoon over a
35
- * chain the structure already draws. `structures` are the view's, whose
36
- * `chains` say which chains are drawn.
36
+ * chain the structure already draws whole. `structures` are the view's, whose
37
+ * `chains` and `filter` say what is drawn.
37
38
  */
38
39
  export function markProblems(marks, structures = []) {
39
40
  if (marks === undefined) {
@@ -60,6 +61,7 @@ export function markProblems(marks, structures = []) {
60
61
  ...encodingProblems(where, mark),
61
62
  ...(mark.mark === 'cartoon' &&
62
63
  site?.kind === 'chain' &&
64
+ !narrowsChains(structure) &&
63
65
  (!drawn || drawn.includes(site.chain))
64
66
  ? [
65
67
  `${where} draws chain ${site.chain} as a cartoon over the one the structure draws; list the other chains in chains`,
@@ -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