jbrowse-plugin-protein3d 1.32.0 → 1.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +7 -5
  2. package/dist/LaunchProteinView/components/GeneStructures.js +19 -4
  3. package/dist/LaunchProteinView/components/HelpDialog.js +1 -1
  4. package/dist/LaunchProteinView/components/StructureListRow.js +6 -2
  5. package/dist/LaunchProteinView/hooks/useDatasetStructures.js +45 -0
  6. package/dist/LaunchProteinView/hooks/useGeneStructures.js +56 -28
  7. package/dist/LaunchProteinView/hooks/useStructureLaunch.js +31 -8
  8. package/dist/LaunchProteinView/utils/structureDatasets.js +179 -0
  9. package/dist/LaunchProteinView/utils/structureList.js +38 -2
  10. package/dist/LaunchProteinViewExtensionPoint/datasetLaunch.js +50 -0
  11. package/dist/LaunchProteinViewExtensionPoint/launchProteinView.js +2 -1
  12. package/dist/chunks/AlphaFoldConfidenceAdapter-6YTRHE3R.js +2 -0
  13. package/dist/chunks/{AlphaFoldConfidenceAdapter-VT7X2M4N.js.map → AlphaFoldConfidenceAdapter-6YTRHE3R.js.map} +1 -1
  14. package/dist/chunks/AlphaMissensePathogenicityAdapter-UX7VHUBB.js +2 -0
  15. package/dist/chunks/{AlphaMissensePathogenicityAdapter-TKOLREIQ.js.map → AlphaMissensePathogenicityAdapter-UX7VHUBB.js.map} +1 -1
  16. package/dist/chunks/{GenomeTrackColorDialog-VD5NKKQZ.js → GenomeTrackColorDialog-EJZ5KTKX.js} +2 -2
  17. package/dist/chunks/HelpDialog-ZGLXAIOU.js +2 -0
  18. package/dist/chunks/{HelpDialog-IKLXHB3B.js.map → HelpDialog-ZGLXAIOU.js.map} +2 -2
  19. package/dist/chunks/LaunchProteinViewDialog-OMCH6FKM.js +3 -0
  20. package/dist/chunks/LaunchProteinViewDialog-OMCH6FKM.js.map +7 -0
  21. package/dist/chunks/{ProteinView-QUCIMT3H.js → ProteinView-IM7GNXMQ.js} +3 -3
  22. package/dist/chunks/{chunk-KAP5JKRU.js → chunk-22BDSJBC.js} +2 -2
  23. package/dist/chunks/chunk-7B4IRZLD.js +2 -0
  24. package/dist/chunks/chunk-7B4IRZLD.js.map +7 -0
  25. package/dist/chunks/{chunk-XQ5PSSWY.js → chunk-7GELEOAH.js} +2 -2
  26. package/dist/chunks/{chunk-FDHODUXS.js → chunk-A73LEL2C.js} +2 -2
  27. package/dist/chunks/chunk-EKHBUHHM.js +3 -0
  28. package/dist/chunks/chunk-EKHBUHHM.js.map +7 -0
  29. package/dist/chunks/chunk-HNO3QZD6.js +2 -0
  30. package/dist/chunks/chunk-HNO3QZD6.js.map +7 -0
  31. package/dist/chunks/{chunk-VQRND5DF.js → chunk-LVAZFGE6.js} +2 -2
  32. package/dist/chunks/{chunk-4YOPOPED.js → chunk-MBUM32YU.js} +3 -3
  33. package/dist/chunks/{chunk-4YOPOPED.js.map → chunk-MBUM32YU.js.map} +2 -2
  34. package/dist/chunks/chunk-NCH7IJII.js +2 -0
  35. package/dist/chunks/{chunk-KML7CVV2.js → chunk-SEVYWN5I.js} +2 -2
  36. package/dist/chunks/{chunk-KML7CVV2.js.map → chunk-SEVYWN5I.js.map} +2 -2
  37. package/dist/chunks/{chunk-KL7O7H46.js → chunk-TZ54BAT7.js} +2 -2
  38. package/dist/chunks/chunk-Y5T7GSKP.js +2 -0
  39. package/dist/chunks/{chunk-CIZQGPKL.js.map → chunk-Y5T7GSKP.js.map} +2 -2
  40. package/dist/chunks/{launchAnnotationView-5RYUC7P4.js → launchAnnotationView-XZ7GDC3Z.js} +2 -2
  41. package/dist/chunks/launchProteinView-ZCQRFJXK.js +2 -0
  42. package/dist/chunks/launchProteinView-ZCQRFJXK.js.map +7 -0
  43. package/dist/chunks/{launchViewUtils-FTOMSLZU.js → launchViewUtils-6INIP22K.js} +2 -2
  44. package/dist/chunks/{model-I3FOCWUA.js → model-J5LYRYAB.js} +2 -2
  45. package/dist/chunks/resolveGeneLaunch-4AG66E4N.js +2 -0
  46. package/dist/index.js +17 -0
  47. package/dist/jbrowse-plugin-protein3d.esm.js +1 -1
  48. package/dist/jbrowse-plugin-protein3d.esm.js.map +3 -3
  49. package/dist/version.js +1 -1
  50. package/package.json +1 -1
  51. package/src/LaunchProteinView/components/GeneStructures.tsx +20 -4
  52. package/src/LaunchProteinView/components/HelpDialog.tsx +4 -1
  53. package/src/LaunchProteinView/components/StructureListRow.tsx +16 -1
  54. package/src/LaunchProteinView/hooks/useDatasetStructures.ts +77 -0
  55. package/src/LaunchProteinView/hooks/useGeneStructures.test.ts +131 -9
  56. package/src/LaunchProteinView/hooks/useGeneStructures.ts +58 -24
  57. package/src/LaunchProteinView/hooks/useStructureLaunch.ts +34 -9
  58. package/src/LaunchProteinView/utils/launchViewUtils.ts +3 -2
  59. package/src/LaunchProteinView/utils/structureDatasets.test.ts +220 -0
  60. package/src/LaunchProteinView/utils/structureDatasets.ts +263 -0
  61. package/src/LaunchProteinView/utils/structureList.ts +51 -2
  62. package/src/LaunchProteinViewExtensionPoint/datasetLaunch.test.ts +97 -0
  63. package/src/LaunchProteinViewExtensionPoint/datasetLaunch.ts +72 -0
  64. package/src/LaunchProteinViewExtensionPoint/launchProteinView.ts +7 -1
  65. package/src/index.ts +22 -0
  66. package/src/version.ts +1 -1
  67. package/dist/chunks/AlphaFoldConfidenceAdapter-VT7X2M4N.js +0 -2
  68. package/dist/chunks/AlphaMissensePathogenicityAdapter-TKOLREIQ.js +0 -2
  69. package/dist/chunks/HelpDialog-IKLXHB3B.js +0 -2
  70. package/dist/chunks/LaunchProteinViewDialog-I2DFRUSD.js +0 -3
  71. package/dist/chunks/LaunchProteinViewDialog-I2DFRUSD.js.map +0 -7
  72. package/dist/chunks/chunk-2KHWAKTL.js +0 -2
  73. package/dist/chunks/chunk-CIZQGPKL.js +0 -2
  74. package/dist/chunks/chunk-HVV3ZRSL.js +0 -2
  75. package/dist/chunks/chunk-HVV3ZRSL.js.map +0 -7
  76. package/dist/chunks/launchProteinView-FD36C2FW.js +0 -2
  77. package/dist/chunks/launchProteinView-FD36C2FW.js.map +0 -7
  78. package/dist/chunks/resolveGeneLaunch-Q3SSFZGF.js +0 -2
  79. /package/dist/chunks/{GenomeTrackColorDialog-VD5NKKQZ.js.map → GenomeTrackColorDialog-EJZ5KTKX.js.map} +0 -0
  80. /package/dist/chunks/{ProteinView-QUCIMT3H.js.map → ProteinView-IM7GNXMQ.js.map} +0 -0
  81. /package/dist/chunks/{chunk-KAP5JKRU.js.map → chunk-22BDSJBC.js.map} +0 -0
  82. /package/dist/chunks/{chunk-XQ5PSSWY.js.map → chunk-7GELEOAH.js.map} +0 -0
  83. /package/dist/chunks/{chunk-FDHODUXS.js.map → chunk-A73LEL2C.js.map} +0 -0
  84. /package/dist/chunks/{chunk-VQRND5DF.js.map → chunk-LVAZFGE6.js.map} +0 -0
  85. /package/dist/chunks/{chunk-2KHWAKTL.js.map → chunk-NCH7IJII.js.map} +0 -0
  86. /package/dist/chunks/{chunk-KL7O7H46.js.map → chunk-TZ54BAT7.js.map} +0 -0
  87. /package/dist/chunks/{launchAnnotationView-5RYUC7P4.js.map → launchAnnotationView-XZ7GDC3Z.js.map} +0 -0
  88. /package/dist/chunks/{launchViewUtils-FTOMSLZU.js.map → launchViewUtils-6INIP22K.js.map} +0 -0
  89. /package/dist/chunks/{model-I3FOCWUA.js.map → model-J5LYRYAB.js.map} +0 -0
  90. /package/dist/chunks/{resolveGeneLaunch-Q3SSFZGF.js.map → resolveGeneLaunch-4AG66E4N.js.map} +0 -0
