jbrowse-plugin-msaview 2.6.0 → 2.6.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.
@@ -1,8 +1,8 @@
1
1
  export default function LaunchMsaViewExtensionPointF(pluginManager) {
2
2
  pluginManager.addToExtensionPoint('LaunchView-MsaView',
3
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) {
4
+ ({ session, data, msaFileLocation, msaIndexedLocation, msaName, treeFileLocation, connectedViewId, connectedFeature, displayName, colorSchemeName, colWidth, rowHeight, treeAreaWidth, treeWidth, drawNodeBubbles, labelsAlignRight, showBranchLen, querySeqName, highlightColumns, }) => {
5
+ if (!data && !msaFileLocation && !msaIndexedLocation) {
6
6
  throw new Error('No MSA data or file location provided when launching MSA view');
7
7
  }
8
8
  session.addView('MsaView', {
@@ -23,9 +23,8 @@ export default function LaunchMsaViewExtensionPointF(pluginManager) {
23
23
  msaData: data?.msa,
24
24
  treeData: data?.tree,
25
25
  msaUrl: msaFileLocation?.uri,
26
- msaTabixLocation,
27
- msaIndexLocation,
28
- msaId,
26
+ msaIndexedLocation,
27
+ msaName,
29
28
  treeUrl: treeFileLocation?.uri,
30
29
  querySeqName,
31
30
  },
@@ -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';
@@ -122,7 +122,7 @@ export function processInit(self) {
122
122
  void (async () => {
123
123
  try {
124
124
  self.setError(undefined);
125
- const { msaData, msaUrl, msaTabixLocation, msaIndexLocation, msaId, treeData, treeUrl, querySeqName, } = init;
125
+ const { msaData, msaUrl, msaIndexedLocation, msaName, treeData, treeUrl, querySeqName, } = init;
126
126
  if (msaUrl) {
127
127
  const id = getUniprotIdFromAlphaFoldUrl(msaUrl);
128
128
  if (id) {
@@ -144,23 +144,16 @@ export function processInit(self) {
144
144
  const data = await response.text();
145
145
  self.setMSA(data);
146
146
  }
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
- }
147
+ else if (msaIndexedLocation && msaName) {
148
+ const fasta = await fetchIndexedMsa({
149
+ location: msaIndexedLocation,
150
+ name: msaName,
151
+ });
152
+ if (fasta) {
153
+ self.setMSA(fasta);
154
+ }
155
+ else {
156
+ throw new Error(`No alignment named ${msaName} in ${msaIndexedLocation.uri}`);
164
157
  }
165
158
  }
166
159
  if (treeData) {
@@ -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;