jbrowse-plugin-msaview 2.6.0 → 2.6.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.
@@ -1,34 +1,24 @@
1
1
  export default function LaunchMsaViewExtensionPointF(pluginManager) {
2
- pluginManager.addToExtensionPoint('LaunchView-MsaView',
3
- // @ts-expect-error
4
- ({ session, data, msaFileLocation, msaTabixLocation, msaIndexLocation, msaId, treeFileLocation, connectedViewId, connectedFeature, displayName, colorSchemeName, colWidth, rowHeight, treeAreaWidth, treeWidth, drawNodeBubbles, labelsAlignRight, showBranchLen, querySeqName, highlightColumns, }) => {
5
- if (!data && !msaFileLocation && !msaTabixLocation) {
2
+ pluginManager.addToExtensionPoint('LaunchView-MsaView', (args) => {
3
+ const { session, data, msaFileLocation, msaIndexedLocation, msaName, treeFileLocation, querySeqName, ...rest } = args;
4
+ if (!data && !msaFileLocation && !msaIndexedLocation) {
6
5
  throw new Error('No MSA data or file location provided when launching MSA view');
7
6
  }
7
+ // all data sources flow through `init` so processInit is the single place
8
+ // that resolves them (AlphaFold detection, native filehandle loading, etc.)
8
9
  session.addView('MsaView', {
9
10
  type: 'MsaView',
10
- displayName,
11
- connectedViewId,
12
- connectedFeature,
13
- colorSchemeName,
14
- colWidth,
15
- rowHeight,
16
- treeAreaWidth,
17
- treeWidth,
18
- drawNodeBubbles,
19
- labelsAlignRight,
20
- showBranchLen,
21
- highlightColumns,
11
+ ...rest,
22
12
  init: {
23
13
  msaData: data?.msa,
24
14
  treeData: data?.tree,
25
15
  msaUrl: msaFileLocation?.uri,
26
- msaTabixLocation,
27
- msaIndexLocation,
28
- msaId,
16
+ msaIndexedLocation,
17
+ msaName,
29
18
  treeUrl: treeFileLocation?.uri,
30
19
  querySeqName,
31
20
  },
32
21
  });
22
+ return args;
33
23
  });
34
24
  }
@@ -1,6 +1,6 @@
1
1
  import { getSession } from '@jbrowse/core/util';
2
2
  import { doLaunchBlast } from './doLaunchBlast';
3
- import { fetchTabixMsa } from './fetchTabixMsa';
3
+ import { fetchIndexedMsa } from './fetchIndexedMsa';
4
4
  import { genomeToMSA } from './genomeToMSA';
5
5
  import { loadProteinDomains } from './loadProteinDomains';
6
6
  import { cleanupOldData, generateDataStoreId, retrieveMsaData, storeMsaData, } from './msaDataStore';
@@ -116,13 +116,17 @@ export function autoLoadProteinDomains(self) {
116
116
  })();
117
117
  }
118
118
  }
