jbrowse-plugin-protein3d 1.8.0 → 1.9.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/AlignTranscriptRpc/index.js +5 -25
  2. package/dist/AlignTranscriptRpc/isoformRanking.js +24 -0
  3. package/dist/LaunchProteinView/components/FoldseekActionMenu.js +1 -1
  4. package/dist/LaunchProteinView/components/ProteinViewActions.js +1 -3
  5. package/dist/LaunchProteinView/components/UserProvidedStructure.js +1 -1
  6. package/dist/LaunchProteinView/hooks/useIsoformRanking.js +1 -1
  7. package/dist/LaunchProteinView/hooks/useTranscriptSelection.js +1 -1
  8. package/dist/LaunchProteinView/index.js +8 -4
  9. package/dist/LaunchProteinView/resolveGeneLaunch.js +1 -1
  10. package/dist/LaunchProteinView/services/foldseekApi.js +13 -186
  11. package/dist/LaunchProteinView/utils/launchViewUtils.js +3 -2
  12. package/dist/LaunchProteinViewExtensionPoint/annotationView.js +5 -80
  13. package/dist/LaunchProteinViewExtensionPoint/index.js +7 -85
  14. package/dist/LaunchProteinViewExtensionPoint/launchAnnotationView.js +82 -0
  15. package/dist/LaunchProteinViewExtensionPoint/launchProteinView.js +83 -0
  16. package/dist/ProteinView/addProteinView.js +12 -0
  17. package/dist/ProteinView/index.js +1 -2
  18. package/dist/chunks/AddStructureDialog-XJLVGA3J.js +2 -0
  19. package/dist/chunks/{AddStructureDialog-Z5HMGUWS.js.map → AddStructureDialog-XJLVGA3J.js.map} +1 -1
  20. package/dist/chunks/{HelpDialog-IRAXBGZB.js → HelpDialog-XVM5IEP4.js} +2 -2
  21. package/dist/chunks/LaunchProteinViewDialog-HVGICMXL.js +2 -0
  22. package/dist/chunks/LaunchProteinViewDialog-HVGICMXL.js.map +7 -0
  23. package/dist/chunks/{ManualAlignmentDialog-BTL4LYX2.js → ManualAlignmentDialog-A5WPMFVH.js} +2 -2
  24. package/dist/chunks/{ProteinAlignmentHelpDialog-LURGMLCI.js → ProteinAlignmentHelpDialog-BNW2WV6D.js} +2 -2
  25. package/dist/chunks/{ProteinView-YFTN6FW3.js → ProteinView-BN6ZKXAS.js} +3 -3
  26. package/dist/chunks/{ProteinView-YFTN6FW3.js.map → ProteinView-BN6ZKXAS.js.map} +1 -1
  27. package/dist/chunks/chunk-2LPERV4E.js +2 -0
  28. package/dist/chunks/chunk-2LPERV4E.js.map +7 -0
  29. package/dist/chunks/chunk-2VSFBM55.js +2 -0
  30. package/dist/chunks/chunk-2VSFBM55.js.map +7 -0
  31. package/dist/chunks/chunk-3PBX6WQ7.js +2 -0
  32. package/dist/chunks/chunk-3PBX6WQ7.js.map +7 -0
  33. package/dist/chunks/chunk-56ZPPPNO.js +2 -0
  34. package/dist/chunks/chunk-56ZPPPNO.js.map +7 -0
  35. package/dist/chunks/chunk-5M4LVDLT.js +2 -0
  36. package/dist/chunks/chunk-5M4LVDLT.js.map +7 -0
  37. package/dist/chunks/chunk-6I2O347B.js +2 -0
  38. package/dist/chunks/chunk-6I2O347B.js.map +7 -0
  39. package/dist/chunks/chunk-7HD7P6NI.js +2 -0
  40. package/dist/chunks/chunk-7HD7P6NI.js.map +7 -0
  41. package/dist/chunks/chunk-7UQOTULP.js +2 -0
  42. package/dist/chunks/chunk-7UQOTULP.js.map +7 -0
  43. package/dist/chunks/chunk-ASJJTAZT.js +2 -0
  44. package/dist/chunks/chunk-ASJJTAZT.js.map +7 -0
  45. package/dist/chunks/chunk-C6C6ZP3E.js +2 -0
  46. package/dist/chunks/chunk-C6C6ZP3E.js.map +7 -0
  47. package/dist/chunks/chunk-CAYS7ALN.js +2 -0
  48. package/dist/chunks/chunk-CAYS7ALN.js.map +7 -0
  49. package/dist/chunks/{chunk-7Q7UK2ZL.js → chunk-CU6NAWYQ.js} +2 -2
  50. package/dist/chunks/chunk-GEIZQIY6.js +2 -0
  51. package/dist/chunks/chunk-GEIZQIY6.js.map +7 -0
  52. package/dist/chunks/chunk-KJFSUZGF.js +3 -0
  53. package/dist/chunks/chunk-KJFSUZGF.js.map +7 -0
  54. package/dist/chunks/chunk-NX4AZNUA.js +2 -0
  55. package/dist/chunks/chunk-NX4AZNUA.js.map +7 -0
  56. package/dist/chunks/chunk-NZ3TO6NV.js +2 -0
  57. package/dist/chunks/chunk-NZ3TO6NV.js.map +7 -0
  58. package/dist/chunks/chunk-OZJGL4WP.js +2 -0
  59. package/dist/chunks/chunk-OZJGL4WP.js.map +7 -0
  60. package/dist/chunks/chunk-P24I4JTG.js +2 -0
  61. package/dist/chunks/chunk-P24I4JTG.js.map +7 -0
  62. package/dist/chunks/chunk-S6PS4I6X.js +2 -0
  63. package/dist/chunks/chunk-S6PS4I6X.js.map +7 -0
  64. package/dist/chunks/chunk-UVDYWAS6.js +2 -0
  65. package/dist/chunks/chunk-UVDYWAS6.js.map +7 -0
  66. package/dist/chunks/chunk-WZCSPP5F.js +30 -0
  67. package/dist/chunks/chunk-WZCSPP5F.js.map +7 -0
  68. package/dist/chunks/chunk-X47I2IB5.js +15 -0
  69. package/dist/chunks/chunk-X47I2IB5.js.map +7 -0
  70. package/dist/chunks/chunk-Y6AFPMX7.js +2 -0
  71. package/dist/chunks/chunk-Y6AFPMX7.js.map +7 -0
  72. package/dist/chunks/chunk-YCRC6WEC.js +2 -0
  73. package/dist/chunks/chunk-YCRC6WEC.js.map +7 -0
  74. package/dist/chunks/clinVarSource-W77HO5ZQ.js +2 -0
  75. package/dist/chunks/esm-LTN2BDGE.js +2 -0
  76. package/dist/chunks/esm-LTN2BDGE.js.map +7 -0
  77. package/dist/chunks/isoformRanking-NNKTCHEX.js +2 -0
  78. package/dist/chunks/isoformRanking-NNKTCHEX.js.map +7 -0
  79. package/dist/chunks/launchAnnotationView-5ASN5337.js +2 -0
  80. package/dist/chunks/launchAnnotationView-5ASN5337.js.map +7 -0
  81. package/dist/chunks/launchProteinView-VQ4UQSZK.js +2 -0
  82. package/dist/chunks/launchProteinView-VQ4UQSZK.js.map +7 -0
  83. package/dist/chunks/launchViewUtils-CVGF4H5D.js +2 -0
  84. package/dist/chunks/launchViewUtils-CVGF4H5D.js.map +7 -0
  85. package/dist/chunks/model-ZEMQIRBO.js +2 -0
  86. package/dist/chunks/model-ZEMQIRBO.js.map +7 -0
  87. package/dist/chunks/resolveGeneLaunch-3TT7UL33.js +2 -0
  88. package/dist/chunks/resolveGeneLaunch-3TT7UL33.js.map +7 -0
  89. package/dist/jbrowse-plugin-protein3d.esm.js +1 -29
  90. package/dist/jbrowse-plugin-protein3d.esm.js.map +4 -4
  91. package/dist/version.js +1 -1
  92. package/package.json +2 -2
  93. package/src/AlignTranscriptRpc/index.ts +6 -48
  94. package/src/AlignTranscriptRpc/isoformRanking.ts +42 -0
  95. package/src/LaunchProteinView/components/FoldseekActionMenu.tsx +1 -1
  96. package/src/LaunchProteinView/components/ProteinViewActions.tsx +3 -3
  97. package/src/LaunchProteinView/components/UserProvidedStructure.tsx +1 -1
  98. package/src/LaunchProteinView/hooks/useIsoformRanking.ts +2 -2
  99. package/src/LaunchProteinView/hooks/useTranscriptSelection.test.ts +1 -1
  100. package/src/LaunchProteinView/hooks/useTranscriptSelection.ts +1 -1
  101. package/src/LaunchProteinView/index.ts +15 -8
  102. package/src/LaunchProteinView/resolveGeneLaunch.test.ts +1 -1
  103. package/src/LaunchProteinView/resolveGeneLaunch.ts +5 -2
  104. package/src/LaunchProteinView/services/foldseekApi.ts +34 -274
  105. package/src/LaunchProteinView/utils/launchViewUtils.ts +3 -2
  106. package/src/LaunchProteinViewExtensionPoint/annotationView.ts +7 -96
  107. package/src/LaunchProteinViewExtensionPoint/index.ts +7 -177
  108. package/src/LaunchProteinViewExtensionPoint/launchAnnotationView.ts +102 -0
  109. package/src/LaunchProteinViewExtensionPoint/launchProteinView.ts +178 -0
  110. package/src/LaunchProteinViewExtensionPoint/launchViewSnapshot.test.ts +1 -1
  111. package/src/ProteinView/addProteinView.ts +18 -0
  112. package/src/ProteinView/index.ts +1 -3
  113. package/src/version.ts +1 -1
  114. package/dist/chunks/AddStructureDialog-Z5HMGUWS.js +0 -2
  115. package/dist/chunks/chunk-C2KRWQQY.js +0 -2
  116. package/dist/chunks/chunk-C2KRWQQY.js.map +0 -7
  117. package/dist/chunks/chunk-EXD7S43Q.js +0 -16
  118. package/dist/chunks/chunk-EXD7S43Q.js.map +0 -7
  119. package/dist/chunks/chunk-QPR5H2OZ.js +0 -2
  120. package/dist/chunks/chunk-QPR5H2OZ.js.map +0 -7
  121. package/dist/chunks/chunk-R46YRV6D.js +0 -2
  122. package/dist/chunks/chunk-R46YRV6D.js.map +0 -7
  123. package/dist/chunks/chunk-RIAQ5NV7.js +0 -2
  124. package/dist/chunks/chunk-RIAQ5NV7.js.map +0 -7
  125. package/dist/chunks/clinVarSource-LCO5EZ6C.js +0 -2
  126. /package/dist/chunks/{HelpDialog-IRAXBGZB.js.map → HelpDialog-XVM5IEP4.js.map} +0 -0
  127. /package/dist/chunks/{ManualAlignmentDialog-BTL4LYX2.js.map → ManualAlignmentDialog-A5WPMFVH.js.map} +0 -0
  128. /package/dist/chunks/{ProteinAlignmentHelpDialog-LURGMLCI.js.map → ProteinAlignmentHelpDialog-BNW2WV6D.js.map} +0 -0
  129. /package/dist/chunks/{chunk-7Q7UK2ZL.js.map → chunk-CU6NAWYQ.js.map} +0 -0
  130. /package/dist/chunks/{clinVarSource-LCO5EZ6C.js.map → clinVarSource-W77HO5ZQ.js.map} +0 -0