package/README.md CHANGED
@@ -16,7 +16,8 @@ model in one click, or **Launch protein view** for the dialog that offers every
16
16
  choice. The dialog looks the gene up in UniProt and lists every structure found
17
17
  for it in one list: the AlphaFold model, the experimental PDB entries RCSB maps
18
18
  to that UniProt entry with their partner proteins and ligands, and the complexes
19
- AlphaFold DB predicted, grouped by what each shows. Check several to open them
19
+ AlphaFold DB predicted, grouped by what each shows, led by any structures the
20
+ site lists for the gene in a dataset of its own. Check several to open them
20
21
  superposed in one view. It can also search Foldseek for related structures, or
21
22
  open your own file. The plugin aligns each structure to the transcript's
22
23
  translation, so hovering a residue highlights its codon and hovering a codon
@@ -46,10 +47,11 @@ Using the plugin:
46
47
  map wrong — a peptide bound to a larger partner, a protein bound to DNA, a
47
48
  receptor with another protein fused into it, a phosphorylated residue, and a
48
49
  mitochondrial protein.
49
- - [Your own structures](docs/your-own-structures.md): opening a model you folded
50
- yourself (ColabFold, AlphaFold 3, Boltz…) instead of the AlphaFold DB one,
51
- from a file, a URL or a generated link per gene, and which features carry
52
- over.
50
+ - [Your own structures](docs/your-own-structures.md): opening models you folded
51
+ yourself (ColabFold, AlphaFold 3, Boltz…) beside or instead of AlphaFold DB's:
52
+ a whole genome's worth from one mapping file named in the config, offered in
53
+ the right-click dialog, or one from a file, a URL or a generated link per
54
+ gene, and which features carry over.
53
55
 
