jbrowse-plugin-msaview 2.2.11 → 2.3.2

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 (129) hide show
  1. package/dist/AddHighlightModel/index.d.ts +1 -1
  2. package/dist/AddHighlightModel/index.js.map +1 -1
  3. package/dist/BgzipFastaMsaAdapter/BgzipFastaMsaAdapter.d.ts +2 -1
  4. package/dist/BgzipFastaMsaAdapter/BgzipFastaMsaAdapter.js +1 -1
  5. package/dist/BgzipFastaMsaAdapter/BgzipFastaMsaAdapter.js.map +1 -1
  6. package/dist/BgzipFastaMsaAdapter/configSchema.d.ts +1 -1
  7. package/dist/BgzipFastaMsaAdapter/configSchema.js.map +1 -1
  8. package/dist/BgzipFastaMsaAdapter/index.d.ts +1 -1
  9. package/dist/BgzipFastaMsaAdapter/index.js.map +1 -1
  10. package/dist/LaunchMsaView/components/EnsemblGeneTree/EnsemblGeneTree.d.ts +1 -1
  11. package/dist/LaunchMsaView/components/EnsemblGeneTree/EnsemblGeneTree.js +1 -1
  12. package/dist/LaunchMsaView/components/EnsemblGeneTree/EnsemblGeneTree.js.map +1 -1
  13. package/dist/LaunchMsaView/components/EnsemblGeneTree/ensemblGeneTreeUtils.js.map +1 -1
  14. package/dist/LaunchMsaView/components/LaunchMsaViewDialog.d.ts +1 -1
  15. package/dist/LaunchMsaView/components/LaunchMsaViewDialog.js.map +1 -1
  16. package/dist/LaunchMsaView/components/ManualMSALoader/ManualMSALoader.d.ts +1 -1
  17. package/dist/LaunchMsaView/components/ManualMSALoader/ManualMSALoader.js +1 -1
  18. package/dist/LaunchMsaView/components/ManualMSALoader/ManualMSALoader.js.map +1 -1
  19. package/dist/LaunchMsaView/components/ManualMSALoader/launchView.d.ts +1 -1
  20. package/dist/LaunchMsaView/components/ManualMSALoader/launchView.js.map +1 -1
  21. package/dist/LaunchMsaView/components/NCBIBlastQuery/CachedBlastResults.d.ts +1 -2
  22. package/dist/LaunchMsaView/components/NCBIBlastQuery/CachedBlastResults.js +21 -14
  23. package/dist/LaunchMsaView/components/NCBIBlastQuery/CachedBlastResults.js.map +1 -1
  24. package/dist/LaunchMsaView/components/NCBIBlastQuery/NCBIBlastAutomaticPanel.d.ts +1 -1
  25. package/dist/LaunchMsaView/components/NCBIBlastQuery/NCBIBlastAutomaticPanel.js +32 -35
  26. package/dist/LaunchMsaView/components/NCBIBlastQuery/NCBIBlastAutomaticPanel.js.map +1 -1
  27. package/dist/LaunchMsaView/components/NCBIBlastQuery/NCBIBlastRIDPanel.d.ts +1 -1
  28. package/dist/LaunchMsaView/components/NCBIBlastQuery/NCBIBlastRIDPanel.js +2 -2
  29. package/dist/LaunchMsaView/components/NCBIBlastQuery/NCBIBlastRIDPanel.js.map +1 -1
  30. package/dist/LaunchMsaView/components/NCBIBlastQuery/blastLaunchView.d.ts +1 -1
  31. package/dist/LaunchMsaView/components/NCBIBlastQuery/blastLaunchView.js.map +1 -1
  32. package/dist/LaunchMsaView/components/NCBIBlastQuery/consts.d.ts +2 -0
  33. package/dist/LaunchMsaView/components/NCBIBlastQuery/consts.js +1 -0
  34. package/dist/LaunchMsaView/components/NCBIBlastQuery/consts.js.map +1 -1
  35. package/dist/LaunchMsaView/components/PreLoadedMSA/PreLoadedMSADataPanel.d.ts +1 -1
  36. package/dist/LaunchMsaView/components/PreLoadedMSA/PreLoadedMSADataPanel.js +6 -8
  37. package/dist/LaunchMsaView/components/PreLoadedMSA/PreLoadedMSADataPanel.js.map +1 -1
  38. package/dist/LaunchMsaView/components/PreLoadedMSA/fetchMSAData.d.ts +2 -2
  39. package/dist/LaunchMsaView/components/PreLoadedMSA/fetchMSAData.js.map +1 -1
  40. package/dist/LaunchMsaView/components/PreLoadedMSA/preCalculatedLaunchView.d.ts +1 -1
  41. package/dist/LaunchMsaView/components/PreLoadedMSA/preCalculatedLaunchView.js.map +1 -1
  42. package/dist/LaunchMsaView/components/TranscriptSelector.d.ts +3 -3
  43. package/dist/LaunchMsaView/components/TranscriptSelector.js +4 -4
  44. package/dist/LaunchMsaView/components/TranscriptSelector.js.map +1 -1
  45. package/dist/LaunchMsaView/components/useTranscriptSelection.d.ts +1 -1
  46. package/dist/LaunchMsaView/components/useTranscriptSelection.js +1 -2
  47. package/dist/LaunchMsaView/components/useTranscriptSelection.js.map +1 -1
  48. package/dist/LaunchMsaView/components/util.js +1 -1
  49. package/dist/LaunchMsaView/components/util.js.map +1 -1
  50. package/dist/LaunchMsaView/index.d.ts +1 -1
  51. package/dist/LaunchMsaView/index.js.map +1 -1
  52. package/dist/LaunchMsaView/util.d.ts +1 -0
  53. package/dist/LaunchMsaView/util.js +10 -0
  54. package/dist/LaunchMsaView/util.js.map +1 -1
  55. package/dist/MsaViewPanel/afterCreateAutoruns.d.ts +10 -0
  56. package/dist/MsaViewPanel/afterCreateAutoruns.js +258 -0
  57. package/dist/MsaViewPanel/afterCreateAutoruns.js.map +1 -0
  58. package/dist/MsaViewPanel/blosum62.d.ts +2 -0
  59. package/dist/MsaViewPanel/blosum62.js +628 -0
  60. package/dist/MsaViewPanel/blosum62.js.map +1 -0
  61. package/dist/MsaViewPanel/components/LoadingBLAST.d.ts +1 -1
  62. package/dist/MsaViewPanel/components/LoadingBLAST.js.map +1 -1
  63. package/dist/MsaViewPanel/components/MsaViewPanel.d.ts +1 -1
  64. package/dist/MsaViewPanel/components/MsaViewPanel.js.map +1 -1
  65. package/dist/MsaViewPanel/doLaunchBlast.d.ts +1 -1
  66. package/dist/MsaViewPanel/doLaunchBlast.js.map +1 -1
  67. package/dist/MsaViewPanel/genomeToMSA.d.ts +1 -1
  68. package/dist/MsaViewPanel/genomeToMSA.js.map +1 -1
  69. package/dist/MsaViewPanel/index.d.ts +1 -1
  70. package/dist/MsaViewPanel/index.js.map +1 -1
  71. package/dist/MsaViewPanel/model.d.ts +25 -39
  72. package/dist/MsaViewPanel/model.js +17 -309
  73. package/dist/MsaViewPanel/model.js.map +1 -1
  74. package/dist/MsaViewPanel/msaDataStore.d.ts +3 -4
  75. package/dist/MsaViewPanel/msaDataStore.js +59 -173
  76. package/dist/MsaViewPanel/msaDataStore.js.map +1 -1
  77. package/dist/MsaViewPanel/pairwiseAlignment.d.ts +0 -7
  78. package/dist/MsaViewPanel/pairwiseAlignment.js +1 -636
  79. package/dist/MsaViewPanel/pairwiseAlignment.js.map +1 -1
  80. package/dist/MsaViewPanel/structureConnection.js +1 -5
  81. package/dist/MsaViewPanel/structureConnection.js.map +1 -1
  82. package/dist/MsaViewPanel/util.d.ts +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.js.map +1 -1
  85. package/dist/jbrowse-plugin-msaview.umd.production.min.js +30 -30
  86. package/dist/jbrowse-plugin-msaview.umd.production.min.js.map +4 -4
  87. package/dist/utils/msa.js +35 -77
  88. package/dist/utils/msa.js.map +1 -1
  89. package/dist/utils/ncbiBlast.js +1 -10
  90. package/dist/utils/ncbiBlast.js.map +1 -1
  91. package/package.json +31 -28
  92. package/src/AddHighlightModel/index.tsx +1 -1
  93. package/src/BgzipFastaMsaAdapter/BgzipFastaMsaAdapter.ts +3 -4
  94. package/src/BgzipFastaMsaAdapter/configSchema.ts +2 -1
  95. package/src/BgzipFastaMsaAdapter/index.ts +2 -1
  96. package/src/LaunchMsaView/components/EnsemblGeneTree/EnsemblGeneTree.tsx +2 -6
  97. package/src/LaunchMsaView/components/EnsemblGeneTree/ensemblGeneTreeUtils.ts +2 -1
  98. package/src/LaunchMsaView/components/LaunchMsaViewDialog.tsx +2 -1
  99. package/src/LaunchMsaView/components/ManualMSALoader/ManualMSALoader.tsx +6 -7
  100. package/src/LaunchMsaView/components/ManualMSALoader/launchView.ts +5 -2
  101. package/src/LaunchMsaView/components/NCBIBlastQuery/CachedBlastResults.tsx +22 -17
  102. package/src/LaunchMsaView/components/NCBIBlastQuery/NCBIBlastAutomaticPanel.tsx +40 -52
  103. package/src/LaunchMsaView/components/NCBIBlastQuery/NCBIBlastRIDPanel.tsx +6 -13
  104. package/src/LaunchMsaView/components/NCBIBlastQuery/blastLaunchView.ts +2 -1
  105. package/src/LaunchMsaView/components/NCBIBlastQuery/consts.ts +2 -0
  106. package/src/LaunchMsaView/components/PreLoadedMSA/PreLoadedMSADataPanel.tsx +7 -19
  107. package/src/LaunchMsaView/components/PreLoadedMSA/fetchMSAData.ts +2 -2
  108. package/src/LaunchMsaView/components/PreLoadedMSA/preCalculatedLaunchView.ts +1 -2
  109. package/src/LaunchMsaView/components/TranscriptSelector.tsx +7 -6
  110. package/src/LaunchMsaView/components/useTranscriptSelection.ts +1 -6
  111. package/src/LaunchMsaView/components/util.ts +1 -1
  112. package/src/LaunchMsaView/index.ts +6 -5
  113. package/src/LaunchMsaView/util.ts +11 -0
  114. package/src/MsaViewPanel/afterCreateAutoruns.ts +299 -0
  115. package/src/MsaViewPanel/blosum62.ts +628 -0
  116. package/src/MsaViewPanel/components/LoadingBLAST.tsx +2 -1
  117. package/src/MsaViewPanel/components/MsaViewPanel.tsx +2 -1
  118. package/src/MsaViewPanel/doLaunchBlast.ts +1 -1
  119. package/src/MsaViewPanel/genomeToMSA.ts +2 -1
  120. package/src/MsaViewPanel/index.ts +2 -1
  121. package/src/MsaViewPanel/model.ts +30 -392
  122. package/src/MsaViewPanel/msaDataStore.ts +56 -196
  123. package/src/MsaViewPanel/pairwiseAlignment.ts +1 -637
  124. package/src/MsaViewPanel/structureConnection.ts +1 -5
  125. package/src/MsaViewPanel/util.ts +1 -1
  126. package/src/index.ts +4 -2
  127. package/src/utils/msa.ts +45 -100
  128. package/src/utils/ncbiBlast.ts +3 -13
  129. package/CHANGELOG.md +0 -101