119
+ // Resolve the declarative `init` launch contract once. Inline strings go straight
120
+ // to the data model; URLs are handed to react-msaview's native filehandle loaders
121
+ // (openLocation + progress + abort + CORS-proxy) rather than a hand-rolled fetch;
122
+ // the bgzip name-indexed block is the one source with no native loader.
119
123
  export function processInit(self) {
120
124
  const { init } = self;
121
125
  if (init) {
126
+ const { msaData, msaUrl, msaIndexedLocation, msaName, treeData, treeUrl, querySeqName, } = init;
122
127
  void (async () => {
123
128
  try {
124
129
  self.setError(undefined);
125
- const { msaData, msaUrl, msaTabixLocation, msaIndexLocation, msaId, treeData, treeUrl, querySeqName, } = init;
126
130
  if (msaUrl) {
127
131
  const id = getUniprotIdFromAlphaFoldUrl(msaUrl);
128
132
  if (id) {
@@ -137,42 +141,25 @@ export function processInit(self) {
137
141
  self.setMSA(msaData);
138
142
  }
139
143
  else if (msaUrl) {
140
- const response = await fetch(msaUrl);
141
- if (!response.ok) {
142
- throw new Error(`Failed to fetch MSA: ${response.status}`);
143
- }
144
- const data = await response.text();
145
- self.setMSA(data);
144
+ self.setMSAFilehandle({ uri: msaUrl, locationType: 'UriLocation' });
146
145
  }
147
- else if (msaTabixLocation) {
148
- const feature = self.connectedFeature;
149
- if (feature) {
150
- const fasta = await fetchTabixMsa({
151
- location: msaTabixLocation,
152
- indexLocation: msaIndexLocation,
153
- msaId: msaId ?? String(feature.name),
154
- refName: String(feature.refName),
155
- start: Number(feature.start),
156
- end: Number(feature.end),
157
- });
158
- if (fasta) {
159
- self.setMSA(fasta);
160
- }
161
- else {
162
- throw new Error(`No alignment for ${msaId ?? String(feature.name)} in ${msaTabixLocation.uri}`);
163
- }
146
+ else if (msaIndexedLocation && msaName) {
147
+ const fasta = await fetchIndexedMsa({
148
+ location: msaIndexedLocation,
149
+ name: msaName,
150
+ });
151
+ if (fasta) {
152
+ self.setMSA(fasta);
153
+ }
154
+ else {
155
+ throw new Error(`No alignment named ${msaName} in ${msaIndexedLocation.uri}`);
164
156
  }
165
157
  }
166
158
  if (treeData) {
167
159
  self.setTree(treeData);
168
160
  }
169
161
  else if (treeUrl) {
170
- const response = await fetch(treeUrl);
171
- if (!response.ok) {
172
- throw new Error(`Failed to fetch tree: ${response.status}`);
173
- }
174
- const data = await response.text();
175
- self.setTree(data);
162
+ self.setTreeFilehandle({ uri: treeUrl, locationType: 'UriLocation' });
176
163
  }
177
164
  self.setInit(undefined);
178
165
  }
@@ -0,0 +1,6 @@
1
+ export declare function fetchIndexedMsa({ location, name, }: {
2
+ location: {
3
+ uri: string;
4
+ };
5
+ name: string;
6
+ }): Promise<string | undefined>;
@@ -0,0 +1,36 @@
1
+ import { BgzfFilehandle } from '@gmod/bgzf-filehandle';
2
+ import { openLocation } from '@jbrowse/core/util/io';
3
+ // Pull one transcript's whole multiple-alignment out of a single bgzip file
4
+ // keyed by NAME. Given the `.fa.gz` uri, the bgzip index (`.gzi`) and name index
5
+ // (`.idx`, a TSV `name<TAB>offset<TAB>length` of each block's uncompressed byte
6
+ // offset + length) are found by suffix. We fetch the small `.idx` once, look up
7
+ // the name, and random-read just that block — already valid FASTA
8
+ // (`>hg38\nSEQ\n>panTro4\nSEQ\n...`). One genome-scale alignment serves any gene
9
+ // with no per-gene files or coordinates. See react-msaview's gene-explorer.
10
+ export async function fetchIndexedMsa({ location, name, }) {
11
+ const open = (uri) => openLocation({ uri, locationType: 'UriLocation' });
12
+ const idxText = await open(`${location.uri}.idx`).readFile('utf8');
13
+ const entry = lookup(idxText, name);
14
+ if (entry) {
15
+ const fh = new BgzfFilehandle({
16
+ filehandle: open(location.uri),
17
+ gziFilehandle: open(`${location.uri}.gzi`),
18
+ });
19
+ const bytes = await fh.read(entry.length, entry.offset);
20
+ return new TextDecoder().decode(bytes).trim();
21
+ }
22
+ return undefined;
23
+ }
24
+ // ids are matched versionless, so version drift between the alignment build and
25
+ // the live annotation never breaks the lookup
26
+ const versionless = (s) => s.replace(/\.\d+$/, '');
27
+ function lookup(idxText, name) {
28
+ const want = versionless(name);
29
+ for (const line of idxText.split('\n')) {
30
+ const [id, offset, length] = line.split('\t');
31
+ if (id && versionless(id) === want) {
32
+ return { offset: Number(offset), length: Number(length) };
33
+ }
34
+ }
35
+ return undefined;
36
+ }
@@ -1,13 +1,10 @@
1
1
  export interface MsaViewInitState {
2
2
  msaData?: string;
3
3
  msaUrl?: string;
4
- msaTabixLocation?: {
4
+ msaIndexedLocation?: {
5
5
  uri: string;
6
6
  };
7
- msaIndexLocation?: {
8
- uri: string;
9
- };
10
- msaId?: string;
7
+ msaName?: string;
11
8
  treeData?: string;
12
9
  treeUrl?: string;
13
10
  querySeqName?: string;