54
56
  Linking and embedding:
55
57
 
@@ -73,7 +73,14 @@ function launchStructure(row) {
73
73
  ? { key: row.key, kind: 'alphafold', model: row.model }
74
74
  : row.kind === 'pdb'
75
75
  ? { key: row.key, kind: 'pdb', pdbId: row.entry.pdbId }
76
- : { key: row.key, kind: 'complex', entity: row.complex.entity };
76
+ : row.kind === 'dataset'
77
+ ? {
78
+ key: row.key,
79
+ kind: 'url',
80
+ url: row.match.structure.url,
81
+ uniprotId: row.match.structure.uniprotId,
82
+ }
83
+ : { key: row.key, kind: 'complex', entity: row.complex.entity };
77
84
  }
78
85
  function describeLaunch(rows, typedPdbId, finding) {
79
86
  const [first, ...rest] = rows;
@@ -98,7 +105,9 @@ const GeneStructures = observer(function GeneStructures({ feature, geneName, pre
98
105
  const lookup = useUniProtIdLookup({ feature, view, preferredTranscriptId });
99
106
  const { uniprotId } = lookup;
100
107
  const structures = useGeneStructures({
108
+ jbrowse: session.jbrowse,
101
109
  uniprotId,
110
+ uniprotPending: lookup.isLookupLoading,
102
111
  geneName,
103
112
  feature,
104
113
  view,
@@ -111,7 +120,7 @@ const GeneStructures = observer(function GeneStructures({ feature, geneName, pre
111
120
  const userPick = picked && picked.uniprotId === uniprotId ? picked.keys : undefined;
112
121
  // nothing is checked until the default is known, or the first structure to
113
122
  // arrive would be ranked against and fetched for nothing
114
- const defaultPending = lookup.isLookupLoading || !structures.defaultSettled;
123
+ const defaultPending = !structures.defaultSettled;
115
124
  const checked = userPick ?? (defaultPending ? [] : defaultChecked(rows));
116
125
  const checkedRows = rows.filter(r => checked.includes(r.key));
117
126
  const [sideBySide, setSideBySide] = useState(() => getLaunchSideBySide());
@@ -129,12 +138,16 @@ const GeneStructures = observer(function GeneStructures({ feature, geneName, pre
129
138
  const launchStructures = typedId
130
139
  ? [{ key: `typed:${typedId}`, kind: 'pdb', pdbId: typedId }]
131
140
  : checkedRows.map(launchStructure);
141
+ // a site's structure is mapped through the transcript it is listed under
142
+ const pivotRow = typedId ? undefined : checkedRows[0];
132
143
  const launch = useStructureLaunch({
133
144
  structures: launchStructures,
134
145
  uniprotId,
135
146
  feature,
136
147
  view,
137
- preferredTranscriptId,
148
+ preferredTranscriptId: (pivotRow?.kind === 'dataset'
149
+ ? pivotRow.match.transcript?.id()
150
+ : undefined) ?? preferredTranscriptId,
138
151
  });
139
152
  // RCSB answering that it has no such entry, as opposed to failing to
140
153
  // answer, means the launch would open a view on a 404
@@ -160,7 +173,9 @@ const GeneStructures = observer(function GeneStructures({ feature, geneName, pre
160
173
  ? undefined
161
174
  : launchStructures[0]?.kind === 'alphafold'
162
175
  ? launchStructures[0].model.accession
163
- : uniprotId;
176
+ : launchStructures[0]?.kind === 'url'
177
+ ? (launchStructures[0].uniprotId ?? uniprotId)
178
+ : uniprotId;
164
179
  const toggle = (row) => {
165
180
  setPicked({ uniprotId, keys: toggleStructure(checked, row, rows) });
166
181
  };
@@ -16,7 +16,7 @@ const HelpDialog = observer(function HelpDialog({ handleClose, }) {
16
16
  React.createElement("i", null, "Change"),
17
17
  " picks another), and lists every structure found for it: AlphaFold's model, the experimental PDB entries RCSB aligns to the entry, and the complexes AlphaFold DB predicted with other proteins. The list is grouped by what each structure shows: the protein on its own, the protein with another protein, and short fragments. Check several rows to open them in one view, superposed onto the first; a short fragment opens on its own. ",
18
18
  React.createElement("i", null, "Open by PDB ID"),
19
- " opens any entry instead."),
19
+ " opens any entry instead. When this site lists its own structures for the gene, in a dataset its configuration names, they lead the list under the dataset's name and the first is checked, mapped through the transcript it was folded from."),
20
20
  React.createElement("li", null,
21
21
  React.createElement("b", null, "Similar structures (Foldseek)"),
22
22
  " sends the protein sequence to the foldseek.com servers and lists structures similar in shape, including ones with little sequence similarity."),
@@ -128,7 +128,9 @@ const Quality = observer(function Quality({ row }) {
128
128
  React.createElement(Plddt, { value: row.model.meanPlddt }),
129
129
  React.createElement(Typography, { variant: "caption", color: "textSecondary" },
130
130
  "AlphaFold DB",
131
- version ? ` v${version}` : ''))) : row.kind === 'complex' ? (React.createElement(React.Fragment, null,
131
+ version ? ` v${version}` : ''))) : row.kind === 'dataset' ? (React.createElement(React.Fragment, null,
132
+ React.createElement(Typography, { variant: "body2" }, row.match.dataset.name),
133
+ row.match.dataset.description ? (React.createElement(Typography, { variant: "caption", color: "textSecondary" }, row.match.dataset.description)) : null)) : row.kind === 'complex' ? (React.createElement(React.Fragment, null,
132
134
  row.complex.iptm === undefined ? null : (React.createElement(Typography, { variant: "body2" },
133
135
  "ipTM ",
134
136
  row.complex.iptm.toFixed(2))),
@@ -187,6 +189,8 @@ const StructureListRow = observer(function StructureListRow({ row, checked, unip
187
189
  React.createElement(Tags, { tags: row.ligands, className: classes.ligand }),
188
190
  React.createElement(Tags, { tags: row.notes }))) : null),
189
191
  React.createElement(Quality, { row: row }),
190
- React.createElement(Coverage, { start: row.start, end: row.end, length: uniprotLength })));
192
+ row.kind === 'dataset' ? (React.createElement(Typography, { variant: "caption", color: "textSecondary" },
193
+ "listed as ",
194
+ row.match.structure.id)) : (React.createElement(Coverage, { start: row.start, end: row.end, length: uniprotLength }))));
191
195
  });
192
196
  export default StructureListRow;
@@ -0,0 +1,45 @@
1
+ import { useMemo } from 'react';
2
+ import useSWR from 'swr';
3
+ import { STATIC_SWR_OPTIONS } from './swrOptions';
4
+ import { errorMessage } from '../../ProteinView/util';
5
+ import { datasetMatches, hostPluginManager, loadStructureMapping, readStructureDatasets, } from '../utils/structureDatasets';
6
+ /**
7
+ * The structures the config's datasets list for a gene. Every mapping file is
8
+ * read once a page; one that fails leaves a line naming it, and the rest are
9
+ * offered as usual.
10
+ */
11
+ export default function useDatasetStructures({ jbrowse, feature, preferredTranscriptId, }) {
12
+ const datasets = useMemo(() => readStructureDatasets(jbrowse), [jbrowse]);
13
+ const pluginManager = hostPluginManager(jbrowse);
14
+ const { data, isLoading } = useSWR(datasets.length > 0
15
+ ? [
16
+ 'structure-datasets',
17
+ ...datasets.map(d => `${d.datasetId} ${JSON.stringify(d.mappingLocation)}`),
18
+ ]
19
+ : null, () => Promise.allSettled(datasets.map(d => loadStructureMapping(d, pluginManager))), STATIC_SWR_OPTIONS);
20
+ const matches = useMemo(() => datasets.flatMap((dataset, i) => {
21
+ const result = data?.[i];
22
+ return result?.status === 'fulfilled'
23
+ ? datasetMatches({
24
+ dataset,
25
+ mapping: result.value,
26
+ feature,
27
+ preferredTranscriptId,
28
+ })
29
+ : [];
30
+ }), [datasets, data, feature, preferredTranscriptId]);
31
+ const notices = datasets.flatMap((dataset, i) => {
32
+ const result = data?.[i];
33
+ return result?.status === 'rejected'
34
+ ? [
35
+ `${dataset.name}'s structure list did not load: ${errorMessage(result.reason)}`,
36
+ ]
37
+ : [];
38
+ });
39
+ return {
40
+ matches,
41
+ notices,
42
+ isLoading,
43
+ loadingMessage: `Reading ${datasets.map(d => d.name).join(', ')}`,
44
+ };
45
+ }
@@ -1,10 +1,11 @@
1
1
  import { useMemo } from 'react';
2
2
  import { useAlphaFoldComplexes } from './useAlphaFoldComplexes';
3
3
  import useAlphaFoldData from './useAlphaFoldData';
4
+ import useDatasetStructures from './useDatasetStructures';
4
5
  import useExperimentalStructures from './useExperimentalStructures';
5
6
  import usePdbEntrySummaries from './usePdbEntrySummaries';
6
7
  import { errorMessage } from '../../ProteinView/util';
7
- import { listOrder, structureRows } from '../utils/structureList';
8
+ import { datasetRow, listOrder, structureRows } from '../utils/structureList';
8
9
  function isText(value) {
9
10
  return typeof value === 'string';
10
11
  }
@@ -23,12 +24,19 @@ function sectionStatus(lines) {
23
24
  };
24
25
  }
25
26
  /**
26
- * Every structure of the gene's protein, from AlphaFold DB's models and
27
- * complexes and RCSB's entries, each source loading and failing on its own:
28
- * what one source has found is listed while another is still asking, and a
29
- * source that fails leaves a line in the sections it would have filled.
27
+ * Every structure of the gene's protein, from the site's own datasets,
28
+ * AlphaFold DB's models and complexes and RCSB's entries, each source loading
29
+ * and failing on its own: what one source has found is listed while another
30
+ * is still asking, and a source that fails leaves a line in the sections it
31
+ * would have filled. A dataset lists its structures by the gene's own ids, so
32
+ * they need no UniProt accession.
30
33
  */
31
- export default function useGeneStructures({ uniprotId, geneName, feature, view, preferredTranscriptId, }) {
34
+ export default function useGeneStructures({ jbrowse, uniprotId, uniprotPending, geneName, feature, view, preferredTranscriptId, }) {
35
+ const datasets = useDatasetStructures({
36
+ jbrowse,
37
+ feature,
38
+ preferredTranscriptId,
39
+ });
32
40
  const alphaFold = useAlphaFoldData({
33
41
  uniprotId,
34
42
  feature,
@@ -45,17 +53,21 @@ export default function useGeneStructures({ uniprotId, geneName, feature, view,
45
53
  const uniprotLength = alphaFold.entryLength ??
46
54
  alphaFold.model?.sequence?.length ??
47
55
  Math.max(1, ...(entries ?? []).map(e => e.end));
48
- const rows = useMemo(() => uniprotId
49
- ? listOrder(structureRows({
50
- geneName,
51
- uniprotId,
52
- uniprotLength,
53
- alphaFold: alphaFold.isLoading ? undefined : alphaFold.model,
54
- entries: entriesReady ? entries : undefined,
55
- summaries: summaries.summaries,
56
- complexes: complexes.complexes,
57
- }))
58
- : [], [
56
+ const rows = useMemo(() => listOrder([
57
+ ...datasets.matches.map(match => datasetRow({ match, geneName, uniprotLength })),
58
+ ...(uniprotId
59
+ ? structureRows({
60
+ geneName,
61
+ uniprotId,
62
+ uniprotLength,
63
+ alphaFold: alphaFold.isLoading ? undefined : alphaFold.model,
64
+ entries: entriesReady ? entries : undefined,
65
+ summaries: summaries.summaries,
66
+ complexes: complexes.complexes,
67
+ })
68
+ : []),
69
+ ]), [
70
+ datasets.matches,
59
71
  uniprotId,
60
72
  geneName,
61
73
  uniprotLength,
@@ -67,8 +79,18 @@ export default function useGeneStructures({ uniprotId, geneName, feature, view,
67
79
  complexes.complexes,
68
80
  ]);
69
81
  const pdb = ['alone', 'partner', 'fragment'];
70
- const sections = uniprotId
71
- ? sectionStatus([
82
+ const datasetLines = [
83
+ {
84
+ sections: ['alone'],
85
+ loading: datasets.isLoading && datasets.loadingMessage,
86
+ },
87
+ ...datasets.notices.map(notice => ({
88
+ sections: ['alone'],
89
+ notice,
90
+ })),
91
+ ];
92
+ const uniprotLines = uniprotId
93
+ ? [
72
94
  {
73
95
  sections: ['alone'],
74
96
  loading: alphaFold.isLoading && 'Asking AlphaFold DB for models',
@@ -101,19 +123,25 @@ export default function useGeneStructures({ uniprotId, geneName, feature, view,
101
123
  notice: complexes.error !== undefined &&
102
124
  `AlphaFold DB's complex list did not answer: ${errorMessage(complexes.error)}`,
103
125
  },
104
- ])
105
- : undefined;
126
+ ]
127
+ : [];
128
+ const sections = sectionStatus([...datasetLines, ...uniprotLines]);
129
+ const hasDatasetRow = datasets.matches.length > 0;
106
130
  return {
107
131
  rows,
108
132
  uniprotLength,
109
133
  sections,
110
134
  alphaFold,
111
- // the default pick is the AlphaFold model, else the first row listed, so
112
- // it is known once AlphaFold DB has answered, or everything has
113
- defaultSettled: !alphaFold.isLoading &&
114
- (!!alphaFold.model ||
115
- !(experimental.isLoading ||
116
- summaries.isLoading ||
117
- complexes.isLoading)),
135
+ // the default pick is a dataset's structure, else the AlphaFold model,
136
+ // else the first row listed, so it is known once the datasets have loaded
137
+ // and listed one, or AlphaFold DB has answered, or everything has
138
+ defaultSettled: !datasets.isLoading &&
139
+ (hasDatasetRow ||
140
+ (!uniprotPending &&
141
+ !alphaFold.isLoading &&
142
+ (!!alphaFold.model ||
143
+ !(experimental.isLoading ||
144
+ summaries.isLoading ||
145
+ complexes.isLoading)))),
118
146
  };
119
147
  }
@@ -2,13 +2,16 @@ import { useMemo } from 'react';
2
2
  import { getPdbStructureUrl, sameProtein } from 'p2s_mapper';
3
3
  import { useAlphaFoldComplexModel } from './useAlphaFoldComplexes';
4
4
  import usePdbEntry from './usePdbEntry';
5
+ import useStructureFileSequence from './useStructureFileSequence';
5
6
  import useTranscriptIsoformSelection from './useTranscriptIsoformSelection';
6
7
  export function structureSource(structure) {
7
8
  return structure.kind === 'alphafold'
8
9
  ? { url: structure.model.url }
9
10
  : structure.kind === 'pdb'
10
11
  ? { url: getPdbStructureUrl(structure.pdbId) }
11
- : { alphaFoldComplexId: structure.entity };
12
+ : structure.kind === 'url'
13
+ ? { url: structure.url, uniprotId: structure.uniprotId }
14
+ : { alphaFoldComplexId: structure.entity };
12
15
  }
13
16
  /**
14
17
  * The transcript a launch maps every structure through, ranked against the
@@ -21,11 +24,15 @@ export default function useStructureLaunch({ structures, uniprotId, feature, vie
21
24
  const pivot = structures[0];
22
25
  const pdb = usePdbEntry(pivot?.kind === 'pdb' ? pivot.pdbId : undefined);
23
26
  const complex = useAlphaFoldComplexModel(pivot?.kind === 'complex' ? pivot.entity : undefined);
27
+ const file = useStructureFileSequence({
28
+ url: pivot?.kind === 'url' ? pivot.url : undefined,
29
+ });
24
30
  const entry = uniprotId?.replace(/-\d+$/, '');
25
31
  const complexChains = complex.model?.chains;
26
32
  const ownChain = complexChains?.find(c => c.accession === entry);
27
33
  const alphaFoldSequence = pivot?.kind === 'alphafold' ? pivot.model.sequence : undefined;
28
34
  const pdbSequences = pdb.entry?.proteinSequences;
35
+ const fileSequences = file.sequences;
29
36
  // a stable array, or the isoform picker realigns on every render
30
37
  const structureSequences = useMemo(() => pivot?.kind === 'alphafold'
31
38
  ? alphaFoldSequence
@@ -33,9 +40,18 @@ export default function useStructureLaunch({ structures, uniprotId, feature, vie
33
40
  : undefined
34
41
  : pivot?.kind === 'pdb'
35
42
  ? pdbSequences
36
- : ownChain
37
- ? [ownChain.sequence]
38
- : complexChains?.map(c => c.sequence), [pivot?.kind, alphaFoldSequence, pdbSequences, ownChain, complexChains]);
43
+ : pivot?.kind === 'url'
44
+ ? fileSequences
45
+ : ownChain
46
+ ? [ownChain.sequence]
47
+ : complexChains?.map(c => c.sequence), [
48
+ pivot?.kind,
49
+ alphaFoldSequence,
50
+ pdbSequences,
51
+ fileSequences,
52
+ ownChain,
53
+ complexChains,
54
+ ]);
39
55
  const selection = useTranscriptIsoformSelection({
40
56
  feature,
41
57
  view,
@@ -48,24 +64,31 @@ export default function useStructureLaunch({ structures, uniprotId, feature, vie
48
64
  // The right-clicked isoform needs no ranking and launches at once. An entry
49
65
  // RCSB cannot describe stops holding the launch.
50
66
  const awaitsChains = selection.selectedTranscriptId !== preferredTranscriptId &&
51
- ((pdb.isValidating && !pdb.error) || complex.isLoading);
67
+ ((pdb.isValidating && !pdb.error) || complex.isLoading || file.isLoading);
52
68
  const loadingStatuses = [
53
69
  selection.isLoading && 'Loading protein sequences from transcript isoforms',
54
70
  selection.isRanking && 'Aligning isoforms to the structure',
55
71
  awaitsChains &&
56
72
  (pivot?.kind === 'pdb'
57
73
  ? 'Reading the chains of the entry from RCSB'
58
- : 'Asking AlphaFold DB for the complex'),
74
+ : pivot?.kind === 'url'
75
+ ? 'Reading residues from the structure'
76
+ : 'Asking AlphaFold DB for the complex'),
59
77
  ].filter(s => typeof s === 'string');
60
78
  const isLoading = loadingStatuses.length > 0;
61
- const predicted = pivot?.kind === 'alphafold' || pivot?.kind === 'complex';
79
+ // a site's own structure is folded from the transcript it is listed under
80
+ const predicted = pivot?.kind === 'alphafold' ||
81
+ pivot?.kind === 'complex' ||
82
+ pivot?.kind === 'url';
62
83
  const isoformSequence = selection.selectedIsoform?.seq;
63
84
  return {
64
85
  ...selection,
65
86
  loadingStatuses,
66
87
  isLoading,
67
88
  // errors wait for loading to finish, so a lookup in flight doesn't flash one
68
- error: isLoading ? undefined : (selection.error ?? complex.error),
89
+ error: isLoading
90
+ ? undefined
91
+ : (selection.error ?? complex.error ?? file.error),
69
92
  pdbEntryError: pdb.error,
70
93
  // only a prediction is meant to be the transcript's own protein; a crystal
71
94
  // is a construct, usually of one domain
@@ -0,0 +1,179 @@
1
+ import { isConfigurationModel, readConfObject, } from '@jbrowse/core/configuration';
2
+ import { fetchAndMaybeUnzipText, isUriLocation } from '@jbrowse/core/util';
3
+ import { openLocation } from '@jbrowse/core/util/io';
4
+ import { getEnv, isStateTreeNode } from '@jbrowse/mobx-state-tree';
5
+ import { isRecord } from './isRecord';
6
+ import { codingTranscripts, flaggedTranscriptId } from '../codingFeature';
7
+ function text(value) {
8
+ return typeof value === 'string' ? value : '';
9
+ }
10
+ function readDataset(value) {
11
+ const location = isRecord(value) ? value.mappingLocation : undefined;
12
+ return isRecord(value) &&
13
+ isUriLocation(location) &&
14
+ text(value.datasetId) !== ''
15
+ ? [
16
+ {
17
+ datasetId: text(value.datasetId),
18
+ name: text(value.name) || text(value.datasetId),
19
+ description: text(value.description),
20
+ mappingLocation: location,
21
+ },
22
+ ]
23
+ : [];
24
+ }
25
+ /**
26
+ * The datasets the config declares, each with an id and a mapping file. The
27
+ * slot is the plugin's root configuration schema, which the host mounts on its
28
+ * config model beside the members the core type names.
29
+ */
30
+ export function readStructureDatasets(jbrowse) {
31
+ const conf = 'protein3d' in jbrowse ? jbrowse.protein3d : undefined;
32
+ const datasets = isConfigurationModel(conf)
33
+ ? readConfObject(conf, 'datasets')
34
+ : undefined;
35
+ return Array.isArray(datasets) ? datasets.flatMap(readDataset) : [];
36
+ }
37
+ const ID_PREFIX = /^(?:transcript:|gene:|rna-|gene-|cds-)/;
38
+ const VERSION = /\.\d+$/;
39
+ function bareId(id) {
40
+ return id.trim().replace(ID_PREFIX, '');
41
+ }
42
+ function append(map, key, value) {
43
+ const list = map.get(key);
44
+ if (list) {
45
+ list.push(value);
46
+ }
47
+ else {
48
+ map.set(key, [value]);
49
+ }
50
+ }
51
+ /**
52
+ * A mapping file's rows by id: tab-separated id, structure url, and optionally
53
+ * a UniProt accession and a label. A line starting with `#` is a comment. Only
54
+ * the id is read here; a row's other fields wait until a gene asks for it, which
55
+ * keeps a 60,000-row file to one pass of `indexOf`.
56
+ */
57
+ export function parseStructureMapping(content, baseUrl) {
58
+ const lines = new Map();
59
+ for (const line of content.split('\n')) {
60
+ const tab = line.indexOf('\t');
61
+ const id = tab > 0 && !line.startsWith('#') ? bareId(line.slice(0, tab)) : '';
62
+ if (id !== '') {
63
+ append(lines, id.replace(VERSION, ''), line);
64
+ }
65
+ }
66
+ return { baseUrl, lines };
67
+ }
68
+ function readRow(line, baseUrl) {
69
+ const [id = '', url = '', uniprotId = '', label = ''] = line
70
+ .replace(/\r$/, '')
71
+ .split('\t')
72
+ .map(field => field.trim());
73
+ return url === '' || !URL.canParse(url, baseUrl)
74
+ ? []
75
+ : [
76
+ {
77
+ id,
78
+ url: new URL(url, baseUrl).href,
79
+ uniprotId: uniprotId || undefined,
80
+ label: label || undefined,
81
+ },
82
+ ];
83
+ }
84
+ /**
85
+ * The structures listed under an id, with urls read against the mapping file.
86
+ * A version written on only one side is ignored, so `ENST00000369535` finds
87
+ * `ENST00000369535.5` and the other way round, but two different versions are
88
+ * two different transcripts: TAIR's `AT1G01010.2` is not `AT1G01010.1`.
89
+ */
90
+ export function structuresFor(mapping, rawId) {
91
+ const id = bareId(rawId);
92
+ const base = id.replace(VERSION, '');
93
+ const listed = (mapping.lines.get(base) ?? []).flatMap(line => readRow(line, mapping.baseUrl));
94
+ const exact = listed.filter(s => bareId(s.id) === id);
95
+ return exact.length > 0
96
+ ? exact
97
+ : base === id
98
+ ? listed
99
+ : listed.filter(s => bareId(s.id) === base);
100
+ }
101
+ function idsOf(feature, attributes) {
102
+ return [
103
+ ...new Set(attributes.map(a => feature.get(a)).filter(v => typeof v === 'string')),
104
+ ];
105
+ }
106
+ const TRANSCRIPT_IDS = ['name', 'Name', 'id', 'ID', 'transcript_id'];
107
+ const PROTEIN_IDS = ['protein_id'];
108
+ const GENE_IDS = ['gene_name', 'gene', 'name', 'Name', 'gene_id', 'id', 'ID'];
109
+ function transcriptIds(transcript) {
110
+ const cds = transcript
111
+ .get('subfeatures')
112
+ ?.find(sub => sub.get('type')?.toLowerCase() === 'cds');
113
+ return [
114
+ ...idsOf(transcript, [...TRANSCRIPT_IDS, ...PROTEIN_IDS]),
115
+ ...(cds ? idsOf(cds, PROTEIN_IDS) : []),
116
+ ];
117
+ }
118
+ function lookUp(mapping, ids) {
119
+ return ids.flatMap(id => structuresFor(mapping, id));
120
+ }
121
+ /** The right-clicked isoform first, then the one flagged representative */
122
+ function transcriptOrder(feature, preferredTranscriptId) {
123
+ const transcripts = codingTranscripts(feature);
124
+ const flagged = flaggedTranscriptId(transcripts);
125
+ const rank = (t) => t.id() === preferredTranscriptId ? 0 : t.id() === flagged ? 1 : 2;
126
+ return transcripts
127
+ .map((t, i) => ({ t, i }))
128
+ .sort((a, b) => rank(a.t) - rank(b.t) || a.i - b.i)
129
+ .map(({ t }) => t);
130
+ }
131
+ /**
132
+ * What a dataset holds for a gene: a structure listed under one of its coding
133
+ * transcripts, by any of the transcript's ids or its protein's, else under the
134
+ * gene itself. Each structure appears once, under the first id that names it.
135
+ */
136
+ export function datasetMatches({ dataset, mapping, feature, preferredTranscriptId, }) {
137
+ const byTranscript = transcriptOrder(feature, preferredTranscriptId).flatMap(transcript => lookUp(mapping, transcriptIds(transcript)).map(structure => ({
138
+ dataset,
139
+ structure,
140
+ transcript,
141
+ })));
142
+ const byGene = lookUp(mapping, idsOf(feature, GENE_IDS)).map(structure => ({
143
+ dataset,
144
+ structure,
145
+ }));
146
+ const seen = new Set();
147
+ return [...byTranscript, ...byGene].filter(match => {
148
+ const fresh = !seen.has(match.structure.url);
149
+ seen.add(match.structure.url);
150
+ return fresh;
151
+ });
152
+ }
153
+ /** Where the mapping file is, which its relative urls are read against */
154
+ export function mappingUrl(location) {
155
+ return isUriLocation(location)
156
+ ? new URL(location.uri, location.baseUri ?? window.location.href).href
157
+ : window.location.href;
158
+ }
159
+ /** The host's, for a mapping file behind one of its internet accounts */
160
+ export function hostPluginManager(jbrowse) {
161
+ return isStateTreeNode(jbrowse)
162
+ ? getEnv(jbrowse).pluginManager
163
+ : undefined;
164
+ }
165
+ const loaded = new Map();
166
+ /**
167
+ * A dataset's mapping, fetched once a page however many dialogs and launches
168
+ * read it. A failed fetch is forgotten, so the next dialog asks again.
169
+ */
170
+ export function loadStructureMapping(dataset, pluginManager) {
171
+ const url = mappingUrl(dataset.mappingLocation);
172
+ const pending = loaded.get(url) ??
173
+ fetchAndMaybeUnzipText(openLocation(dataset.mappingLocation, pluginManager)).then(content => parseStructureMapping(content, url));
174
+ loaded.set(url, pending);
175
+ pending.catch(() => {
176
+ loaded.delete(url);
177
+ });
178
+ return pending;
179
+ }
@@ -1,4 +1,5 @@
1
1
  import { pdbEntryPartners, rcsbEntryUrl } from 'p2s_mapper';
2
+ import { getTranscriptDisplayName } from './util';
2
3
  import { CRYSTALLIZATION_ADDITIVES } from '../../ProteinView/crystallizationAdditives';
3
4
  /** Below this share of the protein a structure is a peptide or one small
4
5
  * domain, too short for TM-align to place beside the whole protein */
@@ -180,6 +181,34 @@ function alphaFoldRow({ model, uniprotId, uniprotLength, }) {
180
181
  end: Math.min(model.sequence?.length ?? uniprotLength, uniprotLength),
181
182
  };
182
183
  }
184
+ function fileName(url) {
185
+ return decodeURIComponent(new URL(url).pathname.split('/').pop() ?? url);
186
+ }
187
+ /**
188
+ * A structure a site's dataset lists for the gene, as one of the protein on
189
+ * its own: what a site folds is the transcript's whole translation. Its
190
+ * residues are not known until it loads, so it claims the whole protein.
191
+ */
192
+ export function datasetRow({ match, geneName, uniprotLength, }) {
193
+ const { dataset, structure, transcript } = match;
194
+ return {
195
+ kind: 'dataset',
196
+ key: `dataset:${dataset.datasetId}:${structure.id}:${fileName(structure.url)}`,
197
+ match,
198
+ section: 'alone',
199
+ predicted: true,
200
+ label: structure.label ?? fileName(structure.url),
201
+ href: structure.url,
202
+ title: transcript
203
+ ? `${dataset.name} model of transcript ${getTranscriptDisplayName(transcript) || structure.id}`
204
+ : `${dataset.name} model of ${geneName}`,
205
+ partners: [],
206
+ ligands: [],
207
+ notes: [],
208
+ start: 1,
209
+ end: uniprotLength,
210
+ };
211
+ }
183
212
  /**
184
213
  * Every structure for a gene's protein in the order the dialog lists them:
185
214
  * the AlphaFold model, the PDB entries as RCSB ranks them, then the complexes
@@ -225,8 +254,15 @@ export const SECTIONS = [
225
254
  export function listOrder(rows) {
226
255
  return SECTIONS.flatMap(section => rows.filter(r => r.section === section));
227
256
  }
228
- /** The AlphaFold model when there is one, else the list's first structure */
257
+ /**
258
+ * A site's own structure when its datasets list one, else the AlphaFold model,
259
+ * else the list's first structure. The site's leads because it was folded from
260
+ * the transcript its mapping names, so the launch maps through that transcript
261
+ * with no ranking, and because a site's genome often has no AlphaFold model.
262
+ */
229
263
  export function defaultChecked(rows) {
230
- const first = rows.find(r => r.kind === 'alphafold') ?? listOrder(rows)[0];
264
+ const first = rows.find(r => r.kind === 'dataset') ??
265
+ rows.find(r => r.kind === 'alphafold') ??
266
+ listOrder(rows)[0];
231
267
  return first ? [first.key] : [];
232
268
  }