jbrowse-plugin-msaview 2.7.3 → 2.7.4
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.
- package/dist/LaunchMsaView/components/LaunchMsaViewDialog.js +7 -1
- package/dist/LaunchMsaView/components/OrthologQuery/OrthologPanel.d.ts +8 -0
- package/dist/LaunchMsaView/components/OrthologQuery/OrthologPanel.js +86 -0
- package/dist/LaunchMsaView/components/OrthologQuery/orthologLaunchView.d.ts +9 -0
- package/dist/LaunchMsaView/components/OrthologQuery/orthologLaunchView.js +13 -0
- package/dist/MsaViewPanel/afterCreateAutoruns.d.ts +8 -0
- package/dist/MsaViewPanel/afterCreateAutoruns.js +28 -0
- package/dist/MsaViewPanel/doLaunchOrthologs.d.ts +23 -0
- package/dist/MsaViewPanel/doLaunchOrthologs.js +97 -0
- package/dist/MsaViewPanel/model.d.ts +21 -5
- package/dist/MsaViewPanel/model.js +12 -1
- package/dist/jbrowse-plugin-msaview.umd.production.min.js +31 -27
- package/dist/jbrowse-plugin-msaview.umd.production.min.js.map +4 -4
- package/dist/utils/ncbiOrthologs.d.ts +105 -0
- package/dist/utils/ncbiOrthologs.js +211 -0
- package/dist/utils/ncbiOrthologs.test.d.ts +1 -0
- package/dist/utils/ncbiOrthologs.test.js +41 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/src/LaunchMsaView/components/LaunchMsaViewDialog.tsx +13 -2
- package/src/LaunchMsaView/components/OrthologQuery/OrthologPanel.tsx +172 -0
- package/src/LaunchMsaView/components/OrthologQuery/orthologLaunchView.ts +28 -0
- package/src/MsaViewPanel/afterCreateAutoruns.ts +27 -0
- package/src/MsaViewPanel/doLaunchOrthologs.ts +123 -0
- package/src/MsaViewPanel/model.ts +24 -0
- package/src/utils/ncbiOrthologs.test.ts +56 -0
- package/src/utils/ncbiOrthologs.ts +320 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export declare const COMMON_SPECIES: readonly [{
|
|
2
|
+
readonly label: "Human";
|
|
3
|
+
readonly taxId: 9606;
|
|
4
|
+
}, {
|
|
5
|
+
readonly label: "Mouse";
|
|
6
|
+
readonly taxId: 10090;
|
|
7
|
+
}, {
|
|
8
|
+
readonly label: "Rat";
|
|
9
|
+
readonly taxId: 10116;
|
|
10
|
+
}, {
|
|
11
|
+
readonly label: "Cow";
|
|
12
|
+
readonly taxId: 9913;
|
|
13
|
+
}, {
|
|
14
|
+
readonly label: "Pig";
|
|
15
|
+
readonly taxId: 9823;
|
|
16
|
+
}, {
|
|
17
|
+
readonly label: "Dog";
|
|
18
|
+
readonly taxId: 9615;
|
|
19
|
+
}, {
|
|
20
|
+
readonly label: "Chicken";
|
|
21
|
+
readonly taxId: 9031;
|
|
22
|
+
}, {
|
|
23
|
+
readonly label: "Frog";
|
|
24
|
+
readonly taxId: 8364;
|
|
25
|
+
}, {
|
|
26
|
+
readonly label: "Zebrafish";
|
|
27
|
+
readonly taxId: 7955;
|
|
28
|
+
}, {
|
|
29
|
+
readonly label: "Fruitfly";
|
|
30
|
+
readonly taxId: 7227;
|
|
31
|
+
}, {
|
|
32
|
+
readonly label: "C. elegans";
|
|
33
|
+
readonly taxId: 6239;
|
|
34
|
+
}, {
|
|
35
|
+
readonly label: "Yeast";
|
|
36
|
+
readonly taxId: 4932;
|
|
37
|
+
}, {
|
|
38
|
+
readonly label: "Arabidopsis";
|
|
39
|
+
readonly taxId: 3702;
|
|
40
|
+
}];
|
|
41
|
+
export declare const COMMON_TAX_RANK: Map<number, number>;
|
|
42
|
+
export interface OrthologRow {
|
|
43
|
+
taxId: number;
|
|
44
|
+
/** single-token id used identically in the FASTA, the tree and the domain GFF */
|
|
45
|
+
label: string;
|
|
46
|
+
scientificName: string;
|
|
47
|
+
commonName?: string;
|
|
48
|
+
geneId: string;
|
|
49
|
+
/** accession.version */
|
|
50
|
+
protein: string;
|
|
51
|
+
sequence: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A free-text gene reference -> NCBI gene id. A bare number is taken as the id
|
|
55
|
+
* itself; anything else is searched as a gene name within the query taxon.
|
|
56
|
+
* Several candidate identifiers are tried in order, because a JBrowse feature
|
|
57
|
+
* carries whatever its GFF/BigBed had — `id()`, `name`, `gene_name` — and only
|
|
58
|
+
* some of those are real symbols.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveGeneId(candidates: string[], taxId: number): Promise<{
|
|
61
|
+
geneId: string;
|
|
62
|
+
matched: string;
|
|
63
|
+
} | undefined>;
|
|
64
|
+
/** One ortholog gene per species, restricted to the requested taxa. */
|
|
65
|
+
export declare function fetchOrthologGenes(geneId: string, taxa: Set<number>): Promise<{
|
|
66
|
+
taxId: number;
|
|
67
|
+
geneId: string;
|
|
68
|
+
scientificName: string;
|
|
69
|
+
commonName?: string;
|
|
70
|
+
}[]>;
|
|
71
|
+
/**
|
|
72
|
+
* geneId -> representative protein accession: MANE Select where flagged, else
|
|
73
|
+
* the longest isoform. A stable, comparable choice across species — picking
|
|
74
|
+
* "the first" would silently vary with NCBI's ordering.
|
|
75
|
+
*/
|
|
76
|
+
export declare function fetchRepresentativeProteins(geneIds: string[]): Promise<Map<string, string>>;
|
|
77
|
+
/** accession (first header token) -> ungapped sequence, from a multi-FASTA. */
|
|
78
|
+
export declare function parseFasta(text: string): Map<string, string>;
|
|
79
|
+
/**
|
|
80
|
+
* Sanitized, unique single-token labels used identically in the FASTA headers,
|
|
81
|
+
* the tree leaf names and the domain GFF seq_ids — that identity is how the
|
|
82
|
+
* viewer pairs a tree leaf to its alignment row to its domain track. Collisions
|
|
83
|
+
* get a numeric suffix rather than silently overwriting a row.
|
|
84
|
+
*/
|
|
85
|
+
export declare function dedupeLabels(names: string[]): string[];
|
|
86
|
+
/**
|
|
87
|
+
* The representative protein for a single gene, with its sequence. Used to
|
|
88
|
+
* decide whether the user's own translated transcript is byte-identical to the
|
|
89
|
+
* RefSeq protein — if it is, that accession's precomputed CDD domains apply to
|
|
90
|
+
* the query row exactly, and if it isn't, they would land at an offset.
|
|
91
|
+
*/
|
|
92
|
+
export declare function fetchProteinForGene(geneId: string): Promise<{
|
|
93
|
+
accession: string;
|
|
94
|
+
sequence: string;
|
|
95
|
+
} | undefined>;
|
|
96
|
+
/**
|
|
97
|
+
* The whole NCBI half of the pipeline: gene -> ortholog rows carrying labels,
|
|
98
|
+
* accessions and sequences. Everything here is a precomputed lookup, so this
|
|
99
|
+
* returns in seconds rather than the 10+ minutes a BLAST submission costs.
|
|
100
|
+
*/
|
|
101
|
+
export declare function fetchOrthologRows({ geneId, taxa, onProgress, }: {
|
|
102
|
+
geneId: string;
|
|
103
|
+
taxa: Set<number>;
|
|
104
|
+
onProgress: (arg: string) => void;
|
|
105
|
+
}): Promise<OrthologRow[]>;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Homolog discovery WITHOUT a search job.
|
|
2
|
+
//
|
|
3
|
+
// The BLAST path answers "what looks like this sequence", which is not the
|
|
4
|
+
// question an MSA row set wants — it wants "what is homologous to this gene,
|
|
5
|
+
// one per species, labelled by species". BLAST then costs 10+ minutes to
|
|
6
|
+
// return a redundant, accession-labelled hit list that has to be deduplicated
|
|
7
|
+
// before it reads. NCBI has already computed the answer: the Datasets
|
|
8
|
+
// orthologs endpoint returns one ortholog gene per species, instantly.
|
|
9
|
+
//
|
|
10
|
+
// gene symbol -> gene id -> orthologs -> a representative protein each ->
|
|
11
|
+
// sequences, all from NCBI, in a handful of requests. The caller aligns them
|
|
12
|
+
// (EBI Clustal Omega, ~10s) and overlays CDD domains, which are already baked
|
|
13
|
+
// into the GenPept records (see ncbiDomains.ts).
|
|
14
|
+
//
|
|
15
|
+
// Mirrors jb2hubs' website/src/components/proteinMsa.ts assembler, trimmed to
|
|
16
|
+
// what the launch dialog needs and using this plugin's fetch/eutils helpers.
|
|
17
|
+
import { NCBI_EMAIL, NCBI_TOOL } from './eutils';
|
|
18
|
+
import { jsonfetch, textfetch } from './fetch';
|
|
19
|
+
// v2, not v2alpha: the alpha path still answers /orthologs but 404s
|
|
20
|
+
// /product_report, so an assembler pointed at it silently resolves zero
|
|
21
|
+
// representative proteins and reports "no orthologs" for every gene.
|
|
22
|
+
const DATASETS = 'https://api.ncbi.nlm.nih.gov/datasets/v2';
|
|
23
|
+
const EUTILS = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils';
|
|
24
|
+
// The species panel offered in the launch dialog, ordered from the reference
|
|
25
|
+
// outward so a run that finds only close relatives still reads as a ladder.
|
|
26
|
+
// Orthologs absent for a given gene are skipped rather than erroring.
|
|
27
|
+
export const COMMON_SPECIES = [
|
|
28
|
+
{ label: 'Human', taxId: 9606 },
|
|
29
|
+
{ label: 'Mouse', taxId: 10090 },
|
|
30
|
+
{ label: 'Rat', taxId: 10116 },
|
|
31
|
+
{ label: 'Cow', taxId: 9913 },
|
|
32
|
+
{ label: 'Pig', taxId: 9823 },
|
|
33
|
+
{ label: 'Dog', taxId: 9615 },
|
|
34
|
+
{ label: 'Chicken', taxId: 9031 },
|
|
35
|
+
{ label: 'Frog', taxId: 8364 },
|
|
36
|
+
{ label: 'Zebrafish', taxId: 7955 },
|
|
37
|
+
{ label: 'Fruitfly', taxId: 7227 },
|
|
38
|
+
{ label: 'C. elegans', taxId: 6239 },
|
|
39
|
+
{ label: 'Yeast', taxId: 4932 },
|
|
40
|
+
{ label: 'Arabidopsis', taxId: 3702 },
|
|
41
|
+
];
|
|
42
|
+
export const COMMON_TAX_RANK = new Map(COMMON_SPECIES.map((s, i) => [s.taxId, i]));
|
|
43
|
+
function ncbiUrl(url) {
|
|
44
|
+
const sep = url.includes('?') ? '&' : '?';
|
|
45
|
+
return `${url}${sep}tool=${NCBI_TOOL}&email=${encodeURIComponent(NCBI_EMAIL)}`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A free-text gene reference -> NCBI gene id. A bare number is taken as the id
|
|
49
|
+
* itself; anything else is searched as a gene name within the query taxon.
|
|
50
|
+
* Several candidate identifiers are tried in order, because a JBrowse feature
|
|
51
|
+
* carries whatever its GFF/BigBed had — `id()`, `name`, `gene_name` — and only
|
|
52
|
+
* some of those are real symbols.
|
|
53
|
+
*/
|
|
54
|
+
export async function resolveGeneId(candidates, taxId) {
|
|
55
|
+
for (const raw of candidates) {
|
|
56
|
+
const query = raw.trim();
|
|
57
|
+
if (!query) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (/^\d+$/.test(query)) {
|
|
61
|
+
return { geneId: query, matched: query };
|
|
62
|
+
}
|
|
63
|
+
// strip a version suffix (NM_000546.6) and any GFF ID prefix (gene:TP53)
|
|
64
|
+
const cleaned = query.replace(/^\w+:/, '').replace(/\.\d+$/, '');
|
|
65
|
+
const term = `${cleaned}[Gene Name] AND ${taxId}[taxid]`;
|
|
66
|
+
const json = await jsonfetch(ncbiUrl(`${EUTILS}/esearch.fcgi?db=gene&term=${encodeURIComponent(term)}&retmode=json&retmax=1`));
|
|
67
|
+
const geneId = json.esearchresult?.idlist?.[0];
|
|
68
|
+
if (geneId) {
|
|
69
|
+
return { geneId, matched: cleaned };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
/** One ortholog gene per species, restricted to the requested taxa. */
|
|
75
|
+
export async function fetchOrthologGenes(geneId, taxa) {
|
|
76
|
+
const json = await jsonfetch(ncbiUrl(`${DATASETS}/gene/id/${geneId}/orthologs?returned_content=COMPLETE`));
|
|
77
|
+
const byTaxon = new Map();
|
|
78
|
+
for (const { gene } of json.reports ?? []) {
|
|
79
|
+
const taxId = Number(gene?.tax_id);
|
|
80
|
+
if (gene?.gene_id && taxa.has(taxId) && !byTaxon.has(taxId)) {
|
|
81
|
+
byTaxon.set(taxId, {
|
|
82
|
+
taxId,
|
|
83
|
+
geneId: gene.gene_id,
|
|
84
|
+
scientificName: gene.taxname ?? String(taxId),
|
|
85
|
+
commonName: gene.common_name,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return [...byTaxon.values()].sort((a, b) => (COMMON_TAX_RANK.get(a.taxId) ?? Infinity) -
|
|
90
|
+
(COMMON_TAX_RANK.get(b.taxId) ?? Infinity));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* geneId -> representative protein accession: MANE Select where flagged, else
|
|
94
|
+
* the longest isoform. A stable, comparable choice across species — picking
|
|
95
|
+
* "the first" would silently vary with NCBI's ordering.
|
|
96
|
+
*/
|
|
97
|
+
export async function fetchRepresentativeProteins(geneIds) {
|
|
98
|
+
const byGene = new Map();
|
|
99
|
+
if (geneIds.length > 0) {
|
|
100
|
+
const json = await jsonfetch(ncbiUrl(`${DATASETS}/gene/id/${geneIds.join(',')}/product_report`));
|
|
101
|
+
for (const { product } of json.reports ?? []) {
|
|
102
|
+
const candidates = (product?.transcripts ?? [])
|
|
103
|
+
.map(t => ({
|
|
104
|
+
acc: t.protein?.accession_version,
|
|
105
|
+
len: t.protein?.length ?? 0,
|
|
106
|
+
mane: /select/i.test(t.select_category ?? ''),
|
|
107
|
+
}))
|
|
108
|
+
.filter((c) => !!c.acc);
|
|
109
|
+
const best = candidates.find(c => c.mane) ??
|
|
110
|
+
[...candidates].sort((a, b) => b.len - a.len).at(0);
|
|
111
|
+
if (product?.gene_id && best) {
|
|
112
|
+
byGene.set(product.gene_id, best.acc);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return byGene;
|
|
117
|
+
}
|
|
118
|
+
/** accession (first header token) -> ungapped sequence, from a multi-FASTA. */
|
|
119
|
+
export function parseFasta(text) {
|
|
120
|
+
const map = new Map();
|
|
121
|
+
let acc;
|
|
122
|
+
let buf = [];
|
|
123
|
+
for (const line of text.split('\n')) {
|
|
124
|
+
if (line.startsWith('>')) {
|
|
125
|
+
if (acc) {
|
|
126
|
+
map.set(acc, buf.join(''));
|
|
127
|
+
}
|
|
128
|
+
acc = line.slice(1).split(/\s+/)[0];
|
|
129
|
+
buf = [];
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
buf.push(line.trim());
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (acc) {
|
|
136
|
+
map.set(acc, buf.join(''));
|
|
137
|
+
}
|
|
138
|
+
return map;
|
|
139
|
+
}
|
|
140
|
+
function sanitize(name) {
|
|
141
|
+
return name.replace(/[^A-Za-z0-9]+/g, '_').replace(/^_+|_+$/g, '');
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Sanitized, unique single-token labels used identically in the FASTA headers,
|
|
145
|
+
* the tree leaf names and the domain GFF seq_ids — that identity is how the
|
|
146
|
+
* viewer pairs a tree leaf to its alignment row to its domain track. Collisions
|
|
147
|
+
* get a numeric suffix rather than silently overwriting a row.
|
|
148
|
+
*/
|
|
149
|
+
export function dedupeLabels(names) {
|
|
150
|
+
const seen = new Map();
|
|
151
|
+
return names.map(name => {
|
|
152
|
+
const base = sanitize(name) || 'row';
|
|
153
|
+
const n = seen.get(base) ?? 0;
|
|
154
|
+
seen.set(base, n + 1);
|
|
155
|
+
return n === 0 ? base : `${base}_${n + 1}`;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The representative protein for a single gene, with its sequence. Used to
|
|
160
|
+
* decide whether the user's own translated transcript is byte-identical to the
|
|
161
|
+
* RefSeq protein — if it is, that accession's precomputed CDD domains apply to
|
|
162
|
+
* the query row exactly, and if it isn't, they would land at an offset.
|
|
163
|
+
*/
|
|
164
|
+
export async function fetchProteinForGene(geneId) {
|
|
165
|
+
const acc = (await fetchRepresentativeProteins([geneId])).get(geneId);
|
|
166
|
+
if (!acc) {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
const seq = parseFasta(await textfetch(ncbiUrl(`${EUTILS}/efetch.fcgi?db=protein&id=${acc}&rettype=fasta&retmode=text`))).get(acc);
|
|
170
|
+
return seq ? { accession: acc, sequence: seq } : undefined;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The whole NCBI half of the pipeline: gene -> ortholog rows carrying labels,
|
|
174
|
+
* accessions and sequences. Everything here is a precomputed lookup, so this
|
|
175
|
+
* returns in seconds rather than the 10+ minutes a BLAST submission costs.
|
|
176
|
+
*/
|
|
177
|
+
export async function fetchOrthologRows({ geneId, taxa, onProgress, }) {
|
|
178
|
+
onProgress('Finding orthologs across species...');
|
|
179
|
+
const genes = await fetchOrthologGenes(geneId, taxa);
|
|
180
|
+
if (genes.length < 2) {
|
|
181
|
+
throw new Error(`Only ${genes.length} ortholog(s) found among the selected species — not enough to align`);
|
|
182
|
+
}
|
|
183
|
+
onProgress('Selecting a representative protein per species...');
|
|
184
|
+
const proteinByGene = await fetchRepresentativeProteins(genes.map(g => g.geneId));
|
|
185
|
+
const withProtein = genes.filter(g => proteinByGene.has(g.geneId));
|
|
186
|
+
if (withProtein.length < 2) {
|
|
187
|
+
throw new Error('Could not resolve representative proteins for the orthologs');
|
|
188
|
+
}
|
|
189
|
+
onProgress(`Fetching ${withProtein.length} protein sequences...`);
|
|
190
|
+
const accessions = withProtein.map(g => proteinByGene.get(g.geneId));
|
|
191
|
+
const seqByAcc = parseFasta(await textfetch(ncbiUrl(`${EUTILS}/efetch.fcgi?db=protein&id=${accessions.join(',')}&rettype=fasta&retmode=text`)));
|
|
192
|
+
const labels = dedupeLabels(withProtein.map(g => g.commonName ?? g.scientificName));
|
|
193
|
+
const rows = withProtein
|
|
194
|
+
.map((g, i) => {
|
|
195
|
+
const protein = proteinByGene.get(g.geneId);
|
|
196
|
+
return {
|
|
197
|
+
taxId: g.taxId,
|
|
198
|
+
label: labels[i],
|
|
199
|
+
scientificName: g.scientificName,
|
|
200
|
+
commonName: g.commonName,
|
|
201
|
+
geneId: g.geneId,
|
|
202
|
+
protein,
|
|
203
|
+
sequence: seqByAcc.get(protein) ?? '',
|
|
204
|
+
};
|
|
205
|
+
})
|
|
206
|
+
.filter(r => r.sequence);
|
|
207
|
+
if (rows.length < 2) {
|
|
208
|
+
throw new Error('Could not fetch protein sequences for the orthologs');
|
|
209
|
+
}
|
|
210
|
+
return rows;
|
|
211
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { dedupeLabels, parseFasta } from './ncbiOrthologs';
|
|
3
|
+
describe('dedupeLabels', () => {
|
|
4
|
+
test('sanitizes to single tokens', () => {
|
|
5
|
+
// labels are used identically as FASTA headers, Newick leaf names and GFF
|
|
6
|
+
// seq_ids, so anything that would need quoting in one of those is stripped
|
|
7
|
+
expect(dedupeLabels(['house mouse', 'Norway rat'])).toEqual([
|
|
8
|
+
'house_mouse',
|
|
9
|
+
'Norway_rat',
|
|
10
|
+
]);
|
|
11
|
+
expect(dedupeLabels(['Frog (X. tropicalis)'])).toEqual([
|
|
12
|
+
'Frog_X_tropicalis',
|
|
13
|
+
]);
|
|
14
|
+
});
|
|
15
|
+
test('suffixes collisions rather than overwriting a row', () => {
|
|
16
|
+
expect(dedupeLabels(['a b', 'a-b', 'a_b'])).toEqual([
|
|
17
|
+
'a_b',
|
|
18
|
+
'a_b_2',
|
|
19
|
+
'a_b_3',
|
|
20
|
+
]);
|
|
21
|
+
});
|
|
22
|
+
test('falls back for a name with no usable characters', () => {
|
|
23
|
+
expect(dedupeLabels(['...', '...'])).toEqual(['row', 'row_2']);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe('parseFasta', () => {
|
|
27
|
+
test('keys by the first header token and joins wrapped lines', () => {
|
|
28
|
+
const map = parseFasta(['>NP_000537.3 cellular tumor antigen p53', 'MEEP', 'QSDP', ''].join('\n'));
|
|
29
|
+
expect(map.get('NP_000537.3')).toBe('MEEPQSDP');
|
|
30
|
+
});
|
|
31
|
+
test('reads every record of a multi-FASTA', () => {
|
|
32
|
+
const map = parseFasta(['>A one', 'MMM', '>B two', 'KKK', '>C three', 'LLL'].join('\n'));
|
|
33
|
+
expect([...map.keys()]).toEqual(['A', 'B', 'C']);
|
|
34
|
+
expect(map.get('C')).toBe('LLL');
|
|
35
|
+
});
|
|
36
|
+
test('returns nothing for a response that carried no records', () => {
|
|
37
|
+
// efetch answers an unknown accession with an error body, not a 4xx, so a
|
|
38
|
+
// caller that assumed "text back = sequences" would build empty rows
|
|
39
|
+
expect(parseFasta('Error: CEFetchPApplication::proxy_stream()').size).toBe(0);
|
|
40
|
+
});
|
|
41
|
+
});
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.7.
|
|
1
|
+
export declare const version = "2.7.4";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.7.
|
|
1
|
+
export const version = '2.7.4';
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.7.
|
|
2
|
+
"version": "2.7.4",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "jbrowse-plugin-msaview",
|
|
5
5
|
"repository": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"eslint-plugin-unicorn": "^72.0.0",
|
|
44
44
|
"mobx": "^6.16.1",
|
|
45
45
|
"mobx-react": "^9.2.2",
|
|
46
|
-
"msa-parsers": "^5.
|
|
46
|
+
"msa-parsers": "^5.7.1",
|
|
47
47
|
"pixelmatch": "^7.2.0",
|
|
48
48
|
"pngjs": "^7.0.0",
|
|
49
49
|
"prettier": "^3.9.6",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"puppeteer": "^25.3.0",
|
|
52
52
|
"react": "^19.2.8",
|
|
53
53
|
"react-dom": "^19.2.8",
|
|
54
|
-
"react-msaview": "^5.7.
|
|
54
|
+
"react-msaview": "^5.7.1",
|
|
55
55
|
"rimraf": "^6.1.3",
|
|
56
56
|
"rxjs": "^7.8.2",
|
|
57
57
|
"serve": "^14.2.6",
|
|
@@ -6,6 +6,7 @@ import { Tab, Tabs } from '@mui/material'
|
|
|
6
6
|
|
|
7
7
|
import ManualMSALoader from './ManualMSALoader/ManualMSALoader'
|
|
8
8
|
import NCBIBlastPanel from './NCBIBlastQuery/NCBIBlastPanel'
|
|
9
|
+
import OrthologPanel from './OrthologQuery/OrthologPanel'
|
|
9
10
|
import PreLoadedMSA from './PreLoadedMSA/PreLoadedMSADataPanel'
|
|
10
11
|
import { readMsaDatasets } from './PreLoadedMSA/types'
|
|
11
12
|
import TabPanel from './TabPanel'
|
|
@@ -25,9 +26,11 @@ export default function LaunchMsaViewDialog({
|
|
|
25
26
|
const datasets = readMsaDatasets(session.jbrowse)
|
|
26
27
|
const hasPreloadedDatasets = !!datasets?.length
|
|
27
28
|
|
|
29
|
+
// orthologs first, and the default: it answers the same question in ~10s
|
|
30
|
+
// that BLAST takes 10+ minutes to answer worse (see utils/ncbiOrthologs.ts)
|
|
28
31
|
const [value, setValue] = useState<
|
|
29
|
-
'ncbi_blast' | 'preloaded_msa' | 'manual_msa'
|
|
30
|
-
>('
|
|
32
|
+
'orthologs' | 'ncbi_blast' | 'preloaded_msa' | 'manual_msa'
|
|
33
|
+
>('orthologs')
|
|
31
34
|
|
|
32
35
|
return (
|
|
33
36
|
<Dialog maxWidth="xl" title="Launch MSA view" open onClose={handleClose}>
|
|
@@ -37,12 +40,20 @@ export default function LaunchMsaViewDialog({
|
|
|
37
40
|
setValue(newValue)
|
|
38
41
|
}}
|
|
39
42
|
>
|
|
43
|
+
<Tab label="Orthologs (fast)" value="orthologs" />
|
|
40
44
|
<Tab label="NCBI BLAST query" value="ncbi_blast" />
|
|
41
45
|
{hasPreloadedDatasets ? (
|
|
42
46
|
<Tab label="Pre-loaded MSA datasets" value="preloaded_msa" />
|
|
43
47
|
) : null}
|
|
44
48
|
<Tab label="Manual upload" value="manual_msa" />
|
|
45
49
|
</Tabs>
|
|
50
|
+
<TabPanel value={value} index="orthologs">
|
|
51
|
+
<OrthologPanel
|
|
52
|
+
handleClose={handleClose}
|
|
53
|
+
feature={feature}
|
|
54
|
+
model={model}
|
|
55
|
+
/>
|
|
56
|
+
</TabPanel>
|
|
46
57
|
<TabPanel value={value} index="ncbi_blast">
|
|
47
58
|
<NCBIBlastPanel
|
|
48
59
|
handleClose={handleClose}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { Checkbox, FormControlLabel, MenuItem, Typography } from '@mui/material'
|
|
4
|
+
import { observer } from 'mobx-react'
|
|
5
|
+
import { makeStyles } from 'tss-react/mui'
|
|
6
|
+
|
|
7
|
+
import { orthologLaunchView } from './orthologLaunchView'
|
|
8
|
+
import TextField2 from '../../../components/TextField2'
|
|
9
|
+
import { COMMON_SPECIES } from '../../../utils/ncbiOrthologs'
|
|
10
|
+
import {
|
|
11
|
+
getGeneDisplayName,
|
|
12
|
+
getGeneIdentifiers,
|
|
13
|
+
getLinearGenomeView,
|
|
14
|
+
getTranscriptDisplayName,
|
|
15
|
+
} from '../../util'
|
|
16
|
+
import LaunchPanelContent from '../LaunchPanelContent'
|
|
17
|
+
import MsaAlgorithmSelect from '../NCBIBlastQuery/MsaAlgorithmSelect'
|
|
18
|
+
import SubmitCancelActions from '../SubmitCancelActions'
|
|
19
|
+
import TranscriptSelector from '../TranscriptSelector'
|
|
20
|
+
import { useTranscriptSelection } from '../useTranscriptSelection'
|
|
21
|
+
|
|
22
|
+
import type { MsaAlgorithm } from '../NCBIBlastQuery/consts'
|
|
23
|
+
import type { AbstractTrackModel, Feature } from '@jbrowse/core/util'
|
|
24
|
+
|
|
25
|
+
const useStyles = makeStyles()({
|
|
26
|
+
selectField: {
|
|
27
|
+
width: 180,
|
|
28
|
+
},
|
|
29
|
+
speciesBox: {
|
|
30
|
+
display: 'flex',
|
|
31
|
+
flexWrap: 'wrap',
|
|
32
|
+
maxWidth: 560,
|
|
33
|
+
marginTop: 12,
|
|
34
|
+
},
|
|
35
|
+
species: {
|
|
36
|
+
width: 160,
|
|
37
|
+
},
|
|
38
|
+
infoText: {
|
|
39
|
+
marginTop: 20,
|
|
40
|
+
maxWidth: 620,
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const OrthologPanel = observer(function ({
|
|
45
|
+
handleClose,
|
|
46
|
+
feature,
|
|
47
|
+
model,
|
|
48
|
+
}: {
|
|
49
|
+
model: AbstractTrackModel
|
|
50
|
+
feature: Feature
|
|
51
|
+
handleClose: () => void
|
|
52
|
+
}) {
|
|
53
|
+
const { classes } = useStyles()
|
|
54
|
+
const view = getLinearGenomeView(model)
|
|
55
|
+
const [launchViewError, setLaunchViewError] = useState<unknown>()
|
|
56
|
+
const [taxId, setTaxId] = useState(9606)
|
|
57
|
+
const [msaAlgorithm, setMsaAlgorithm] = useState<MsaAlgorithm>('clustalo')
|
|
58
|
+
const [excluded, setExcluded] = useState<number[]>([])
|
|
59
|
+
|
|
60
|
+
const geneCandidates = useMemo(() => getGeneIdentifiers(feature), [feature])
|
|
61
|
+
const transcriptSelection = useTranscriptSelection({ feature, view })
|
|
62
|
+
const { selectedTranscript, proteinSequence } = transcriptSelection
|
|
63
|
+
const e = transcriptSelection.error ?? launchViewError
|
|
64
|
+
|
|
65
|
+
const taxa = COMMON_SPECIES.map(s => s.taxId).filter(
|
|
66
|
+
t => !excluded.includes(t),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<>
|
|
71
|
+
<LaunchPanelContent error={e}>
|
|
72
|
+
<Typography>
|
|
73
|
+
Builds the alignment from NCBI's precomputed orthologs — one gene
|
|
74
|
+
per species — instead of searching. There is no job to wait on: the
|
|
75
|
+
NCBI lookups take about a second, and only the multiple alignment at
|
|
76
|
+
EBI costs real time (~10s), against 10+ minutes for BLAST. Rows come
|
|
77
|
+
out labelled by species rather than by accession, and NCBI's CDD
|
|
78
|
+
domains are overlaid automatically.
|
|
79
|
+
</Typography>
|
|
80
|
+
|
|
81
|
+
<div>
|
|
82
|
+
<TextField2
|
|
83
|
+
variant="outlined"
|
|
84
|
+
label="Query species"
|
|
85
|
+
className={classes.selectField}
|
|
86
|
+
select
|
|
87
|
+
value={taxId}
|
|
88
|
+
onChange={event => {
|
|
89
|
+
setTaxId(Number(event.target.value))
|
|
90
|
+
}}
|
|
91
|
+
helperText="the species this gene is from"
|
|
92
|
+
>
|
|
93
|
+
{COMMON_SPECIES.map(s => (
|
|
94
|
+
<MenuItem value={s.taxId} key={s.taxId}>
|
|
95
|
+
{s.label}
|
|
96
|
+
</MenuItem>
|
|
97
|
+
))}
|
|
98
|
+
</TextField2>
|
|
99
|
+
|
|
100
|
+
<MsaAlgorithmSelect
|
|
101
|
+
className={classes.selectField}
|
|
102
|
+
value={msaAlgorithm}
|
|
103
|
+
onChange={setMsaAlgorithm}
|
|
104
|
+
/>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<Typography variant="subtitle2" style={{ marginTop: 12 }}>
|
|
108
|
+
Species to include (those without an ortholog are skipped)
|
|
109
|
+
</Typography>
|
|
110
|
+
<div className={classes.speciesBox}>
|
|
111
|
+
{COMMON_SPECIES.map(s => (
|
|
112
|
+
<FormControlLabel
|
|
113
|
+
className={classes.species}
|
|
114
|
+
key={s.taxId}
|
|
115
|
+
control={
|
|
116
|
+
<Checkbox
|
|
117
|
+
checked={!excluded.includes(s.taxId)}
|
|
118
|
+
onChange={event => {
|
|
119
|
+
setExcluded(
|
|
120
|
+
event.target.checked
|
|
121
|
+
? excluded.filter(t => t !== s.taxId)
|
|
122
|
+
: [...excluded, s.taxId],
|
|
123
|
+
)
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
}
|
|
127
|
+
label={s.label}
|
|
128
|
+
/>
|
|
129
|
+
))}
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
<TranscriptSelector feature={feature} {...transcriptSelection} />
|
|
133
|
+
|
|
134
|
+
<Typography className={classes.infoText} variant="body2">
|
|
135
|
+
The query row is the transcript selected above, not NCBI's
|
|
136
|
+
representative protein, so the alignment stays linked to the genome
|
|
137
|
+
view at codon resolution.
|
|
138
|
+
</Typography>
|
|
139
|
+
</LaunchPanelContent>
|
|
140
|
+
<SubmitCancelActions
|
|
141
|
+
submitDisabled={!proteinSequence || taxa.length < 2}
|
|
142
|
+
onSubmit={() => {
|
|
143
|
+
try {
|
|
144
|
+
if (selectedTranscript) {
|
|
145
|
+
setLaunchViewError(undefined)
|
|
146
|
+
orthologLaunchView({
|
|
147
|
+
feature: selectedTranscript,
|
|
148
|
+
view,
|
|
149
|
+
newViewTitle: `Orthologs - ${getGeneDisplayName(feature)} - ${getTranscriptDisplayName(selectedTranscript)}`,
|
|
150
|
+
orthologParams: {
|
|
151
|
+
taxId,
|
|
152
|
+
taxa,
|
|
153
|
+
geneCandidates,
|
|
154
|
+
msaAlgorithm,
|
|
155
|
+
selectedTranscript,
|
|
156
|
+
proteinSequence,
|
|
157
|
+
},
|
|
158
|
+
})
|
|
159
|
+
handleClose()
|
|
160
|
+
}
|
|
161
|
+
} catch (e) {
|
|
162
|
+
console.error(e)
|
|
163
|
+
setLaunchViewError(e)
|
|
164
|
+
}
|
|
165
|
+
}}
|
|
166
|
+
onCancel={handleClose}
|
|
167
|
+
/>
|
|
168
|
+
</>
|
|
169
|
+
)
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
export default OrthologPanel
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getSession } from '@jbrowse/core/util'
|
|
2
|
+
|
|
3
|
+
import type { OrthologParams } from '../../../MsaViewPanel/model'
|
|
4
|
+
import type { Feature } from '@jbrowse/core/util'
|
|
5
|
+
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
|
|
6
|
+
|
|
7
|
+
export function orthologLaunchView({
|
|
8
|
+
newViewTitle,
|
|
9
|
+
view,
|
|
10
|
+
feature,
|
|
11
|
+
orthologParams,
|
|
12
|
+
}: {
|
|
13
|
+
newViewTitle: string
|
|
14
|
+
view: LinearGenomeViewModel
|
|
15
|
+
feature: Feature
|
|
16
|
+
orthologParams: OrthologParams
|
|
17
|
+
}) {
|
|
18
|
+
getSession(view).addView('MsaView', {
|
|
19
|
+
type: 'MsaView',
|
|
20
|
+
displayName: newViewTitle,
|
|
21
|
+
connectedViewId: view.id,
|
|
22
|
+
connectedFeature: feature.toJSON(),
|
|
23
|
+
drawNodeBubbles: true,
|
|
24
|
+
colWidth: 10,
|
|
25
|
+
rowHeight: 12,
|
|
26
|
+
orthologParams,
|
|
27
|
+
})
|
|
28
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getSession } from '@jbrowse/core/util'
|
|
2
2
|
|
|
3
3
|
import { doLaunchBlast } from './doLaunchBlast'
|
|
4
|
+
import { doLaunchOrthologs } from './doLaunchOrthologs'
|
|
4
5
|
import { fetchIndexedMsa } from './fetchIndexedMsa'
|
|
5
6
|
import { genomeToMSA } from './genomeToMSA'
|
|
6
7
|
import { loadProteinDomains } from './loadProteinDomains'
|
|
@@ -78,6 +79,32 @@ export function storeDataToIndexedDB(self: JBrowsePluginMsaViewModel) {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Same shape as launchBlastIfNeeded, for the ortholog path: the params ARE the
|
|
84
|
+
* request, and clearing them on success is what marks it done. They are left in
|
|
85
|
+
* place on failure so the error stays attributable to a specific request; the
|
|
86
|
+
* autorun's only tracked read is orthologParams itself, so nothing refires
|
|
87
|
+
* until a new request replaces them.
|
|
88
|
+
*/
|
|
89
|
+
export function launchOrthologsIfNeeded(self: JBrowsePluginMsaViewModel) {
|
|
90
|
+
if (self.orthologParams) {
|
|
91
|
+
void (async () => {
|
|
92
|
+
try {
|
|
93
|
+
self.setProgress('Resolving orthologs')
|
|
94
|
+
self.setError(undefined)
|
|
95
|
+
const data = await doLaunchOrthologs({ self })
|
|
96
|
+
self.setData(data)
|
|
97
|
+
self.setOrthologParams(undefined)
|
|
98
|
+
} catch (e) {
|
|
99
|
+
self.setError(e)
|
|
100
|
+
console.error(e)
|
|
101
|
+
} finally {
|
|
102
|
+
self.setProgress('')
|
|
103
|
+
}
|
|
104
|
+
})()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
81
108
|
export function launchBlastIfNeeded(self: JBrowsePluginMsaViewModel) {
|
|
82
109
|
if (self.blastParams) {
|
|
83
110
|
void (async () => {
|