jbrowse-plugin-protein3d 1.7.0 → 1.8.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 (61) hide show
  1. package/dist/LaunchProteinView/components/clinVarTrack.js +70 -0
  2. package/dist/LaunchProteinView/components/clinVarTrackSource.js +55 -0
  3. package/dist/LaunchProteinView/components/launchProteinAnnotationView.js +26 -9
  4. package/dist/LaunchProteinView/components/proteinTrackSetup.js +5 -18
  5. package/dist/LaunchProteinView/utils/launchViewUtils.js +2 -0
  6. package/dist/LaunchProteinViewExtensionPoint/annotationView.js +2 -0
  7. package/dist/ProteinView/clinVar.js +101 -32
  8. package/dist/ProteinView/clinVarSource.js +23 -14
  9. package/dist/chunks/{HelpDialog-GBG7PHDR.js → HelpDialog-IRAXBGZB.js} +2 -2
  10. package/dist/chunks/{ManualAlignmentDialog-B35TUUYU.js → ManualAlignmentDialog-BTL4LYX2.js} +2 -2
  11. package/dist/chunks/{ProteinView-DQOR5RTK.js → ProteinView-YFTN6FW3.js} +2 -2
  12. package/dist/chunks/{ProteinView-DQOR5RTK.js.map → ProteinView-YFTN6FW3.js.map} +1 -1
  13. package/dist/chunks/{chunk-2CJBOB5B.js → chunk-7Q7UK2ZL.js} +2 -2
  14. package/dist/chunks/{chunk-2CJBOB5B.js.map → chunk-7Q7UK2ZL.js.map} +1 -1
  15. package/dist/chunks/{chunk-TPLXHUOA.js → chunk-EXD7S43Q.js} +2 -2
  16. package/dist/chunks/{chunk-TPLXHUOA.js.map → chunk-EXD7S43Q.js.map} +1 -1
  17. package/dist/chunks/chunk-R46YRV6D.js +2 -0
  18. package/dist/chunks/chunk-R46YRV6D.js.map +7 -0
  19. package/dist/chunks/{chunk-X5RLRQSB.js → chunk-SIZG3XB4.js} +1 -1
  20. package/dist/chunks/{chunk-X5RLRQSB.js.map → chunk-SIZG3XB4.js.map} +1 -1
  21. package/dist/chunks/{chunk-SQLUPFUS.js → chunk-SPXMXPSC.js} +1 -1
  22. package/dist/chunks/chunk-SPXMXPSC.js.map +7 -0
  23. package/dist/chunks/clinVarSource-LCO5EZ6C.js +2 -0
  24. package/dist/chunks/clinVarSource-LCO5EZ6C.js.map +7 -0
  25. package/dist/chunks/{molstarExports-M6FNLMIU.js → molstarExports-PLBMBP6Q.js} +3 -3
  26. package/dist/index.js +0 -2
  27. package/dist/jbrowse-plugin-protein3d.esm.js +10 -10
  28. package/dist/jbrowse-plugin-protein3d.esm.js.map +4 -4
  29. package/dist/version.js +1 -1
  30. package/package.json +6 -6
  31. package/src/LaunchProteinView/components/clinVarTrack.test.ts +126 -0
  32. package/src/LaunchProteinView/components/clinVarTrack.ts +113 -0
  33. package/src/LaunchProteinView/components/clinVarTrackSource.ts +81 -0
  34. package/src/LaunchProteinView/components/launchProteinAnnotationView.test.ts +78 -4
  35. package/src/LaunchProteinView/components/launchProteinAnnotationView.ts +37 -8
  36. package/src/LaunchProteinView/components/proteinTrackSetup.test.ts +2 -16
  37. package/src/LaunchProteinView/components/proteinTrackSetup.ts +5 -22
  38. package/src/LaunchProteinView/utils/launchViewUtils.ts +3 -0
  39. package/src/LaunchProteinViewExtensionPoint/annotationView.ts +3 -0
  40. package/src/ProteinView/clinVar.ts +145 -34
  41. package/src/ProteinView/clinVarMissense.test.ts +131 -0
  42. package/src/ProteinView/clinVarSource.ts +41 -24
  43. package/src/index.ts +0 -2
  44. package/src/version.ts +1 -1
  45. package/dist/UniProtVariationAdapter/UniProtVariationAdapter.js +0 -32
  46. package/dist/UniProtVariationAdapter/configSchema.js +0 -19
  47. package/dist/UniProtVariationAdapter/index.js +0 -10
  48. package/dist/chunks/UniProtVariationAdapter-2GQU7BV6.js +0 -2
  49. package/dist/chunks/UniProtVariationAdapter-2GQU7BV6.js.map +0 -7
  50. package/dist/chunks/chunk-2U2S5MMZ.js +0 -2
  51. package/dist/chunks/chunk-2U2S5MMZ.js.map +0 -7
  52. package/dist/chunks/chunk-SQLUPFUS.js.map +0 -7
  53. package/dist/chunks/clinVarSource-SXH525M3.js +0 -2
  54. package/dist/chunks/clinVarSource-SXH525M3.js.map +0 -7
  55. package/src/UniProtVariationAdapter/UniProtVariationAdapter.ts +0 -65
  56. package/src/UniProtVariationAdapter/configSchema.ts +0 -27
  57. package/src/UniProtVariationAdapter/index.ts +0 -18
  58. package/src/UniProtVariationAdapter/parseUniProtVariants.test.ts +0 -40
  59. /package/dist/chunks/{HelpDialog-GBG7PHDR.js.map → HelpDialog-IRAXBGZB.js.map} +0 -0
  60. /package/dist/chunks/{ManualAlignmentDialog-B35TUUYU.js.map → ManualAlignmentDialog-BTL4LYX2.js.map} +0 -0
  61. /package/dist/chunks/{molstarExports-M6FNLMIU.js.map → molstarExports-PLBMBP6Q.js.map} +0 -0