@@ -1,47 +1,27 @@
1
1
  import { RpcMethodType } from '@jbrowse/core/pluggableElementTypes';
2
- import { alignTranscriptToEntity, chooseMappedEntity, classifyIsoforms, pickStructureSequence, } from 'p2s_mapper';
3
- /** The launch dialog's isoform order: one alignment per chain to pick the
4
- * chain, then one per isoform that does not match it exactly. */
5
- export function rankIsoforms(isoforms, structureSequences) {
6
- const structureSequence = pickStructureSequence(structureSequences, isoforms);
7
- return {
8
- structureSequence,
9
- ranking: classifyIsoforms({ isoforms, structureSequence }),
10
- };
11
- }
12
- /**
13
- * The isoform to open from a ranking. An exact match to the structure wins;
14
- * the annotation's flagged transcript (MANE Select) breaks a tie between exact
15
- * matches, and leads when there is no structure to rank against, where length
16
- * alone would decide.
17
- */
18
- export function rankedTranscriptId({ matches, nonMatches }, flaggedId) {
19
- const flagged = (list) => list.find(i => i.id === flaggedId);
20
- const unranked = nonMatches.every(i => i.score === undefined);
21
- return (flagged(matches) ??
22
- matches[0] ??
23
- (unranked ? flagged(nonMatches) : undefined) ??
24
- nonMatches[0])?.id;
25
- }
26
2
  // The alignment DP runs ~50 ns a cell, so a 4,000-residue transcript against