@@ -0,0 +1,299 @@
1
+ import { getSession } from '@jbrowse/core/util'
2
+
3
+ import { doLaunchBlast } from './doLaunchBlast'
4
+ import { msaCoordToGenomeCoord } from './msaCoordToGenomeCoord'
5
+ import {
6
+ cleanupOldData,
7
+ generateDataStoreId,
8
+ retrieveMsaData,
9
+ storeMsaData,
10
+ } from './msaDataStore'
11
+ import { gappedToUngappedPosition } from './structureConnection'
12
+ import { getUniprotIdFromAlphaFoldUrl } from './util'
13
+
14
+ import type { JBrowsePluginMsaViewModel } from './model'
15
+
16
+ export function loadStoredData(self: JBrowsePluginMsaViewModel) {
17
+ const { dataStoreId, rows } = self
18
+ if (dataStoreId && rows.length === 0) {
19
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
20
+ ;(async () => {
21
+ try {
22
+ self.setLoadingStoredData(true)
23
+ const storedData = await retrieveMsaData(dataStoreId)
24
+ if (storedData) {
25
+ if (storedData.msa) {
26
+ self.setMSA(storedData.msa)
27
+ }
28
+ if (storedData.tree) {
29
+ self.setTree(storedData.tree)
30
+ }
31
+ }
32
+ } catch (e) {
33
+ console.error('Failed to load MSA data from IndexedDB:', e)
34
+ } finally {
35
+ self.setLoadingStoredData(false)
36
+ }
37
+ })()
38
+ }
39
+ }
40
+
41
+ export function storeDataToIndexedDB(self: JBrowsePluginMsaViewModel) {
42
+ const { rows, dataStoreId } = self
43
+ if (rows.length > 0 && !dataStoreId) {
44
+ const hasFilehandle = !!(self.msaFilehandle ?? self.treeFilehandle)
45
+ if (hasFilehandle) {
46
+ return
47
+ }
48
+
49
+ const msaData = self.data.msa
50
+ const treeData = self.data.tree
51
+
52
+ if (msaData || treeData) {
53
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
54
+ ;(async () => {
55
+ try {
56
+ const newId = generateDataStoreId()
57
+ const success = await storeMsaData(newId, {
58
+ msa: msaData,
59
+ tree: treeData,
60
+ treeMetadata: self.data.treeMetadata,
61
+ })
62
+ if (success) {
63
+ self.setDataStoreId(newId)
64
+ }
65
+ } catch (e) {
66
+ console.error('Failed to store MSA data to IndexedDB:', e)
67
+ }
68
+ })()
69
+ }
70
+ }
71
+ }
72
+
73
+ export function launchBlastIfNeeded(self: JBrowsePluginMsaViewModel) {
74
+ if (self.blastParams) {
75
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
76
+ ;(async () => {
77
+ try {
78
+ self.setProgress('Submitting query')
79
+ self.setError(undefined)
80
+ const data = await doLaunchBlast({ self })
81
+ self.setData(data)
82
+ self.setBlastParams(undefined)
83
+ } catch (e) {
84
+ self.setError(e)
85
+ console.error(e)
86
+ } finally {
87
+ self.setProgress('')
88
+ }
89
+ })()
90
+ }
91
+ }
92
+
93
+ export function processInit(self: JBrowsePluginMsaViewModel) {
94
+ const { init } = self
95
+ if (init) {
96
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
97
+ ;(async () => {
98
+ try {
99
+ self.setError(undefined)
100
+ const { msaData, msaUrl, treeData, treeUrl, querySeqName } = init
101
+
102
+ if (msaUrl) {
103
+ const id = getUniprotIdFromAlphaFoldUrl(msaUrl)
104
+ if (id) {
105
+ self.setUniprotId(id)
106
+ self.setQuerySeqName('query')
107
+ }
108
+ }
109
+
110
+ if (querySeqName) {
111
+ self.setQuerySeqName(querySeqName)
112
+ }
113
+
114
+ if (msaData) {
115
+ self.setMSA(msaData)
116
+ } else if (msaUrl) {
117
+ const response = await fetch(msaUrl)
118
+ if (!response.ok) {
119
+ throw new Error(`Failed to fetch MSA: ${response.status}`)
120
+ }
121
+ const data = await response.text()
122
+ self.setMSA(data)
123
+ }
124
+
125
+ if (treeData) {
126
+ self.setTree(treeData)
127
+ } else if (treeUrl) {
128
+ const response = await fetch(treeUrl)
129
+ if (!response.ok) {
130
+ throw new Error(`Failed to fetch tree: ${response.status}`)
131
+ }
132
+ const data = await response.text()
133
+ self.setTree(data)
134
+ }
135
+
136
+ self.setInit(undefined)
137
+ } catch (e) {
138
+ self.setError(e)
139
+ console.error(e)
140
+ }
141
+ })()
142
+ }
143
+ }
144
+
145
+ export function updateGenomeHighlights(self: JBrowsePluginMsaViewModel) {
146
+ const { mouseCol, mouseClickCol } = self
147
+ const r1 =
148
+ mouseCol === undefined
149
+ ? undefined
150
+ : msaCoordToGenomeCoord({ model: self, coord: mouseCol })
151
+ const r2 =
152
+ mouseClickCol === undefined
153
+ ? undefined
154
+ : msaCoordToGenomeCoord({ model: self, coord: mouseClickCol })
155
+
156
+ self.setConnectedHighlights([r1, r2].filter(f => !!f))
157
+ }
158
+
159
+ export function highlightConnectedStructures(self: JBrowsePluginMsaViewModel) {
160
+ const { mouseCol, connectedProteinViews } = self
161
+ if (connectedProteinViews.length === 0) {
162
+ return
163
+ }
164
+
165
+ for (const conn of connectedProteinViews) {
166
+ const structure = conn.proteinView?.structures?.[conn.structureIdx]
167
+ if (!structure) {
168
+ continue
169
+ }
170
+
171
+ if (mouseCol === undefined) {
172
+ structure.clearHighlightFromExternal?.()
173
+ continue
174
+ }
175
+
176
+ const seq = self.getSequenceByRowName(conn.msaRowName)
177
+ if (!seq) {
178
+ continue
179
+ }
180
+
181
+ const msaUngapped = gappedToUngappedPosition(seq, mouseCol)
182
+ if (msaUngapped === undefined) {
183
+ structure.clearHighlightFromExternal?.()
184
+ continue
185
+ }
186
+
187
+ const structurePos = conn.msaToStructure[msaUngapped]
188
+ if (structurePos === undefined) {
189
+ structure.clearHighlightFromExternal?.()
190
+ } else {
191
+ structure.highlightFromExternal?.(structurePos)
192
+ }
193
+ }
194
+ }
195
+
196
+ export function autoConnectStructures(self: JBrowsePluginMsaViewModel) {
197
+ const { views } = getSession(self)
198
+ const { connectedViewId, uniprotId, rows, connectedStructures } = self
199
+
200
+ if (!uniprotId || rows.length === 0) {
201
+ return
202
+ }
203
+
204
+ for (const view of views) {
205
+ const v = view as any
206
+ if (v.type !== 'ProteinView' || !v.structures) {
207
+ continue
208
+ }
209
+
210
+ for (
211
+ let structureIdx = 0;
212
+ structureIdx < v.structures.length;
213
+ structureIdx++
214
+ ) {
215
+ const structure = v.structures[structureIdx]
216
+
217
+ if (structure.connectedViewId !== connectedViewId) {
218
+ continue
219
+ }
220
+
221
+ if (structure.uniprotId !== uniprotId) {
222
+ continue
223
+ }
224
+
225
+ const alreadyConnected = connectedStructures.some(
226
+ c => c.proteinViewId === v.id && c.structureIdx === structureIdx,
227
+ )
228
+ if (alreadyConnected) {
229
+ continue
230
+ }
231
+
232
+ if (!structure.structureSequences?.[0]) {
233
+ continue
234
+ }
235
+
236
+ try {
237
+ self.connectToStructure(v.id, structureIdx)
238
+ } catch (e) {
239
+ console.error('Failed to auto-connect to ProteinView:', e)
240
+ }
241
+ }
242
+ }
243
+ }
244
+
245
+ export function observeProteinHighlights(self: JBrowsePluginMsaViewModel) {
246
+ const { views } = getSession(self)
247
+ const { connectedViewId, transcriptToMsaMap, querySeqName } = self
248
+
249
+ if (!connectedViewId || !transcriptToMsaMap) {
250
+ return
251
+ }
252
+
253
+ const columns: number[] = []
254
+
255
+ for (const view of views) {
256
+ const v = view as any
257
+ if (v.type !== 'ProteinView' || !v.structures) {
258
+ continue
259
+ }
260
+
261
+ for (const structure of v.structures) {
262
+ if (structure.connectedViewId !== connectedViewId) {
263
+ continue
264
+ }
265
+
266
+ const highlights = structure.hoverGenomeHighlights
267
+ if (!highlights || highlights.length === 0) {
268
+ continue
269
+ }
270
+
271
+ const { g2p } = transcriptToMsaMap
272
+ for (const highlight of highlights) {
273
+ for (let coord = highlight.start; coord < highlight.end; coord++) {
274
+ const proteinPos = g2p[coord]
275
+ if (proteinPos !== undefined) {
276
+ const col = self.seqPosToGlobalCol(querySeqName, proteinPos)
277
+ if (!columns.includes(col)) {
278
+ columns.push(col)
279
+ }
280
+ }
281
+ }
282
+ }
283
+ }
284
+ }
285
+
286
+ const visibleColumns = columns
287
+ .map(col => self.globalColToVisibleCol(col))
288
+ .filter((col): col is number => col !== undefined)
289
+
290
+ self.setHighlightedColumns(
291
+ visibleColumns.length > 0 ? visibleColumns : undefined,
292
+ )
293
+ }
294
+
295
+ export function runCleanup() {
296
+ cleanupOldData().catch((e: unknown) => {
297
+ console.error('Failed to cleanup old MSA data:', e)
298
+ })
299
+ }