@@ -0,0 +1,70 @@
1
+ import { clinVarCategory } from '../../ProteinView/clinVar';
2
+ // The structure's clinvar scheme counts pathogenic calls in reds; the track
3
+ // shows every classification, so the reds are kept for the pathogenic end,
4
+ // greens for the benign end, and greys for what ClinVar cannot decide.
5
+ export const CLINVAR_CATEGORY_COLORS = {
6
+ pathogenic: '#a50f15',
7
+ 'likely pathogenic': '#de2d26',
8
+ conflicting: '#fd8d3c',
9
+ uncertain: '#969696',
10
+ 'likely benign': '#74c476',
11
+ benign: '#238b45',
12
+ other: '#bdbdbd',
13
+ };
14
+ /**
15
+ * One feature per placed variant, on the entry's residues. A variant whose
16
+ * residue the entry does not share with the transcript (an isoform's private
17
+ * exon) has nowhere to go and is left out.
18
+ */
19
+ export function clinVarTrackFeatures({ placed, uniprotId, toEntryPosition, }) {
20
+ return placed
21
+ .flatMap(({ variant, residue, from, to }, index) => {
22
+ const position = toEntryPosition(residue);
23
+ if (position === undefined) {
24
+ return [];
25
+ }
26
+ const category = clinVarCategory(variant.significance);
27
+ const name = `${from}${position + 1}${to}`;
28
+ const onTranscript = `${from}${residue + 1}${to}`;
29
+ return [
30
+ {
31
+ uniqueId: `clinvar-${variant.id ?? `${variant.start}${variant.alt}`}-${index}`,
32
+ refName: uniprotId,
33
+ start: position,
34
+ end: position + 1,
35
+ name,
36
+ type: 'missense_variant',
37
+ category,
38
+ color: CLINVAR_CATEGORY_COLORS[category],
39
+ significance: variant.significance.join(', ').replaceAll('_', ' '),
40
+ ...(variant.id === undefined ? {} : { clinvarId: variant.id }),
41
+ ...(onTranscript === name ? {} : { transcriptChange: onTranscript }),
42
+ },
43
+ ];
44
+ })
45
+ .sort((a, b) => a.start - b.start || a.name.localeCompare(b.name));
46
+ }
47
+ export function clinVarTrackConf({ uniprotId, idPrefix, features, }) {
48
+ const trackId = `${idPrefix}-ClinVar`;
49
+ return {
50
+ type: 'FeatureTrack',
51
+ trackId,
52
+ name: 'ClinVar',
53
+ assemblyNames: [uniprotId],
54
+ adapter: {
55
+ type: 'FromConfigAdapter',
56
+ adapterId: trackId,
57
+ features,
58
+ },
59
+ displays: [
60
+ {
61
+ type: 'LinearBasicDisplay',
62
+ displayId: `${trackId}-LinearBasicDisplay`,
63
+ renderer: {
64
+ type: 'SvgFeatureRenderer',
65
+ color1: "jexl:get(feature,'color')",
66
+ },
67
+ },
68
+ ],
69
+ };
70
+ }
@@ -0,0 +1,55 @@
1
+ import { SimpleFeature } from '@jbrowse/core/util';
2
+ import { makeCoordinateMapper, transcriptPos } from 'p2s_mapper';
3
+ import { clinVarTrackConf, clinVarTrackFeatures } from './clinVarTrack';
4
+ import { linkedGenomeAssemblyName, resolveLinkageAlignment, } from '../../Protein1DLinkage/linkage';
5
+ import { sessionLinkageHost } from '../../Protein1DLinkage/sessionLinkageHost';
6
+ import { clinVarBuild, isUnnumberedMitochondrion, } from '../../ProteinView/clinVar';
7
+ import { placeClinVarOnTranscript } from '../../ProteinView/clinVarSource';
8
+ // TP53's slice is under 1 MB; a stalled host should not hold the view open
9
+ // forever on one track
10
+ const CLINVAR_TIMEOUT_MS = 60_000;
11
+ /**
12
+ * The ClinVar track of a 1D view: every missense substitution NCBI's VCF
13
+ * classifies on the linked transcript, each on the entry residue its
14
+ * transcript residue aligns to. Undefined, with no track, when the genome
15
+ * view's assembly is not a build ClinVar numbers, or the transcript and the
16
+ * entry do not align; the view's own linkage reports the latter. A failed
17
+ * read throws, for the opener to report as the track's.
18
+ */
19
+ export async function clinVarTrackConfFor({ session, linkage, idPrefix, }) {
20
+ const { uniprotId, feature } = linkage;
21
+ const assemblyName = linkedGenomeAssemblyName(session, linkage);
22
+ const assembly = assemblyName
23
+ ? session.assemblyManager.get(assemblyName)
24
+ : undefined;
25
+ const build = clinVarBuild([
26
+ ...(assemblyName ? [assemblyName] : []),
27
+ ...(assembly ? [assembly.name, ...assembly.aliases] : []),
28
+ ]);
29
+ if (!assemblyName ||
30
+ !build ||
31
+ isUnnumberedMitochondrion(feature.refName, build)) {
32
+ return undefined;
33
+ }
34
+ const linked = await resolveLinkageAlignment(sessionLinkageHost(session, linkage));
35
+ if (!('alignment' in linked)) {
36
+ return undefined;
37
+ }
38
+ const { placed } = await placeClinVarOnTranscript({
39
+ build,
40
+ feature: new SimpleFeature(feature),
41
+ assemblyName,
42
+ session,
43
+ signal: AbortSignal.timeout(CLINVAR_TIMEOUT_MS),
44
+ });
45
+ const mapper = makeCoordinateMapper(linked.alignment);
46
+ return clinVarTrackConf({
47
+ uniprotId,
48
+ idPrefix,
49
+ features: clinVarTrackFeatures({
50
+ placed,
51
+ uniprotId,
52
+ toEntryPosition: residue => mapper.transcriptToStructure(transcriptPos(residue)),
53
+ }),
54
+ });
55
+ }
@@ -16,7 +16,7 @@ export async function launchProteinAnnotationView(args) {
16
16
  await openProteinAnnotationView({ ...args, featureTypes });
17
17
  }