27
3
  // its structure is almost a second and a complex of long chains several: on
28
4
  // the main thread, frozen UI. These run it in the host's RPC worker instead,
29
- // or in place on a host whose driver is MainThreadRpcDriver.
5
+ // or in place on a host whose driver is MainThreadRpcDriver. The aligner loads
6
+ // on the first call, so registering the methods costs the plugin's boot nothing.
30
7
  export class ProteinChooseMappedEntity extends RpcMethodType {
31
8
  name = 'ProteinChooseMappedEntity';
32
9
  async execute({ transcript, entities, algorithm }) {
10
+ const { chooseMappedEntity } = await import('p2s_mapper');
33
11
  return chooseMappedEntity(transcript, entities, algorithm);
34
12
  }
35
13
  }
36
14
  export class ProteinAlignTranscriptToEntity extends RpcMethodType {
37
15
  name = 'ProteinAlignTranscriptToEntity';
38
16
  async execute({ transcript, entitySeq, algorithm }) {
17
+ const { alignTranscriptToEntity } = await import('p2s_mapper');
39
18
  return alignTranscriptToEntity(transcript, entitySeq, algorithm);
40
19
  }
41
20
  }
42
21
  export class ProteinRankIsoforms extends RpcMethodType {
43
22
  name = 'ProteinRankIsoforms';
44
23
  async execute({ isoforms, structureSequences }) {
24
+ const { rankIsoforms } = await import('./isoformRanking');
45
25
  return rankIsoforms(isoforms, structureSequences);
46
26
  }
47
27
  }
@@ -0,0 +1,24 @@
1
+ import { classifyIsoforms, pickStructureSequence } from 'p2s_mapper';
2
+ /** The launch dialog's isoform order: one alignment per chain to pick the
3
+ * chain, then one per isoform that does not match it exactly. */
4
+ export function rankIsoforms(isoforms, structureSequences) {
5
+ const structureSequence = pickStructureSequence(structureSequences, isoforms);
6
+ return {
7
+ structureSequence,
8
+ ranking: classifyIsoforms({ isoforms, structureSequence }),
9
+ };
10
+ }
11
+ /**
12
+ * The isoform to open from a ranking. An exact match to the structure wins;
13
+ * the annotation's flagged transcript (MANE Select) breaks a tie between exact
14
+ * matches, and leads when there is no structure to rank against, where length
15
+ * alone would decide.
16
+ */
17
+ export function rankedTranscriptId({ matches, nonMatches }, flaggedId) {
18
+ const flagged = (list) => list.find(i => i.id === flaggedId);
19
+ const unranked = nonMatches.every(i => i.score === undefined);
20
+ return (flagged(matches) ??
21
+ matches[0] ??
22
+ (unranked ? flagged(nonMatches) : undefined) ??
23
+ nonMatches[0])?.id;
24
+ }
@@ -21,7 +21,7 @@ export default function FoldseekActionMenu({ hit, session, view, feature, select
21
21
  const pdbData = !hit.structureUrl && hasValidCaCoords(hit)
22
22
  ? caCoordsToPdb(hit.tCa, hit.tSeq, 'A', hit.target)
23
23
  : undefined;
24
- launch3DProteinView({
24
+ return launch3DProteinView({
25
25
  ...baseParams,
26
26
  url: hit.structureUrl,
27
27
  data: pdbData,
@@ -36,9 +36,7 @@ export default function ProteinViewActions({ handleClose, uniprotId, userSelecte
36
36
  userProvidedTranscriptSequence: userSelectedProteinSequence?.seq,
37
37
  sideBySide,
38
38
  };
39
- const handleLaunch3DView = runLaunch(() => {
40
- launch3DProteinView(launch3DParams);
41
- });
39
+ const handleLaunch3DView = runLaunch(() => launch3DProteinView(launch3DParams));
42
40
  const { launch1D } = getConditionalProteinLaunches({
43
41
  session,
44
42
  view,
@@ -70,7 +70,7 @@ const UserProvidedStructure = observer(function UserProvidedStructure({ feature,
70
70
  const structureData = activeFile
71
71
  ? await readStructureFile(activeFile)
72
72
  : undefined;
73
- launch3DProteinView({
73
+ await launch3DProteinView({
74
74
  session,
75
75
  view,
76
76
  feature,
@@ -1,7 +1,7 @@
1
1
  import { getSession } from '@jbrowse/core/util';
2
2
  import useSWR from 'swr';
3
3
  import { STATIC_SWR_OPTIONS } from './swrOptions';
4
- import { rankIsoforms } from '../../AlignTranscriptRpc';
4
+ import { rankIsoforms } from '../../AlignTranscriptRpc/isoformRanking';
5
5
  import { alignOffThread } from '../../ProteinView/alignOffThread';
6
6
  /**
7
7
  * The isoforms in the order the picker lists them, ranked in the RPC worker:
@@ -1,5 +1,5 @@
1
1
  import { useState } from 'react';
2
- import { rankedTranscriptId } from '../../AlignTranscriptRpc';
2
+ import { rankedTranscriptId } from '../../AlignTranscriptRpc/isoformRanking';
3
3
  import { flaggedTranscriptId } from '../codingFeature';
4
4
  import { rankableIsoforms } from '../utils/util';
5
5
  /**
@@ -1,10 +1,10 @@
1
+ import { lazy } from 'react';
1
2
  import { getContainingTrack, getContainingView, getSession, isGeneLikeType, } from '@jbrowse/core/util';
2
3
  import AddIcon from '@mui/icons-material/Add';
3
4
  import { isCodingFeature } from './codingFeature';
4
- import LaunchProteinViewDialog from './components/LaunchProteinViewDialog';
5
- import { describeMissingStructure, resolveGeneLaunch, sessionGeneLaunchHost, } from './resolveGeneLaunch';
6
- import { launch3DProteinView } from './utils/launchViewUtils';
7
5
  import { getGeneDisplayName } from './utils/util';
6
+ // the menu items register at boot; what they open loads on the first click
7
+ const LaunchProteinViewDialog = lazy(() => import('./components/LaunchProteinViewDialog'));
8
8
  function isDisplay(elt) {
9
9
  return elt.name === 'LinearBasicDisplay';
10
10
  }
@@ -84,6 +84,10 @@ function openAlphaFoldStructure(self, target) {
84
84
  return;
85
85
  }
86
86
  session.notify(`Looking up the AlphaFold structure of ${name}`, 'info');
87
+ const [{ describeMissingStructure, resolveGeneLaunch, sessionGeneLaunchHost }, { launch3DProteinView },] = await Promise.all([
88
+ import('./resolveGeneLaunch'),
89
+ import('./utils/launchViewUtils'),
90
+ ]);
87
91
  const launch = await resolveGeneLaunch({
88
92
  host: sessionGeneLaunchHost(session, assemblyName),
89
93
  feature,
@@ -91,7 +95,7 @@ function openAlphaFoldStructure(self, target) {
91
95
  });
92
96
  const { transcript, userProvidedTranscriptSequence, uniprotId, url } = launch;
93
97
  if (url) {
94
- launch3DProteinView({
98
+ await launch3DProteinView({
95
99
  session,
96
100
  view,
97
101
  feature,
@@ -1,7 +1,7 @@
1
1
  import { getConf } from '@jbrowse/core/configuration';
2
2
  import { fetchAlphaFoldModels, getAlphaFoldStructureUrl, pickAlphaFoldModel, searchUniProtEntries, } from 'p2s_mapper';
3
3
  import { codingTranscripts, flaggedTranscriptId } from './codingFeature';
4
- import { rankIsoforms, rankedTranscriptId } from '../AlignTranscriptRpc';
4
+ import { rankIsoforms, rankedTranscriptId, } from '../AlignTranscriptRpc/isoformRanking';
5
5
  import { fetchTranscriptProteinSeqs } from './utils/translateTranscripts';
6
6
  import { extractFeatureIdentifiers, extractTaxonId } from './utils/util';
7
7
  import { alignOffThread } from '../ProteinView/alignOffThread';
@@ -1,187 +1,14 @@
1
- import { abortError, httpError, jsonfetch, rawfetch, timeout } from 'p2s_mapper';
2
- import { isRecord } from '../utils/isRecord';
3
- export const FOLDSEEK_DATABASES = [
4
- { id: 'pdb100', label: 'PDB (100% redundancy)' },
5
- { id: 'afdb-swissprot', label: 'AlphaFold DB (Swiss-Prot)' },
6
- { id: 'afdb50', label: 'AlphaFold DB (50% redundancy)' },
7
- { id: 'afdb-proteome', label: 'AlphaFold DB (Proteomes)' },
8
- { id: 'cath50', label: 'CATH (50% redundancy)' },
9
- { id: 'mgnify_esm30', label: 'MGnify ESM30' },
10
- { id: 'bfmd', label: 'BFMD' },
11
- { id: 'gmgcl_id', label: 'GMGCL' },
12
- ];
13
- export const DEFAULT_DATABASES = [
14
- 'pdb100',
15
- 'afdb-swissprot',
16
- ];
17
- export const FOLDSEEK_MAX_RESIDUES = 1200;
18
- export function cleanFoldseekSequence(aaSequence) {
19
- return aaSequence
20
- .split('\n')
21
- .filter(line => !line.startsWith('>'))
22
- .join('')
23
- .toUpperCase()
24
- .replace(/[^ACDEFGHIKLMNPQRSTVWY]/g, '');
25
- }
26
- export function foldseekLengthProblem(aaSequence) {
27
- const { length } = cleanFoldseekSequence(aaSequence);
28
- return length > FOLDSEEK_MAX_RESIDUES
29
- ? `Foldseek's 3Di predictor takes at most ${FOLDSEEK_MAX_RESIDUES.toLocaleString('en-US')} residues and this sequence has ${length.toLocaleString('en-US')}. Trim it to the region you want to search.`
30
- : undefined;
31
- }
32
- export async function predict3Di({ aaSequence, signal, }) {
33
- const problem = foldseekLengthProblem(aaSequence);
34
- if (problem) {
35
- throw new Error(problem);
36
- }
37
- const cleanSequence = cleanFoldseekSequence(aaSequence);
38
- const url = `https://3di.foldseek.com/predict/${encodeURIComponent(cleanSequence)}`;
39
- const response = await rawfetch(url, { signal });
40
- if (!response.ok) {
41
- throw await httpError(response, url);
42
- }
43
- const di3Sequence = await response.text();
44
- // Remove any quotes, slashes, or whitespace from the response
45
- const cleanDi3 = di3Sequence
46
- .replace(/^["'/\s]+/, '')
47
- .replace(/["'/\s]+$/, '')
48
- .trim();
49
- return { aaSequence: cleanSequence, di3Sequence: cleanDi3 };
50
- }
51
- export async function submitFoldseekSearch({ aaSequence, di3Sequence, databases, signal, }) {
52
- // Submit both AA and 3Di sequences (with trailing newline like working example)
53
- const fastaContent = `>query\n${aaSequence}\n>3DI\n${di3Sequence}\n`;
54
- const params = new URLSearchParams();
55
- params.append('q', fastaContent);
56
- params.append('mode', '3diaa');
57
- params.append('email', '');
58
- for (const db of databases) {
59
- params.append('database[]', db);
60
- }
61
- const url = 'https://search.foldseek.com/api/ticket';
62
- const response = await rawfetch(url, {
63
- method: 'POST',
64
- headers: {
65
- 'Content-Type': 'application/x-www-form-urlencoded',
66
- },
67
- body: params,
68
- signal,
69
- });
70
- if (!response.ok) {
71
- throw await httpError(response, url);
72
- }
73
- // The server answers a refusal (RATELIMIT, MAINTENANCE) with a 200 and no
74
- // id, which used to be polled as ticket "undefined" for three minutes
75
- const text = await response.text();
76
- const ticket = parseTicket(text);
77
- if (!ticket) {
78
- throw new Error(`Foldseek did not accept the search: ${text.slice(0, 200)}`);
79
- }
80
- return ticket;
81
- }
82
- function parseTicket(text) {
83
- let body;
84
- try {
85
- body = JSON.parse(text);
86
- }
87
- catch {
88
- return undefined;
89
- }
90
- if (!isRecord(body)) {
91
- return undefined;
92
- }
93
- const { id, status } = body;
94
- return typeof id === 'string' &&
95
- (status === 'PENDING' ||
96
- status === 'RUNNING' ||
97
- status === 'COMPLETE' ||
98
- status === 'ERROR')
99
- ? { id, status }
100
- : undefined;
101
- }
102
- async function pollFoldseekStatus({ ticketId, signal, }) {
103
- // Use the /tickets endpoint (plural) with POST
104
- const params = new URLSearchParams();
105
- params.append('tickets[]', ticketId);
106
- const url = 'https://search.foldseek.com/api/tickets';
107
- const response = await rawfetch(url, {
108
- method: 'POST',
109
- headers: {
110
- 'Content-Type': 'application/x-www-form-urlencoded',
111
- },
112
- body: params,
113
- signal,
114
- });
115
- if (!response.ok) {
116
- throw await httpError(response, url);
117
- }
118
- return parseTicketStatus(await response.json());
119
- }
120
- function parseTicketStatus(body) {
121
- const first = Array.isArray(body) ? body[0] : undefined;
122
- if (!isRecord(first) || typeof first.status !== 'string') {
123
- throw new Error('Foldseek returned no ticket status');
124
- }
125
- return {
126
- status: first.status,
127
- error: typeof first.error === 'string' ? first.error : undefined,
128
- };
129
- }
130
- function isQuery(value) {
131
- return (isRecord(value) &&
132
- typeof value.header === 'string' &&
133
- typeof value.sequence === 'string');
134
- }
135
- function isAlignmentRows(value) {
136
- return (Array.isArray(value) &&
137
- value.every((row) => Array.isArray(row) &&
138
- row.every((hit) => isRecord(hit) && typeof hit.target === 'string')));
139
- }
140
- function parseFoldseekResult(body) {
141
- if (!isRecord(body) || !Array.isArray(body.results)) {
142
- throw new Error('Foldseek returned a result with no list of databases');
143
- }
144
- const firstQuery = Array.isArray(body.queries)
145
- ? body.queries[0]
146
- : undefined;
147
- return {
148
- query: isQuery(firstQuery) ? firstQuery : { header: '', sequence: '' },
149
- results: body.results.map((result) => {
150
- if (!isRecord(result) || typeof result.db !== 'string') {
151
- throw new Error('Foldseek returned a result naming no database');
152
- }
153
- return {
154
- db: result.db,
155
- alignments: isAlignmentRows(result.alignments)
156
- ? result.alignments
157
- : undefined,
158
- };
159
- }),
160
- };
161
- }
162
- export async function waitForFoldseekResults({ ticketId, onStatusChange, signal, }) {
163
- // Wall-clock budget, not a poll count: each round trips to the server and
164
- // then sleeps a second, so counting polls under-reports elapsed time by
165
- // however slow the server is — and the progress message read as seconds.
166
- const timeoutMs = 180_000;
167
- const startedAt = Date.now();
168
- const elapsedSeconds = () => Math.round((Date.now() - startedAt) / 1000);
169
- while (Date.now() - startedAt < timeoutMs) {
170
- if (signal?.aborted) {
171
- throw abortError(signal);
172
- }
173
- const status = await pollFoldseekStatus({ ticketId, signal });
174
- if (status.status === 'COMPLETE') {
175
- onStatusChange?.('Fetching results...');
176
- return parseFoldseekResult(await jsonfetch(`https://search.foldseek.com/api/result/${ticketId}/0`, { signal }));
177
- }
178
- // the server also answers RATELIMIT, MAINTENANCE and UNKNOWN, none of
179
- // which a wait resolves
180
- if (status.status !== 'PENDING' && status.status !== 'RUNNING') {
181
- throw new Error(`Foldseek search failed: ${status.error ?? status.status}`);
182
- }
183
- onStatusChange?.(`Search ${status.status.toLowerCase()}... (${elapsedSeconds()}s)`);
184
- await timeout(1000, signal);
185
- }
186
- throw new Error(`Foldseek search timed out after ${Math.round(timeoutMs / 1000)}s`);
1
+ import { DEFAULT_FOLDSEEK_DATABASES, FOLDSEEK_DATABASES, FOLDSEEK_MAX_RESIDUES, cleanFoldseekSequence, foldseekLengthProblem, predict3Di as predict, submitFoldseekSearch as submit, waitForFoldseekResults as wait, } from 'p2s_mapper';
2
+ // The client is p2s_mapper's, shared with react-msaview-structure. These
3
+ // wrappers keep the shape this plugin's hooks and dialogs already call.
4
+ export { FOLDSEEK_DATABASES, FOLDSEEK_MAX_RESIDUES, cleanFoldseekSequence, foldseekLengthProblem, };
5
+ export const DEFAULT_DATABASES = DEFAULT_FOLDSEEK_DATABASES;
6
+ export function predict3Di({ aaSequence, signal, }) {
7
+ return predict(aaSequence, { signal });
8
+ }
9
+ export function submitFoldseekSearch({ aaSequence, di3Sequence, databases, signal, }) {
10
+ return submit({ aaSequence, di3Sequence, databases }, { signal });
11
+ }
12
+ export function waitForFoldseekResults({ ticketId, onStatusChange, signal, }) {
13
+ return wait(ticketId, { signal, onStatus: onStatusChange });
187
14
  }
@@ -1,5 +1,6 @@
1
1
  import { maybeLaunchSideBySide } from './sideBySide';
2
2
  import { getGeneDisplayName, getTranscriptDisplayName } from './util';
3
+ import { addProteinView } from '../../ProteinView/addProteinView';
3
4
  import { proteinViewSnapshot } from '../../ProteinView/proteinViewSpec';
4
5
  import { clinVarTrackConfFor } from '../components/clinVarTrackSource';
5
6
  import { launchProteinAnnotationView } from '../components/launchProteinAnnotationView';
@@ -16,7 +17,7 @@ export function formatViewName(prefix, feature, selectedTranscript, uniprotId) {
16
17
  .filter(s => !!s)
17
18
  .join(' - ');
18
19
  }
19
- export function launch3DProteinView({ session, view, feature, selectedTranscript, uniprotId, url, data, userProvidedTranscriptSequence, sideBySide, }) {
20
+ export async function launch3DProteinView({ session, view, feature, selectedTranscript, uniprotId, url, data, userProvidedTranscriptSequence, sideBySide, }) {
20
21
  const snap = proteinViewSnapshot({
21
22
  displayName: formatViewName('Protein view', feature, selectedTranscript, uniprotId),
22
23
  structures: [
@@ -29,7 +30,7 @@ export function launch3DProteinView({ session, view, feature, selectedTranscript
29
30
  },
30
31
  ],
31
32
  });
32
- const proteinView = session.addView('ProteinView', snap);
33
+ const proteinView = await addProteinView(session, snap);
33
34
  maybeLaunchSideBySide(session, proteinView.id, sideBySide);
34
35
  return proteinView;
35
36
  }
@@ -1,91 +1,16 @@
1
- import { SimpleFeature } from '@jbrowse/core/util';
2
- import { fetchAlphaFoldModels } from 'p2s_mapper';
3
- import { normalizeAnnotationLaunch } from './normalizeAnnotationLaunch';
4
- import { connectGenomeView, resolveTranscriptLinkage, } from './transcriptLinkage';
5
- import { clinVarTrackConfFor } from '../LaunchProteinView/components/clinVarTrackSource';
6
- import { openProteinAnnotationView } from '../LaunchProteinView/components/launchProteinAnnotationView';
7
- import { canAddTemporaryAssembly } from '../LaunchProteinView/components/proteinAssemblySetup';
8
- import { fetchUniProtFeatureTypes } from '../LaunchProteinView/components/proteinTrackSetup';
9
- import { describeMissingStructure } from '../LaunchProteinView/resolveGeneLaunch';
10
- import { uniProtEntry } from '../LaunchProteinView/utils/launchViewUtils';
11
- import { viewAssemblyName } from '../ProteinView/util';
12
- // The canonical model's pLDDT is in the entry's numbering; an isoform model's
13
- // is not, and has no place on the entry's track
14
- async function entryConfidenceUrl(uniprotId) {
15
- try {
16
- const models = await fetchAlphaFoldModels(uniprotId);
17
- return models.find(m => m.accession === uniprotId)?.confidenceUrl;
18
- }
19
- catch {
20
- return undefined;
21
- }
22
- }
23
1
  /**
24
2
  * The 1D protein-annotation view of a UniProt entry, from a session spec:
25
3
  * the same view the launch dialog's 1D option opens, linked to the transcript
26
4
  * a `gene` or `transcriptId` names the way a ProteinView spec links its
27
5
  * structures. The view itself is a LinearGenomeView on a temporary assembly,
28
6
  * so the extension point is named for the spec type rather than the view type.
7
+ *
8
+ * The launch itself loads on first use, so registering it costs the plugin's
9
+ * boot nothing.
29
10
  */
30
11
  export default function LaunchProteinAnnotationViewF(pluginManager) {
31
12
  pluginManager.addToExtensionPoint('LaunchView-ProteinAnnotationView', async (args) => {
32
- const { session, ...given } = args;
33
- const fail = (e) => {
34
- console.error(e);
35
- session.notify(`Could not launch protein annotation view: ${e}`, 'error');
36
- return args;
37
- };
38
- const normalized = normalizeAnnotationLaunch(given);
39
- for (const warning of normalized.warnings) {
40
- console.warn(warning);
41
- session.notify(`Protein annotation view launch: ${warning}`, 'warning');
42
- }
43
- if ('error' in normalized) {
44
- return fail(normalized.error);
45
- }
46
- if (!canAddTemporaryAssembly(session)) {
47
- return fail('this session cannot add the temporary assembly the view opens on');
48
- }
49
- const { launch } = normalized;
50
- try {
51
- const { named, resolved, connectedView } = await resolveTranscriptLinkage(session, launch, {
52
- findStructure: !launch.uniprotId,
53
- });
54
- const accession = launch.uniprotId ?? named?.uniprotId;
55
- if (!accession) {
56
- throw new Error(launch.gene && named
57
- ? `${describeMissingStructure(launch.gene, named)}; name a uniprotId`
58
- : 'no UniProt entry to open');
59
- }
60
- const uniprotId = uniProtEntry(accession);
61
- // fetched before anything is added, so a failure leaves no view
62
- const [featureTypes, confidenceUrl] = await Promise.all([
63
- fetchUniProtFeatureTypes(uniprotId),
64
- entryConfidenceUrl(uniprotId),
65
- ]);
66
- const transcript = resolved
67
- ? new SimpleFeature(resolved.feature)
68
- : undefined;
69
- const connectedViewId = transcript
70
- ? connectGenomeView(session, launch.connectedViewId, connectedView)
71
- : undefined;
72
- await openProteinAnnotationView({
73
- session,
74
- feature: transcript,
75
- selectedTranscript: transcript,
76
- uniprotId,
77
- confidenceUrl,
78
- connectedViewId,
79
- connectedAssemblyName: (launch.connectedViewId
80
- ? viewAssemblyName(session, launch.connectedViewId)
81
- : undefined) ?? connectedView?.assembly,
82
- featureTypes,
83
- clinVar: (linkage, idPrefix) => clinVarTrackConfFor({ session, linkage, idPrefix }),
84
- });
85
- }
86
- catch (e) {
87
- return fail(e);
88
- }
89
- return args;
13
+ const { launchAnnotationView } = await import('./launchAnnotationView');
14
+ return launchAnnotationView(args);
90
15
  });
91
16
  }
@@ -1,88 +1,10 @@
1
- import { coerceAlignmentAlgorithm } from 'p2s_mapper';
2
- import { normalizeLaunch } from './normalizeLaunch';
3
- import { connectGenomeView, resolveTranscriptLinkage, } from './transcriptLinkage';
4
- import { describeMissingStructure } from '../LaunchProteinView/resolveGeneLaunch';
5
- import { maybeLaunchSideBySide } from '../LaunchProteinView/utils/sideBySide';
6
- import { coerceColorScheme } from '../ProteinView/applyColorTheme';
7
- import { proteinViewSnapshot } from '../ProteinView/proteinViewSpec';
8
- export function launchViewSnapshot({ alignmentAlgorithm, colorScheme, ...settings }, structures) {
9
- return proteinViewSnapshot({
10
- ...settings,
11
- alignmentAlgorithm: alignmentAlgorithm === undefined
12
- ? undefined
13
- : coerceAlignmentAlgorithm(alignmentAlgorithm),
14
- colorScheme: colorScheme === undefined ? undefined : coerceColorScheme(colorScheme),
15
- structures,
16
- });
17
- }
1
+ /**
2
+ * The launch itself loads on first use, so registering it costs the plugin's
3
+ * boot nothing.
4
+ */
18
5
  export default function LaunchProteinViewExtensionPointF(pluginManager) {
19
- pluginManager.addToExtensionPoint('LaunchView-ProteinView',
20
- // A LaunchView point is a transformer — the chain hands what each callback
21
- // returns to the next — and JBrowse now warns when one returns undefined
22
- // ("...returned undefined instead of the value it was passed, so its result
23
- // was ignored"), on every launch. This used to return nothing on the
24
- // assumption that the result was ignored; it is not. The handler returns
25
- // its extendee at each exit now, like jbrowse-components' own
26
- // LaunchDotplotView does.
27
- async (args) => {
28
- const { session, structures: _structures, url: _url, data: _data, pdbId: _pdbId, initialSelection: _initialSelection, initialResidues: _initialResidues, initialTranscriptResidues: _initialTranscriptResidues, mappedEntityId: _mappedEntityId, pairwiseAlignment: _pairwiseAlignment, alignmentImported: _alignmentImported, hidden: _hidden, uniprotId, transcriptId, userProvidedTranscriptSequence, feature, connectedViewId, connectedView: givenConnectedView, gene, sideBySide, ...settings } = args;
29
- const fail = (e) => {
30
- console.error(e);
31
- session.notify(`Could not launch protein view: ${e}`, 'error');
32
- return args;
33
- };
34
- const { session: _session, ...launch } = args;
35
- const normalized = normalizeLaunch(launch);
36
- for (const warning of normalized.warnings) {
37
- console.warn(warning);
38
- session.notify(`Protein view launch: ${warning}`, 'warning');
39
- }
40
- if ('error' in normalized) {
41
- return fail(normalized.error);
42
- }
43
- const { geneModel } = normalized;
44
- // A gene name alone: the host's text search finds the gene, and the
45
- // launch dialog's defaults pick its isoform and AlphaFold model. A
46
- // structure, transcript or locus the spec names wins over those. The
47
- // short form instead derives the feature and sequence from the
48
- // connected track, and the same mapping applies to every structure.
49
- let linkage;
50
- try {
51
- linkage = await resolveTranscriptLinkage(session, {
52
- gene,
53
- transcriptId,
54
- uniprotId,
55
- userProvidedTranscriptSequence,
56
- connectedView: givenConnectedView,
57
- connectedViewId,
58
- }, { findStructure: geneModel === 'required' });
59
- }
60
- catch (e) {
61
- return fail(e);
62
- }
63
- const { named, resolved, connectedView } = linkage;
64
- if (gene && named && geneModel === 'required' && !named.url) {
65
- return fail(new Error(`${describeMissingStructure(gene, named)}; name a ${named.uniprotId ? 'pdbId or url' : 'uniprotId or pdbId'}`));
66
- }
67
- const requested = named && geneModel
68
- ? normalized.requested.map(s => ({ ...s, url: named.url }))
69
- : normalized.requested;
70
- // a connected view this launch created itself can be split beside the
71
- // protein view; a pre-existing connectedViewId is left in place
72
- const ownsConnectedView = !connectedViewId && !!connectedView;
73
- const resolvedConnectedViewId = connectGenomeView(session, connectedViewId, connectedView);
74
- const structures = requested.map(s => ({
75
- ...s,
76
- userProvidedTranscriptSequence: s.userProvidedTranscriptSequence ??
77
- resolved?.userProvidedTranscriptSequence ??
78
- userProvidedTranscriptSequence,
79
- feature: s.feature ?? resolved?.feature ?? feature,
80
- connectedViewId: s.connectedViewId ?? resolvedConnectedViewId,
81
- }));
82
- const proteinView = session.addView('ProteinView', launchViewSnapshot({ displayName: named?.displayName, ...settings }, structures));
83
- if (ownsConnectedView) {
84
- maybeLaunchSideBySide(session, proteinView.id, sideBySide);
85
- }
86
- return args;
6
+ pluginManager.addToExtensionPoint('LaunchView-ProteinView', async (args) => {
7
+ const { launchProteinView } = await import('./launchProteinView');
8
+ return launchProteinView(args);
87
9
  });
88
10
  }