18
18
  /** The view, once the entry's feature types are in hand. */
19
- export async function openProteinAnnotationView({ session, feature, selectedTranscript, uniprotId, confidenceUrl, connectedViewId, connectedAssemblyName, featureTypes, }) {
19
+ export async function openProteinAnnotationView({ session, feature, selectedTranscript, uniprotId, confidenceUrl, connectedViewId, connectedAssemblyName, featureTypes, clinVar, }) {
20
20
  // A second view of an entry, another isoform's say, shares the first's
21
21
  // assembly; adding it again makes the host warn. `has`, where the host has
22
22
  // it, because `get` reports an unknown name to every plugin that resolves
@@ -47,6 +47,25 @@ export async function openProteinAnnotationView({ session, feature, selectedTran
47
47
  if (!isTrackLaunchingView(view)) {
48
48
  throw new Error('The host added a view that cannot open tracks');
49
49
  }
50
+ const idPrefix = `${view.id}-${uniprotId}`;
51
+ const open = async (conf) => {
52
+ try {
53
+ // the host reports a config it rejects itself and resolves undefined
54
+ await view.launchTrack(conf.trackId, {}, {}, conf);
55
+ }
56
+ catch (e) {
57
+ session.notifyError(`Could not open the ${conf.name} track: ${e}`, e);
58
+ }
59
+ };
60
+ // ClinVar waits on the transcript's alignment to the entry and a range read
61
+ // of NCBI's VCF, so it is asked for first and opened last, after the tracks
62
+ // that need only the entry
63
+ const clinVarTrack = proteinLinkage && clinVar
64
+ ? clinVar(proteinLinkage, idPrefix).catch((e) => {
65
+ session.notifyError(`Could not open the ClinVar track: ${e}`, e);
66
+ return undefined;
67
+ })
68
+ : undefined;
50
69
  // Each config rides on its track in this view, not in the session's track
51
70
  // list: the host rejects a session track naming a temporary assembly, and
52
71
  // the track selector lists session tracks only, so every track opens here
@@ -55,15 +74,13 @@ export async function openProteinAnnotationView({ session, feature, selectedTran
55
74
  uniprotId,
56
75
  featureTypes,
57
76
  confidenceUrl,
58
- idPrefix: `${view.id}-${uniprotId}`,
77
+ idPrefix,
59
78
  })) {
60
- try {
61
- // the host reports a config it rejects itself and resolves undefined
62
- await view.launchTrack(conf.trackId, {}, {}, conf);
63
- }
64
- catch (e) {
65
- session.notifyError(`Could not open the ${conf.name} track: ${e}`, e);
66
- }
79
+ await open(conf);
67
80
  }
68
81
  await view.navToLocString(uniprotId, uniprotId);
82
+ const conf = await clinVarTrack;
83
+ if (conf) {
84
+ await open(conf);
85
+ }
69
86
  }
@@ -52,20 +52,6 @@ function antigenTrackConf(uniprotId, idPrefix) {
52
52
  assemblyNames: [uniprotId],
53
53
  };
54
54
  }
55
- function variationTrackConf(uniprotId, idPrefix) {
56
- return {
57
- type: 'FeatureTrack',
58
- trackId: `${idPrefix}-Variation`,
59
- name: 'Variation',
60
- adapter: {
61
- type: 'UniProtVariationAdapter',
62
- location: {
63
- uri: `https://www.ebi.ac.uk/proteins/api/variation/${uniprotId}.json`,
64
- },
65
- },
66
- assemblyNames: [uniprotId],
67
- };
68
- }
69
55
  function alphaFoldConfidenceTrackConf({ uniprotId, confidenceUrl, idPrefix, }) {
70
56
  return {
71
57
  type: 'QuantitativeTrack',
@@ -115,15 +101,16 @@ function alphaMissenseTrackConf(uniprotId, idPrefix) {
115
101
  };
116
102
  }
117
103
  /**
118
- * Every annotation track of a UniProt entry, as configs for the view to carry.
119
- * `idPrefix` has to be unique to the view: two views of one entry each hold
120
- * their own copy, and a session tree cannot hold one trackId twice.
104
+ * Every annotation track of a UniProt entry that needs only the entry, as
105
+ * configs for the view to carry; the ClinVar track, which needs the linked
106
+ * transcript, is built by clinVarTrackSource. `idPrefix` has to be unique to
107
+ * the view: two views of one entry each hold their own copy, and a session
108
+ * tree cannot hold one trackId twice.
121
109
  */
122
110
  export function proteinTrackConfs({ uniprotId, featureTypes, confidenceUrl, idPrefix, }) {
123
111
  return [
124
112
  ...uniProtFeatureTrackConfs({ uniprotId, featureTypes, idPrefix }),
125
113
  antigenTrackConf(uniprotId, idPrefix),
126
- variationTrackConf(uniprotId, idPrefix),
127
114
  ...(confidenceUrl
128
115
  ? [alphaFoldConfidenceTrackConf({ uniprotId, confidenceUrl, idPrefix })]
129
116
  : []),
@@ -1,6 +1,7 @@
1
1
  import { maybeLaunchSideBySide } from './sideBySide';
2
2
  import { getGeneDisplayName, getTranscriptDisplayName } from './util';
3
3
  import { proteinViewSnapshot } from '../../ProteinView/proteinViewSpec';
4
+ import { clinVarTrackConfFor } from '../components/clinVarTrackSource';
4
5
  import { launchProteinAnnotationView } from '../components/launchProteinAnnotationView';
5
6
  import { canAddTemporaryAssembly } from '../components/proteinAssemblySetup';
6
7
  export function formatViewName(prefix, feature, selectedTranscript, uniprotId) {
@@ -57,6 +58,7 @@ async function launch1DProteinView({ session, view, feature, selectedTranscript,
57
58
  confidenceUrl: entry === uniprotId ? confidenceUrl : undefined,
58
59
  connectedViewId: view.id,
59
60
  connectedAssemblyName: view.assemblyNames[0],
61
+ clinVar: (linkage, idPrefix) => clinVarTrackConfFor({ session, linkage, idPrefix }),
60
62
  });
61
63
  }
62
64
  // What the launches below are CALLED, shared for the same reason their
@@ -2,6 +2,7 @@ import { SimpleFeature } from '@jbrowse/core/util';
2
2
  import { fetchAlphaFoldModels } from 'p2s_mapper';
3
3
  import { normalizeAnnotationLaunch } from './normalizeAnnotationLaunch';
4
4
  import { connectGenomeView, resolveTranscriptLinkage, } from './transcriptLinkage';
5
+ import { clinVarTrackConfFor } from '../LaunchProteinView/components/clinVarTrackSource';
5
6
  import { openProteinAnnotationView } from '../LaunchProteinView/components/launchProteinAnnotationView';
6
7
  import { canAddTemporaryAssembly } from '../LaunchProteinView/components/proteinAssemblySetup';
7
8
  import { fetchUniProtFeatureTypes } from '../LaunchProteinView/components/proteinTrackSetup';
@@ -79,6 +80,7 @@ export default function LaunchProteinAnnotationViewF(pluginManager) {
79
80
  ? viewAssemblyName(session, launch.connectedViewId)
80
81
  : undefined) ?? connectedView?.assembly,
81
82
  featureTypes,
83
+ clinVar: (linkage, idPrefix) => clinVarTrackConfFor({ session, linkage, idPrefix }),
82
84
  });
83
85
  }
84
86
  catch (e) {
@@ -58,15 +58,13 @@ function infoField(info, key) {
58
58
  return new RegExp(`(?:^|;)${key}=([^;]*)`).exec(info)?.[1];
59
59
  }
60
60
  /**
61
- * The substitution a ClinVar VCF line records, when ClinVar's aggregate
62
- * germline classification calls it pathogenic or likely pathogenic and it is
63
- * missense on some transcript. `CLNSIG` joins classifications with `/`, `|`
64
- * and `,` (`Pathogenic/Likely_pathogenic`, `Pathogenic,_low_penetrance`);
65
- * `Conflicting_classifications_of_pathogenicity` holds no such term, so a
66
- * conflicted call does not count.
61
+ * The substitution a ClinVar VCF line records, when it is a single base,
62
+ * missense on some transcript, and carries a germline classification.
63
+ * `CLNSIG` joins classifications with `/`, `|` and `,`
64
+ * (`Pathogenic/Likely_pathogenic`, `Pathogenic,_low_penetrance`).
67
65
  */
68
- export function parseClinVarSnv(line) {
69
- const [, pos, , ref, alt, , , info = ''] = line.split('\t');
66
+ export function parseClinVarMissense(line) {
67
+ const [, pos, id, ref, alt, , , info = ''] = line.split('\t');
70
68
  const significance = infoField(info, 'CLNSIG')?.split(/[/|,]/);
71
69
  const consequences = infoField(info, 'MC')?.split(',');
72
70
  return pos &&
@@ -74,27 +72,70 @@ export function parseClinVarSnv(line) {
74
72
  alt &&
75
73
  BASE.test(ref) &&
76
74
  BASE.test(alt) &&
77
- significance?.some(s => s === 'Pathogenic' || s === 'Likely_pathogenic') &&
75
+ significance &&
78
76
  consequences?.some(c => c.endsWith('|missense_variant'))
79
- ? { start: +pos - 1, ref, alt }
77
+ ? {
78
+ start: +pos - 1,
79
+ ref,
80
+ alt,
81
+ id: id && id !== '.' ? id : undefined,
82
+ significance,
83
+ }
84
+ : undefined;
85
+ }
86
+ /**
87
+ * Whether ClinVar's aggregate germline classification calls a variant
88
+ * pathogenic or likely pathogenic.
89
+ * `Conflicting_classifications_of_pathogenicity` holds no such term, so a
90
+ * conflicted call does not count.
91
+ */
92
+ export function isPathogenic(significance) {
93
+ return significance.some(s => s === 'Pathogenic' || s === 'Likely_pathogenic');
94
+ }
95
+ /** The pathogenic or likely pathogenic missense substitution a line records */
96
+ export function parseClinVarSnv(line) {
97
+ const variant = parseClinVarMissense(line);
98
+ return variant && isPathogenic(variant.significance)
99
+ ? { start: variant.start, ref: variant.ref, alt: variant.alt }
80
100
  : undefined;
81
101
  }
102
+ export const CLINVAR_CATEGORIES = [
103
+ 'pathogenic',
104
+ 'likely pathogenic',
105
+ 'conflicting',
106
+ 'uncertain',
107
+ 'likely benign',
108
+ 'benign',
109
+ 'other',
110
+ ];
111
+ const CATEGORY_TERMS = [
112
+ ['Pathogenic', 'pathogenic'],
113
+ ['Likely_pathogenic', 'likely pathogenic'],
114
+ ['Conflicting_classifications_of_pathogenicity', 'conflicting'],
115
+ ['Uncertain_significance', 'uncertain'],
116
+ ['Benign', 'benign'],
117
+ ['Likely_benign', 'likely benign'],
118
+ ];
119
+ /** The one category a classification is shown under, its gravest term
120
+ * deciding: `Benign/Likely_benign` is benign, `Likely_pathogenic|risk_factor`
121
+ * likely pathogenic. */
122
+ export function clinVarCategory(significance) {
123
+ return (CATEGORY_TERMS.find(([term]) => significance.includes(term))?.[1] ?? 'other');
124
+ }
82
125
  const COMPLEMENT = { A: 'T', C: 'G', G: 'C', T: 'A' };
83
126
  /**
84
- * How many distinct missense substitutions ClinVar calls pathogenic or likely
85
- * pathogenic at each 0-based residue of a transcript. Each substitution is
86
- * translated on this transcript's own codon: `p2gCodon` (g2p_mapper's, 0-based)
87
- * lists a codon's genome positions in reading order, so a codon split by an
88
- * intron and a minus-strand codon both read right. A variant the VCF calls
89
- * missense on another transcript but that is synonymous, nonsense or outside
90
- * the coding sequence of this one does not count, nor does one whose `REF`
91
- * disagrees with the genome. Two codon changes to one amino acid count once.
92
- * Every residue with a whole codon gets a count, zero included, so a residue
93
- * ClinVar has no call for is told apart from one the structure cannot place.
94
- * `checked` counts the variants that landed on a codon, and `disagreeing`
95
- * those whose `REF` the genome does not spell.
127
+ * Each variant translated on this transcript's own codon: `p2gCodon`
128
+ * (g2p_mapper's, 0-based) lists a codon's genome positions in reading order,
129
+ * so a codon split by an intron and a minus-strand codon both read right. A
130
+ * variant the VCF calls missense on another transcript but that is
131
+ * synonymous, nonsense or outside the coding sequence of this one is left
132
+ * out, as is one whose `REF` disagrees with the genome. `residues` lists
133
+ * every residue with a whole codon, so a residue ClinVar has no call for is
134
+ * told apart from one the structure cannot place. `checked` counts the
135
+ * variants that landed on a codon, and `disagreeing` those whose `REF` the
136
+ * genome does not spell.
96
137
  */
97
- export function pathogenicCountByTranscriptPosition({ variants, p2gCodon, strand, genomeBase, codonTable, }) {
138
+ export function placeMissenseOnTranscript({ variants, p2gCodon, strand, genomeBase, codonTable, }) {
98
139
  const oriented = (base) => base && strand === -1 ? COMPLEMENT[base] : base;
99
140
  const codons = new Map();
100
141
  const residueAt = new Map();
@@ -107,10 +148,11 @@ export function pathogenicCountByTranscriptPosition({ variants, p2gCodon, strand
107
148
  });
108
149
  }
109
150
  }
110
- const substitutions = new Map();
151
+ const placed = [];
111
152
  let checked = 0;
112
153
  let disagreeing = 0;
113
- for (const { start, ref, alt } of variants) {
154
+ for (const variant of variants) {
155
+ const { start, ref, alt } = variant;
114
156
  const at = residueAt.get(start);
115
157
  const codon = at ? codons.get(at.residue) : undefined;
116
158
  if (!at || !codon) {
@@ -125,15 +167,42 @@ export function pathogenicCountByTranscriptPosition({ variants, p2gCodon, strand
125
167
  const from = codonTable[codon.join('')];
126
168
  const to = codonTable[mutated.join('')];
127
169
  if (from && to && from !== to && from !== '*' && to !== '*') {
128
- const seen = substitutions.get(at.residue) ?? new Set();
129
- seen.add(to);
130
- substitutions.set(at.residue, seen);
170
+ placed.push({ variant, residue: at.residue, from, to });
131
171
  }
132
172
  }
133
- const byPosition = new Map([...codons.keys()]
134
- .toSorted((a, b) => a - b)
135
- .map(residue => [residue, substitutions.get(residue)?.size ?? 0]));
136
- return { byPosition, checked, disagreeing };
173
+ return {
174
+ placed,
175
+ residues: [...codons.keys()].toSorted((a, b) => a - b),
176
+ checked,
177
+ disagreeing,
178
+ };
179
+ }
180
+ /**
181
+ * How many distinct substitutions land on each residue: two codon changes to
182
+ * one amino acid count once, and every residue with a whole codon gets a
183
+ * count, zero included.
184
+ */
185
+ export function substitutionCountByResidue(placed, residues) {
186
+ const substitutions = new Map();
187
+ for (const { residue, to } of placed) {
188
+ const seen = substitutions.get(residue) ?? new Set();
189
+ seen.add(to);
190
+ substitutions.set(residue, seen);
191
+ }
192
+ return new Map(residues.map(residue => [residue, substitutions.get(residue)?.size ?? 0]));
193
+ }
194
+ /**
195
+ * How many distinct missense substitutions ClinVar calls pathogenic or likely
196
+ * pathogenic at each 0-based residue of a transcript, given the pathogenic
197
+ * ones.
198
+ */
199
+ export function pathogenicCountByTranscriptPosition(args) {
200
+ const { placed, residues, checked, disagreeing } = placeMissenseOnTranscript(args);
201
+ return {
202
+ byPosition: substitutionCountByResidue(placed, residues),
203
+ checked,
204
+ disagreeing,
205
+ };
137
206
  }
138
207
  /**
139
208
  * Whether the genome under a transcript is some other build than the VCF's:
@@ -1,7 +1,7 @@
1
1
  import { TabixIndexedFile } from '@gmod/tabix';
2
2
  import { getGeneticCode } from '@jbrowse/core/util/geneticCodes';
3
3
  import { transcriptGeneticCodeId } from '@jbrowse/core/util/translateTranscript';
4
- import { clinVarRefName, clinVarVcfUrl, isWrongBuild, parseClinVarSnv, pathogenicCountByTranscriptPosition, } from './clinVar';
4
+ import { clinVarRefName, clinVarVcfUrl, isPathogenic, isWrongBuild, parseClinVarMissense, placeMissenseOnTranscript, substitutionCountByResidue, } from './clinVar';
5
5
  import { VariantEffectRefusal } from './variantEffects';
6
6
  import { fetchRegionSequence } from '../LaunchProteinView/utils/translateTranscripts';
7
7
  import { genomeToTranscriptSeqMapping } from '../mappings';
@@ -15,7 +15,7 @@ function clinVarVcf(build) {
15
15
  }
16
16
  return file;
17
17
  }
18
- async function readPathogenicSnvs(build, refNames, start, end, signal) {
18
+ async function readMissense(build, refNames, start, end, signal) {
19
19
  const file = clinVarVcf(build);
20
20
  const names = await file.getReferenceSequenceNames({ signal });
21
21
  const refName = refNames
@@ -28,20 +28,20 @@ async function readPathogenicSnvs(build, refNames, start, end, signal) {
28
28
  await file.getLines(refName, start, end, {
29
29
  signal,
30
30
  lineCallback: line => {
31
- const snv = parseClinVarSnv(line);
32
- if (snv) {
33
- variants.push(snv);
31
+ const variant = parseClinVarMissense(line);
32
+ if (variant) {
33
+ variants.push(variant);
34
34
  }
35
35
  },
36
36
  });
37
37
  return variants;
38
38
  }
39
39
  /**
40
- * The pathogenic missense count at each residue of a transcript, read from
41
- * NCBI's ClinVar VCF by range over the transcript's coding span and translated
42
- * on the genome under it
40
+ * Every missense substitution ClinVar classifies on a transcript, read from
41
+ * NCBI's VCF by range over the transcript's coding span and translated on
42
+ * the genome under it. Refuses when the genome is plainly another build.
43
43
  */
44
- export async function fetchClinVarCounts({ build, feature, assemblyName, session, signal, }) {
44
+ export async function placeClinVarOnTranscript({ build, feature, assemblyName, session, signal, }) {
45
45
  const { p2gCodon, strand, refName } = genomeToTranscriptSeqMapping(feature);
46
46
  const positions = Object.values(p2gCodon).flat();
47
47
  if (positions.length === 0) {
@@ -51,22 +51,31 @@ export async function fetchClinVarCounts({ build, feature, assemblyName, session
51
51
  const end = Math.max(...positions) + 1;
52
52
  const assembly = await session.assemblyManager.waitForAssembly(assemblyName);
53
53
  const [variants, genome] = await Promise.all([
54
- readPathogenicSnvs(build, [refName, ...(assembly?.getAliasesForRefName(refName) ?? [])], start, end, signal),
54
+ readMissense(build, [refName, ...(assembly?.getAliasesForRefName(refName) ?? [])], start, end, signal),
55
55
  fetchRegionSequence({ session, assemblyName, refName, start, end }),
56
56
  ]);
57
57
  const { seq, assemblyGeneticCodeId } = genome;
58
58
  if (!seq) {
59
59
  throw new Error('no genome sequence under the transcript');
60
60
  }
61
- const counts = pathogenicCountByTranscriptPosition({
61
+ const placement = placeMissenseOnTranscript({
62
62
  variants,
63
63
  p2gCodon,
64
64
  strand,
65
65
  genomeBase: position => seq[position - start],
66
66
  codonTable: getGeneticCode(transcriptGeneticCodeId(feature, assemblyGeneticCodeId)).codonTable,
67
67
  });
68
- if (isWrongBuild(counts)) {
69
- throw new VariantEffectRefusal(`ClinVar's REF disagrees with this assembly's sequence at ${counts.disagreeing} of ${counts.checked} variants; is the assembly ${build}?`);
68
+ if (isWrongBuild(placement)) {
69
+ throw new VariantEffectRefusal(`ClinVar's REF disagrees with this assembly's sequence at ${placement.disagreeing} of ${placement.checked} variants; is the assembly ${build}?`);
70
70
  }
71
- return counts.byPosition;
71
+ return placement;
72
+ }
73
+ /**
74
+ * The pathogenic missense count at each residue of a transcript, zero
75
+ * included for every residue with a whole codon; two codon changes to one
76
+ * amino acid count once.
77
+ */
78
+ export async function fetchClinVarCounts(args) {
79
+ const { placed, residues } = await placeClinVarOnTranscript(args);
80
+ return substitutionCountByResidue(placed.filter(p => isPathogenic(p.variant.significance)), residues);
72
81
  }
@@ -1,2 +1,2 @@
1
- import{a as s}from"./chunk-2CJBOB5B.js";import"./chunk-X5RLRQSB.js";import"./chunk-533QNNGN.js";import{a as r}from"./chunk-HLB63AD7.js";import{a}from"./chunk-HAGLAQP5.js";import{a as l}from"./chunk-GVEKA5YG.js";import{c as t}from"./chunk-KVMUXFPB.js";var e=t(l()),n=t(r()),o=t(a());var h="https://github.com/GMOD/jbrowse-plugin-protein3d/issues";function p({handleClose:i}){return e.default.createElement(n.Dialog,{open:!0,maxWidth:"lg",onClose:i,title:"Help"},e.default.createElement(o.DialogContent,null,e.default.createElement(o.Typography,{sx:{mb:2}},"Each tab finds a structure a different way. All of them end in the same place: the plugin aligns the structure's residues to the protein sequence it translates from the transcript you pick, and that alignment maps genome coordinates onto positions in the 3D view."),e.default.createElement(o.Typography,{component:"div"},e.default.createElement("ul",null,e.default.createElement("li",null,e.default.createElement("b",null,"AlphaFoldDB search")," resolves the feature to a UniProt accession \u2014 from its own identifiers, or one you type \u2014 and opens AlphaFold's predicted model for it."),e.default.createElement("li",null,e.default.createElement("b",null,"PDB search")," lists the experimental structures RCSB aligns to that accession, ranked on coverage and resolution. A crystal is usually one domain, often with binding partners, so the view picks the chain the transcript belongs to once the structure loads."),e.default.createElement("li",null,e.default.createElement("b",null,"Foldseek search")," sends the protein sequence to the foldseek.com servers and lists structures similar in shape, including ones with little sequence similarity."),e.default.createElement("li",null,e.default.createElement("b",null,"File or URL")," opens a structure you already have \u2014 the output of ColabFold or another modelling tool, or any PDB/mmCIF file reachable by URL."))),e.default.createElement(o.Typography,{sx:{mb:2}},"The isoform list marks which transcripts match the structure's residues exactly, and counts identical residues for the rest. You do not need an exact match; the alignment absorbs the differences between the two representations."),e.default.createElement(o.Typography,null,"If a gene will not resolve, or something looks wrong, please open an issue at"," ",e.default.createElement(s,{href:h},"github.com/GMOD/jbrowse-plugin-protein3d"),".")),e.default.createElement(o.Divider,null),e.default.createElement(o.DialogActions,null,e.default.createElement(o.Button,{onClick:i,color:"primary"},"Close")))}export{p as default};
2
- //# sourceMappingURL=HelpDialog-GBG7PHDR.js.map
1
+ import{a as s}from"./chunk-7Q7UK2ZL.js";import"./chunk-SIZG3XB4.js";import"./chunk-533QNNGN.js";import{a as r}from"./chunk-HLB63AD7.js";import{a}from"./chunk-HAGLAQP5.js";import{a as l}from"./chunk-GVEKA5YG.js";import{c as t}from"./chunk-KVMUXFPB.js";var e=t(l()),n=t(r()),o=t(a());var h="https://github.com/GMOD/jbrowse-plugin-protein3d/issues";function p({handleClose:i}){return e.default.createElement(n.Dialog,{open:!0,maxWidth:"lg",onClose:i,title:"Help"},e.default.createElement(o.DialogContent,null,e.default.createElement(o.Typography,{sx:{mb:2}},"Each tab finds a structure a different way. All of them end in the same place: the plugin aligns the structure's residues to the protein sequence it translates from the transcript you pick, and that alignment maps genome coordinates onto positions in the 3D view."),e.default.createElement(o.Typography,{component:"div"},e.default.createElement("ul",null,e.default.createElement("li",null,e.default.createElement("b",null,"AlphaFoldDB search")," resolves the feature to a UniProt accession \u2014 from its own identifiers, or one you type \u2014 and opens AlphaFold's predicted model for it."),e.default.createElement("li",null,e.default.createElement("b",null,"PDB search")," lists the experimental structures RCSB aligns to that accession, ranked on coverage and resolution. A crystal is usually one domain, often with binding partners, so the view picks the chain the transcript belongs to once the structure loads."),e.default.createElement("li",null,e.default.createElement("b",null,"Foldseek search")," sends the protein sequence to the foldseek.com servers and lists structures similar in shape, including ones with little sequence similarity."),e.default.createElement("li",null,e.default.createElement("b",null,"File or URL")," opens a structure you already have \u2014 the output of ColabFold or another modelling tool, or any PDB/mmCIF file reachable by URL."))),e.default.createElement(o.Typography,{sx:{mb:2}},"The isoform list marks which transcripts match the structure's residues exactly, and counts identical residues for the rest. You do not need an exact match; the alignment absorbs the differences between the two representations."),e.default.createElement(o.Typography,null,"If a gene will not resolve, or something looks wrong, please open an issue at"," ",e.default.createElement(s,{href:h},"github.com/GMOD/jbrowse-plugin-protein3d"),".")),e.default.createElement(o.Divider,null),e.default.createElement(o.DialogActions,null,e.default.createElement(o.Button,{onClick:i,color:"primary"},"Close")))}export{p as default};
2
+ //# sourceMappingURL=HelpDialog-IRAXBGZB.js.map
@@ -1,8 +1,8 @@
1
- import{c as w,d as q}from"./chunk-C2KRWQQY.js";import"./chunk-QPR5H2OZ.js";import"./chunk-SQLUPFUS.js";import{a as L}from"./chunk-LOG7ZCI7.js";import{a as k}from"./chunk-HAGLAQP5.js";import{a as S}from"./chunk-GVEKA5YG.js";import{c as g}from"./chunk-KVMUXFPB.js";var r=g(S()),o=g(k());function x(t){let e=t.next();for(;!e.done&&e.value.trim()==="";)e=t.next();return e.value}function E(t){let e=t.trim();return e?e.split(/\s+/).every(n=>/^\d+$/.test(n)):!1}function C(t){let e=t.trim();return/^\w+\s+/.test(e)&&!E(t)}function D(t){return t.length>=3&&/^\d+$/.test(t[1])}function v(t,e){let n=t.trim().split(/\s+/),i=n[e],l=t.indexOf(i,t.indexOf(n[0])+n[0].length);return[l,l+i.length]}function y(t){let e=x(t),s=[],n="";if(!e)return;for(;e;)E(e)||(C(e)?s.push(e):n=e),e=t.next().value;if(s.length===0)return;let i=s.map(p=>p.trim().split(/\s+/)),l=i[0];if(!l)return;let a=D(l)?2:1,[c,f]=v(s[0],a),u=i.map(p=>p[0]),m=i.map(p=>p[a]),d=n.slice(c,f),h=m[0];if(h){let p=h.length-d.length;p>0&&(d+=" ".repeat(p))}return{ids:u,seqs:m,consensus:d}}function b(t){let e,s=y(t);if(s!==void 0)for(;e=y(t);){for(let n=0;n<e.seqs.length;n++)s.seqs[n]+=e.seqs[n];s.consensus+=e.consensus}return s}function A(t){let e=t.split(`
1
+ import{c as w,d as q}from"./chunk-C2KRWQQY.js";import"./chunk-QPR5H2OZ.js";import"./chunk-SPXMXPSC.js";import{a as L}from"./chunk-LOG7ZCI7.js";import{a as k}from"./chunk-HAGLAQP5.js";import{a as S}from"./chunk-GVEKA5YG.js";import{c as g}from"./chunk-KVMUXFPB.js";var r=g(S()),o=g(k());function x(t){let e=t.next();for(;!e.done&&e.value.trim()==="";)e=t.next();return e.value}function E(t){let e=t.trim();return e?e.split(/\s+/).every(n=>/^\d+$/.test(n)):!1}function C(t){let e=t.trim();return/^\w+\s+/.test(e)&&!E(t)}function D(t){return t.length>=3&&/^\d+$/.test(t[1])}function v(t,e){let n=t.trim().split(/\s+/),i=n[e],l=t.indexOf(i,t.indexOf(n[0])+n[0].length);return[l,l+i.length]}function y(t){let e=x(t),s=[],n="";if(!e)return;for(;e;)E(e)||(C(e)?s.push(e):n=e),e=t.next().value;if(s.length===0)return;let i=s.map(p=>p.trim().split(/\s+/)),l=i[0];if(!l)return;let a=D(l)?2:1,[c,f]=v(s[0],a),u=i.map(p=>p[0]),m=i.map(p=>p[a]),d=n.slice(c,f),h=m[0];if(h){let p=h.length-d.length;p>0&&(d+=" ".repeat(p))}return{ids:u,seqs:m,consensus:d}}function b(t){let e,s=y(t);if(s!==void 0)for(;e=y(t);){for(let n=0;n<e.seqs.length;n++)s.seqs[n]+=e.seqs[n];s.consensus+=e.consensus}return s}function A(t){let e=t.split(`
2
2
  `).filter(a=>!a.startsWith("#")).join(`
3
3
  `),s=b(e.split(`
4
4
  `)[Symbol.iterator]());if(s===void 0)throw new Error("No blocks parsed");let n=s.seqs.map((a,c)=>({id:s.ids[c],seq:a})),{consensus:i}=s,l=n[0];if(!l)throw new Error("No alignments found");if(i.length!==l.seq.length)throw new Error(`Consensus length !== sequence length. Con ${i.length} seq ${l.seq.length}`);if(n.length!==2)throw new Error(`Expected exactly 2 sequences in pairwise alignment, got ${n.length}`);return{consensus:i,alns:n}}var P=g(L());var B=(0,P.observer)(function({model:e,handleClose:s}){let[n,i]=(0,r.useState)(""),[l,a]=(0,r.useState)(),{alignmentStructure:c}=e,f=()=>{if(n.trim())try{let u=A(n.trim()),m=c?.entities,d=c&&m?q(u,c.userProvidedTranscriptSequence,m,c.mappedEntityId):void 0;!c||!d?a("No structure loaded to apply alignment to"):"problem"in d?a(d.problem):(c.importAlignment(w(u)),s())}catch(u){a(`Failed to parse alignment: ${u}`)}};return r.default.createElement(o.Dialog,{open:!0,onClose:s,maxWidth:"md",fullWidth:!0},r.default.createElement(o.DialogTitle,null,"Import manual alignment",c?.label?` for ${c.label}`:""),r.default.createElement(o.DialogContent,null,r.default.createElement(o.Typography,{variant:"body2",color:"text.secondary",sx:{mb:2}},"Paste a pre-computed alignment in Clustal format. The first sequence should be the transcript and the second should be the structure."),r.default.createElement(o.TextField,{multiline:!0,rows:12,fullWidth:!0,placeholder:`Example:
5
5
  transcript MKAAYLSMFGKEDHKPFGDDEVELFRAVPGLKLKIAG
6
6
  |||||||||||||||||||||||||||||||||||||
7
7
  structure MKAAYLSMFGKEDHKPFGDDEVELFRAVPGLKLKIAG`,value:n,onChange:u=>{i(u.target.value),a(void 0)},slotProps:{htmlInput:{style:{fontFamily:"monospace",fontSize:12}}}}),l?r.default.createElement(o.Typography,{color:"error",variant:"body2",sx:{mt:1}},l):null),r.default.createElement(o.DialogActions,null,r.default.createElement(o.Button,{onClick:s},"Cancel"),r.default.createElement(o.Button,{onClick:()=>{f()},variant:"contained",color:"primary",disabled:!n.trim()},"Apply alignment")))}),I=B;export{I as default};
8
- //# sourceMappingURL=ManualAlignmentDialog-B35TUUYU.js.map
8
+ //# sourceMappingURL=ManualAlignmentDialog-BTL4LYX2.js.map