p2s_mapper 1.4.0 → 2.1.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.
- package/README.md +220 -39
- package/dist/alignmentQuality.d.ts +5 -5
- package/dist/alphaFoldModels.d.ts +4 -4
- package/dist/alphaFoldModels.js +4 -4
- package/dist/chooseMappedEntity.d.ts +11 -13
- package/dist/chooseMappedEntity.js +9 -12
- package/dist/chooseMappedEntity.js.map +1 -1
- package/dist/coordinates.d.ts +19 -19
- package/dist/coordinates.js.map +1 -1
- package/dist/dbIds.d.ts +1 -2
- package/dist/extractPerResidueConfidence.d.ts +1 -2
- package/dist/extractStructureSequences.d.ts +26 -34
- package/dist/extractStructureSequences.js +2 -2
- package/dist/extractStructureSequences.js.map +1 -1
- package/dist/fetchUtils.d.ts +7 -7
- package/dist/fetchUtils.js +26 -8
- package/dist/fetchUtils.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/isoformRanking.d.ts +4 -1
- package/dist/mappings.d.ts +9 -12
- package/dist/mappings.js +4 -5
- package/dist/mappings.js.map +1 -1
- package/dist/pairwiseAlignment.d.ts +5 -4
- package/dist/pairwiseAlignment.js +9 -7
- package/dist/pairwiseAlignment.js.map +1 -1
- package/dist/pdbEntry.d.ts +32 -0
- package/dist/pdbEntry.js +182 -0
- package/dist/pdbEntry.js.map +1 -0
- package/dist/pdbUniProtMapping.d.ts +14 -39
- package/dist/pdbUniProtMapping.js +22 -140
- package/dist/pdbUniProtMapping.js.map +1 -1
- package/dist/structureFormat.d.ts +11 -18
- package/dist/structureFormat.js +4 -6
- package/dist/structureFormat.js.map +1 -1
- package/dist/structureSources.d.ts +37 -13
- package/dist/structureSources.js +144 -57
- package/dist/structureSources.js.map +1 -1
- package/dist/structureUrls.d.ts +13 -16
- package/dist/structureUrls.js +25 -23
- package/dist/structureUrls.js.map +1 -1
- package/dist/types.d.ts +2 -5
- package/dist/types.js +2 -5
- package/dist/types.js.map +1 -1
- package/dist/uniProtSearch.js +3 -8
- package/dist/uniProtSearch.js.map +1 -1
- package/esm/alignmentQuality.d.ts +5 -5
- package/esm/alphaFoldModels.d.ts +4 -4
- package/esm/alphaFoldModels.js +4 -4
- package/esm/chooseMappedEntity.d.ts +11 -13
- package/esm/chooseMappedEntity.js +9 -12
- package/esm/chooseMappedEntity.js.map +1 -1
- package/esm/coordinates.d.ts +19 -19
- package/esm/coordinates.js.map +1 -1
- package/esm/dbIds.d.ts +1 -2
- package/esm/extractPerResidueConfidence.d.ts +1 -2
- package/esm/extractStructureSequences.d.ts +26 -34
- package/esm/extractStructureSequences.js +2 -2
- package/esm/extractStructureSequences.js.map +1 -1
- package/esm/fetchUtils.d.ts +7 -7
- package/esm/fetchUtils.js +26 -8
- package/esm/fetchUtils.js.map +1 -1
- package/esm/index.d.ts +1 -3
- package/esm/index.js +2 -4
- package/esm/index.js.map +1 -1
- package/esm/isoformRanking.d.ts +4 -1
- package/esm/mappings.d.ts +9 -12
- package/esm/mappings.js +4 -5
- package/esm/mappings.js.map +1 -1
- package/esm/pairwiseAlignment.d.ts +5 -4
- package/esm/pairwiseAlignment.js +7 -5
- package/esm/pairwiseAlignment.js.map +1 -1
- package/esm/pdbEntry.d.ts +32 -0
- package/esm/pdbEntry.js +174 -0
- package/esm/pdbEntry.js.map +1 -0
- package/esm/pdbUniProtMapping.d.ts +14 -39
- package/esm/pdbUniProtMapping.js +22 -137
- package/esm/pdbUniProtMapping.js.map +1 -1
- package/esm/structureFormat.d.ts +11 -18
- package/esm/structureFormat.js +4 -6
- package/esm/structureFormat.js.map +1 -1
- package/esm/structureSources.d.ts +37 -13
- package/esm/structureSources.js +139 -55
- package/esm/structureSources.js.map +1 -1
- package/esm/structureUrls.d.ts +13 -16
- package/esm/structureUrls.js +23 -23
- package/esm/structureUrls.js.map +1 -1
- package/esm/types.d.ts +2 -5
- package/esm/types.js +2 -5
- package/esm/types.js.map +1 -1
- package/esm/uniProtSearch.js +3 -8
- package/esm/uniProtSearch.js.map +1 -1
- package/package.json +3 -2
- package/src/alignmentQuality.ts +5 -5
- package/src/alphaFoldModels.ts +4 -4
- package/src/chooseMappedEntity.ts +12 -15
- package/src/coordinates.ts +14 -17
- package/src/dbIds.ts +1 -1
- package/src/extractPerResidueConfidence.ts +1 -1
- package/src/extractStructureSequences.ts +26 -33
- package/src/fetchUtils.ts +30 -8
- package/src/index.ts +2 -4
- package/src/isoformRanking.ts +4 -4
- package/src/mappings.ts +9 -12
- package/src/pairwiseAlignment.ts +12 -9
- package/src/pdbEntry.ts +240 -0
- package/src/pdbUniProtMapping.ts +25 -164
- package/src/structureFormat.ts +11 -18
- package/src/structureSources.ts +194 -70
- package/src/structureUrls.ts +25 -23
- package/src/types.ts +2 -5
- package/src/uniProtSearch.ts +3 -8
- package/dist/pdbeBestStructures.d.ts +0 -23
- package/dist/pdbeBestStructures.js +0 -79
- package/dist/pdbeBestStructures.js.map +0 -1
- package/dist/pdbeEntryMolecules.d.ts +0 -7
- package/dist/pdbeEntryMolecules.js +0 -39
- package/dist/pdbeEntryMolecules.js.map +0 -1
- package/dist/siftsNumbering.d.ts +0 -23
- package/dist/siftsNumbering.js +0 -44
- package/dist/siftsNumbering.js.map +0 -1
- package/esm/pdbeBestStructures.d.ts +0 -23
- package/esm/pdbeBestStructures.js +0 -73
- package/esm/pdbeBestStructures.js.map +0 -1
- package/esm/pdbeEntryMolecules.d.ts +0 -7
- package/esm/pdbeEntryMolecules.js +0 -35
- package/esm/pdbeEntryMolecules.js.map +0 -1
- package/esm/siftsNumbering.d.ts +0 -23
- package/esm/siftsNumbering.js +0 -40
- package/esm/siftsNumbering.js.map +0 -1
- package/src/pdbeBestStructures.ts +0 -94
- package/src/pdbeEntryMolecules.ts +0 -37
- package/src/siftsNumbering.ts +0 -61
package/dist/pdbEntry.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// What RCSB knows about one PDB entry that a mapping needs, in one GraphQL
|
|
3
|
+
// call: each polymer entity's sequence, its author chains, and its alignment
|
|
4
|
+
// to UniProt. The alignment is what SIFTS publishes per chain, numbered the
|
|
5
|
+
// same way (`entity_beg_seq_id` is label_seq_id, 1-based into the SEQRES),
|
|
6
|
+
// and agreed with PDBe's SIFTS on every residue of 23 entries checked
|
|
7
|
+
// (2026-10-11, 1TUP, 2RH1, 4HHB, 7K00 among them), in a tenth of the time.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.RCSB_DATA_GRAPHQL_URL = void 0;
|
|
10
|
+
exports.pdbEntryQuery = pdbEntryQuery;
|
|
11
|
+
exports.graphqlFetch = graphqlFetch;
|
|
12
|
+
exports.fetchPdbEntry = fetchPdbEntry;
|
|
13
|
+
exports.fetchUniProtStructureMappings = fetchUniProtStructureMappings;
|
|
14
|
+
exports.parsePdbEntry = parsePdbEntry;
|
|
15
|
+
const fetchUtils_ts_1 = require("./fetchUtils.js");
|
|
16
|
+
exports.RCSB_DATA_GRAPHQL_URL = 'https://data.rcsb.org/graphql';
|
|
17
|
+
function pdbEntryQuery(pdbId) {
|
|
18
|
+
return `{ entry(entry_id: "${pdbId.toUpperCase()}") { polymer_entities {
|
|
19
|
+
rcsb_id
|
|
20
|
+
entity_poly { type pdbx_seq_one_letter_code_can }
|
|
21
|
+
rcsb_polymer_entity_container_identifiers { auth_asym_ids }
|
|
22
|
+
rcsb_polymer_entity_align {
|
|
23
|
+
reference_database_name reference_database_accession
|
|
24
|
+
aligned_regions { entity_beg_seq_id ref_beg_seq_id length }
|
|
25
|
+
}
|
|
26
|
+
uniprots { rcsb_id rcsb_uniprot_entry_name }
|
|
27
|
+
} } }`;
|
|
28
|
+
}
|
|
29
|
+
const RETRY_DELAYS_MS = [1000, 3000];
|
|
30
|
+
// bounded, since a view reports itself loading until the entry answers
|
|
31
|
+
const TIMEOUT_MS = 20_000;
|
|
32
|
+
/**
|
|
33
|
+
* A GraphQL request. The server answers 200 whatever happened, so a failure
|
|
34
|
+
* is read from the body's `errors`, and counts as a 400: the server
|
|
35
|
+
* understood the query and declined it, so asking again gets the same answer.
|
|
36
|
+
*/
|
|
37
|
+
async function graphqlFetch(url, query, variables, opts) {
|
|
38
|
+
const json = await (0, fetchUtils_ts_1.jsonfetch)(url, {
|
|
39
|
+
...opts,
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: { 'Content-Type': 'application/json' },
|
|
42
|
+
body: JSON.stringify({ query, variables }),
|
|
43
|
+
});
|
|
44
|
+
const errors = isRecord(json) ? json.errors : undefined;
|
|
45
|
+
if (Array.isArray(errors) && errors.length > 0) {
|
|
46
|
+
const first = errors[0];
|
|
47
|
+
const message = isRecord(first) && typeof first.message === 'string'
|
|
48
|
+
? first.message
|
|
49
|
+
: 'unknown error';
|
|
50
|
+
throw new fetchUtils_ts_1.HttpError(`${new URL(url).host}: ${message}`, 400);
|
|
51
|
+
}
|
|
52
|
+
return isRecord(json) ? json.data : undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The entry, retried twice: one failed request would otherwise leave a fusion
|
|
56
|
+
* construct mapped onto its partner for the whole session. An id RCSB has no
|
|
57
|
+
* entry for is a 404, which is not retried, since that answer cannot change.
|
|
58
|
+
*/
|
|
59
|
+
async function fetchPdbEntry(pdbId, opts) {
|
|
60
|
+
const { signal: caller, ...rest } = opts ?? {};
|
|
61
|
+
const signal = caller ?? undefined;
|
|
62
|
+
const deadline = () => signal
|
|
63
|
+
? AbortSignal.any([signal, AbortSignal.timeout(TIMEOUT_MS)])
|
|
64
|
+
: AbortSignal.timeout(TIMEOUT_MS);
|
|
65
|
+
for (let attempt = 0;; attempt++) {
|
|
66
|
+
try {
|
|
67
|
+
const entry = parsePdbEntry(await graphqlFetch(exports.RCSB_DATA_GRAPHQL_URL, pdbEntryQuery(pdbId), undefined, { ...rest, signal: deadline() }));
|
|
68
|
+
if (!entry) {
|
|
69
|
+
throw new fetchUtils_ts_1.HttpError(`RCSB has no entry ${pdbId.toUpperCase()}`, 404);
|
|
70
|
+
}
|
|
71
|
+
return entry;
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
const delay = RETRY_DELAYS_MS[attempt];
|
|
75
|
+
// the caller's own abort is not a failure to retry either
|
|
76
|
+
if (delay === undefined || (0, fetchUtils_ts_1.isDefinitiveFailure)(e) || signal?.aborted) {
|
|
77
|
+
throw e;
|
|
78
|
+
}
|
|
79
|
+
await (0, fetchUtils_ts_1.timeout)(delay, signal);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** The entry's UniProt alignment alone. */
|
|
84
|
+
async function fetchUniProtStructureMappings(pdbId, opts) {
|
|
85
|
+
return (await fetchPdbEntry(pdbId, opts)).mappings;
|
|
86
|
+
}
|
|
87
|
+
function isRecord(value) {
|
|
88
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
89
|
+
}
|
|
90
|
+
function finiteNumber(value) {
|
|
91
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
92
|
+
}
|
|
93
|
+
function strings(value) {
|
|
94
|
+
return Array.isArray(value)
|
|
95
|
+
? value.filter((v) => typeof v === 'string')
|
|
96
|
+
: [];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Parses the `data` of `pdbEntryQuery`. Undefined when RCSB has no such
|
|
100
|
+
* entry; an entry nothing aligns to UniProt (DNA alone, say) parses to no
|
|
101
|
+
* mappings. An unparseable alignment is skipped rather than failing the
|
|
102
|
+
* entry, so a chimera with one malformed region still maps its other chains.
|
|
103
|
+
*/
|
|
104
|
+
function parsePdbEntry(data) {
|
|
105
|
+
const entry = isRecord(data) ? data.entry : undefined;
|
|
106
|
+
if (!isRecord(entry)) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
const entities = Array.isArray(entry.polymer_entities)
|
|
110
|
+
? entry.polymer_entities.filter(isRecord)
|
|
111
|
+
: [];
|
|
112
|
+
const byAccession = new Map();
|
|
113
|
+
const proteinSequences = [];
|
|
114
|
+
for (const entity of entities.toSorted((a, b) => entityNumber(a.rcsb_id) - entityNumber(b.rcsb_id))) {
|
|
115
|
+
const entityId = String(entityNumber(entity.rcsb_id));
|
|
116
|
+
const poly = isRecord(entity.entity_poly) ? entity.entity_poly : undefined;
|
|
117
|
+
const sequence = poly?.pdbx_seq_one_letter_code_can;
|
|
118
|
+
if (typeof poly?.type === 'string' &&
|
|
119
|
+
poly.type.startsWith('polypeptide') &&
|
|
120
|
+
typeof sequence === 'string' &&
|
|
121
|
+
sequence.length > 0) {
|
|
122
|
+
proteinSequences.push(sequence);
|
|
123
|
+
}
|
|
124
|
+
const ids = entity.rcsb_polymer_entity_container_identifiers;
|
|
125
|
+
const chains = strings(isRecord(ids) ? ids.auth_asym_ids : undefined);
|
|
126
|
+
const names = new Map((Array.isArray(entity.uniprots) ? entity.uniprots : [])
|
|
127
|
+
.filter(isRecord)
|
|
128
|
+
.map(u => [u.rcsb_id, strings(u.rcsb_uniprot_entry_name)[0]]));
|
|
129
|
+
for (const align of Array.isArray(entity.rcsb_polymer_entity_align)
|
|
130
|
+
? entity.rcsb_polymer_entity_align.filter(isRecord)
|
|
131
|
+
: []) {
|
|
132
|
+
const accession = align.reference_database_accession;
|
|
133
|
+
if (align.reference_database_name !== 'UniProt' ||
|
|
134
|
+
typeof accession !== 'string') {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const segments = (Array.isArray(align.aligned_regions) ? align.aligned_regions : []).flatMap(region => parseSegments(region, entityId, chains));
|
|
138
|
+
if (segments.length === 0) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const mapping = byAccession.get(accession) ?? {
|
|
142
|
+
accession,
|
|
143
|
+
name: names.get(accession),
|
|
144
|
+
segments: [],
|
|
145
|
+
};
|
|
146
|
+
mapping.segments.push(...segments);
|
|
147
|
+
byAccession.set(accession, mapping);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return { mappings: [...byAccession.values()], proteinSequences };
|
|
151
|
+
}
|
|
152
|
+
function entityNumber(rcsbId) {
|
|
153
|
+
return typeof rcsbId === 'string' ? Number(rcsbId.split('_')[1]) : NaN;
|
|
154
|
+
}
|
|
155
|
+
/** One segment per chain carrying the entity, so a PDB-format file, whose
|
|
156
|
+
* entities Mol* numbers per chain, still matches by chain. */
|
|
157
|
+
function parseSegments(region, entityId, chains) {
|
|
158
|
+
if (!isRecord(region)) {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
const entityBeg = finiteNumber(region.entity_beg_seq_id);
|
|
162
|
+
const refBeg = finiteNumber(region.ref_beg_seq_id);
|
|
163
|
+
const length = finiteNumber(region.length);
|
|
164
|
+
if (entityBeg === undefined ||
|
|
165
|
+
refBeg === undefined ||
|
|
166
|
+
length === undefined ||
|
|
167
|
+
length < 1) {
|
|
168
|
+
return [];
|
|
169
|
+
}
|
|
170
|
+
const segment = {
|
|
171
|
+
entityId,
|
|
172
|
+
unpStart: refBeg,
|
|
173
|
+
unpEnd: refBeg + length - 1,
|
|
174
|
+
// SEQRES/label_seq_id is 1-based, structure positions are 0-based
|
|
175
|
+
structStart: entityBeg - 1,
|
|
176
|
+
structEnd: entityBeg + length - 2,
|
|
177
|
+
};
|
|
178
|
+
return chains.length === 0
|
|
179
|
+
? [segment]
|
|
180
|
+
: chains.map(chainId => ({ ...segment, chainId }));
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=pdbEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdbEntry.js","sourceRoot":"","sources":["../src/pdbEntry.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,6EAA6E;AAC7E,4EAA4E;AAC5E,2EAA2E;AAC3E,sEAAsE;AACtE,2EAA2E;;;AAyB3E,sCAWC;AAWD,oCAsBC;AAOD,sCAiCC;AAGD,sEAKC;AAsBD,sCAyDC;AAlMD,mD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,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;AACxE,CAAC;AAED;8DAC8D;AAC9D,SAAS,aAAa,CACpB,MAAe,EACf,QAAgB,EAChB,MAAgB;IAEhB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,CAAA;IACX,CAAC;IACD,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAA;IACxD,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;IAClD,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC1C,IACE,SAAS,KAAK,SAAS;QACvB,MAAM,KAAK,SAAS;QACpB,MAAM,KAAK,SAAS;QACpB,MAAM,GAAG,CAAC,EACV,CAAC;QACD,OAAO,EAAE,CAAA;IACX,CAAC;IACD,MAAM,OAAO,GAAG;QACd,QAAQ;QACR,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC;QAC3B,kEAAkE;QAClE,WAAW,EAAE,SAAS,GAAG,CAAC;QAC1B,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,CAAC;KAClC,CAAA;IACD,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC;QACxB,CAAC,CAAC,CAAC,OAAO,CAAC;QACX,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAA;AACtD,CAAC"}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import type { FetchOptions } from './fetchUtils.ts';
|
|
2
1
|
/** One contiguous UniProt <-> structure correspondence for a single entity.
|
|
3
2
|
* `unp*` are 1-based UniProt positions; `struct*` are 0-based inclusive
|
|
4
|
-
* structure-sequence positions, this
|
|
3
|
+
* structure-sequence positions, this package's native coordinate. */
|
|
5
4
|
export interface UniProtStructureSegment {
|
|
6
5
|
entityId: string;
|
|
7
|
-
/** author chain id, when the
|
|
6
|
+
/** author chain id, when the source names it */
|
|
8
7
|
chainId?: string;
|
|
9
8
|
unpStart: number;
|
|
10
9
|
unpEnd: number;
|
|
11
10
|
structStart: number;
|
|
12
11
|
structEnd: number;
|
|
13
|
-
/** the endpoints' author residue numbers, the numbering a paper cites and a
|
|
14
|
-
* Mol* hover shows; absent when the response omits them */
|
|
15
|
-
authorStart?: number;
|
|
16
|
-
authorEnd?: number;
|
|
17
12
|
}
|
|
18
13
|
export interface UniProtStructureMapping {
|
|
19
14
|
accession: string;
|
|
@@ -27,46 +22,26 @@ export interface UniProtStructureMapping {
|
|
|
27
22
|
* the feature instead of drawing it somewhere misleading.
|
|
28
23
|
*/
|
|
29
24
|
export type MapUniProtPosition = (uniprotPos: number) => number | undefined;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* SIFTS for an entry, retried twice: one failed request would otherwise leave a
|
|
33
|
-
* fusion construct mapped onto its partner for the whole session.
|
|
34
|
-
*
|
|
35
|
-
* A 4xx is not retried. PDBe answers 404 for an entry it has no UniProt
|
|
36
|
-
* mapping for at all — a DNA-only or obsolete entry — and that answer cannot
|
|
37
|
-
* change, so the retries only postponed it: measured 2026-09-16, `1hhb` and
|
|
38
|
-
* `1bna` each took three requests and ~4.8s to say so, which a caller shows as
|
|
39
|
-
* four and a half seconds of "resolving" for a structure that will never
|
|
40
|
-
* resolve.
|
|
41
|
-
*/
|
|
42
|
-
export declare function fetchUniProtStructureMappings(pdbId: string, opts?: FetchOptions): Promise<UniProtStructureMapping[]>;
|
|
43
|
-
/**
|
|
44
|
-
* Parses a PDBe `mappings/uniprot/{pdbId}` response into one entry per UniProt
|
|
45
|
-
* accession. Unparseable segments are skipped rather than failing the whole
|
|
46
|
-
* response — a chimera with one malformed segment still maps its other chains.
|
|
47
|
-
* The response is keyed by pdb id, so the single entry is taken whatever its key.
|
|
48
|
-
*/
|
|
49
|
-
export declare function parseUniProtStructureMappings(json: unknown): UniProtStructureMapping[];
|
|
50
|
-
/** The entity a SIFTS segment is matched against: its mmCIF id and the author
|
|
25
|
+
/** The entity a segment is matched against: its mmCIF id and the author
|
|
51
26
|
* chains carrying it. */
|
|
52
27
|
export interface SegmentEntity {
|
|
53
28
|
entityId: string;
|
|
54
29
|
chains: readonly string[];
|
|
55
30
|
}
|
|
56
31
|
/**
|
|
57
|
-
* Picks the UniProt entry
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* contributing the most residues wins.
|
|
32
|
+
* Picks the UniProt entry for a given entity, with its segments narrowed to
|
|
33
|
+
* that entity. Pass the entity mapped to the transcript: a heteromer's chains
|
|
34
|
+
* align to different accessions, and the wrong one would annotate the wrong
|
|
35
|
+
* protein. When several accessions cover one entity (a chimeric construct), the
|
|
36
|
+
* one covering the most residues wins.
|
|
63
37
|
*/
|
|
64
38
|
export declare function chooseUniProtMappingForEntity(mappings: UniProtStructureMapping[], entity: SegmentEntity | undefined): UniProtStructureMapping | undefined;
|
|
65
39
|
/**
|
|
66
|
-
* Mapped structure positions
|
|
67
|
-
* transcript's, on a chain that fuses two. Local
|
|
68
|
-
* boundary, and on every GPCR fusion construct
|
|
69
|
-
* residues onto the partner, 33 of them onto T4
|
|
40
|
+
* Mapped structure positions the entry's UniProt alignment assigns to a
|
|
41
|
+
* protein other than the transcript's, on a chain that fuses two. Local
|
|
42
|
+
* alignment bridges a fusion boundary, and on every GPCR fusion construct
|
|
43
|
+
* checked it scattered receptor residues onto the partner, 33 of them onto T4
|
|
44
|
+
* lysozyme in 2RH1.
|
|
70
45
|
*
|
|
71
46
|
* `mapped` is each mapped structure position and whether its pair is
|
|
72
47
|
* identical. The transcript's own accession is the one whose covered positions
|
|
@@ -75,7 +50,7 @@ export declare function chooseUniProtMappingForEntity(mappings: UniProtStructure
|
|
|
75
50
|
* fused to CDK2 covers 11 positions against 224 chance hits on the kinase, and
|
|
76
51
|
* counting unmapped the peptide. Unless that accession reaches half identity
|
|
77
52
|
* the transcript is taken to be neither protein, and nothing is unmapped.
|
|
78
|
-
* Residues
|
|
53
|
+
* Residues assigned to no accession, such as tags, stay mapped.
|
|
79
54
|
*/
|
|
80
55
|
export declare function fusionPartnerPositions(mappings: UniProtStructureMapping[], entity: SegmentEntity | undefined, mapped: ReadonlyMap<number, boolean>): Set<number>;
|
|
81
56
|
/** 1-based UniProt position -> 0-based structure position, for an AlphaFold
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//
|
|
2
|
+
// UniProt <-> PDB residue mapping.
|
|
3
3
|
//
|
|
4
4
|
// UniProt feature coordinates are positions in the UniProt canonical sequence.
|
|
5
5
|
// For an AlphaFold model that *is* the structure's own sequence, so a feature at
|
|
@@ -7,142 +7,24 @@
|
|
|
7
7
|
// entry it is not: the deposited construct is usually a fragment, often with
|
|
8
8
|
// tags or engineered residues, so the two numberings differ by a per-segment
|
|
9
9
|
// offset (1TUP's p53 chain starts at UniProt 94; 6VXX's spike SEQRES 33 is
|
|
10
|
-
// UniProt 14).
|
|
11
|
-
//
|
|
10
|
+
// UniProt 14). The entry's own UniProt alignment, which `fetchPdbEntry` reads
|
|
11
|
+
// from RCSB, is the authority on that correspondence.
|
|
12
12
|
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
// position + 1 (see applyLociInteractivity.ts for the other place that boundary
|
|
16
|
-
// is crossed).
|
|
13
|
+
// Structure positions here index the entity's SEQRES from 0, i.e.
|
|
14
|
+
// label_seq_id - 1, which is this package's structure-sequence position.
|
|
17
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
16
|
exports.identityUniProtPositionMap = void 0;
|
|
19
|
-
exports.pdbeSiftsUrl = pdbeSiftsUrl;
|
|
20
|
-
exports.fetchUniProtStructureMappings = fetchUniProtStructureMappings;
|
|
21
|
-
exports.parseUniProtStructureMappings = parseUniProtStructureMappings;
|
|
22
17
|
exports.chooseUniProtMappingForEntity = chooseUniProtMappingForEntity;
|
|
23
18
|
exports.fusionPartnerPositions = fusionPartnerPositions;
|
|
24
19
|
exports.makeUniProtPositionMap = makeUniProtPositionMap;
|
|
25
|
-
const fetchUtils_ts_1 = require("./fetchUtils.js");
|
|
26
|
-
function pdbeSiftsUrl(pdbId) {
|
|
27
|
-
return `https://www.ebi.ac.uk/pdbe/api/mappings/uniprot/${pdbId.toLowerCase()}`;
|
|
28
|
-
}
|
|
29
|
-
const SIFTS_RETRY_DELAYS_MS = [1000, 3000];
|
|
30
|
-
// bounded, since a view reports itself loading until SIFTS answers
|
|
31
|
-
const SIFTS_TIMEOUT_MS = 20_000;
|
|
32
|
-
/**
|
|
33
|
-
* SIFTS for an entry, retried twice: one failed request would otherwise leave a
|
|
34
|
-
* fusion construct mapped onto its partner for the whole session.
|
|
35
|
-
*
|
|
36
|
-
* A 4xx is not retried. PDBe answers 404 for an entry it has no UniProt
|
|
37
|
-
* mapping for at all — a DNA-only or obsolete entry — and that answer cannot
|
|
38
|
-
* change, so the retries only postponed it: measured 2026-09-16, `1hhb` and
|
|
39
|
-
* `1bna` each took three requests and ~4.8s to say so, which a caller shows as
|
|
40
|
-
* four and a half seconds of "resolving" for a structure that will never
|
|
41
|
-
* resolve.
|
|
42
|
-
*/
|
|
43
|
-
async function fetchUniProtStructureMappings(pdbId, opts) {
|
|
44
|
-
const { signal: caller, ...rest } = opts ?? {};
|
|
45
|
-
const signal = caller ?? undefined;
|
|
46
|
-
const deadline = () => signal
|
|
47
|
-
? AbortSignal.any([signal, AbortSignal.timeout(SIFTS_TIMEOUT_MS)])
|
|
48
|
-
: AbortSignal.timeout(SIFTS_TIMEOUT_MS);
|
|
49
|
-
for (let attempt = 0;; attempt++) {
|
|
50
|
-
try {
|
|
51
|
-
return parseUniProtStructureMappings(await (0, fetchUtils_ts_1.jsonfetch)(pdbeSiftsUrl(pdbId), { ...rest, signal: deadline() }));
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
const delay = SIFTS_RETRY_DELAYS_MS[attempt];
|
|
55
|
-
// the caller's own abort is not a failure to retry either
|
|
56
|
-
if (delay === undefined || (0, fetchUtils_ts_1.isDefinitiveFailure)(e) || signal?.aborted) {
|
|
57
|
-
throw e;
|
|
58
|
-
}
|
|
59
|
-
await (0, fetchUtils_ts_1.timeout)(delay, signal);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function isRecord(value) {
|
|
64
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
65
|
-
}
|
|
66
|
-
function finiteNumber(value) {
|
|
67
|
-
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
68
|
-
}
|
|
69
|
-
function residueNumber(endpoint) {
|
|
70
|
-
return isRecord(endpoint) ? finiteNumber(endpoint.residue_number) : undefined;
|
|
71
|
-
}
|
|
72
|
-
function authorResidueNumber(endpoint) {
|
|
73
|
-
return isRecord(endpoint)
|
|
74
|
-
? finiteNumber(endpoint.author_residue_number)
|
|
75
|
-
: undefined;
|
|
76
|
-
}
|
|
77
|
-
function parseSegment(mapping) {
|
|
78
|
-
if (!isRecord(mapping)) {
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
const entityId = finiteNumber(mapping.entity_id);
|
|
82
|
-
const unpStart = finiteNumber(mapping.unp_start);
|
|
83
|
-
const unpEnd = finiteNumber(mapping.unp_end);
|
|
84
|
-
const structStart = residueNumber(mapping.start);
|
|
85
|
-
const structEnd = residueNumber(mapping.end);
|
|
86
|
-
const authorStart = authorResidueNumber(mapping.start);
|
|
87
|
-
const authorEnd = authorResidueNumber(mapping.end);
|
|
88
|
-
return entityId === undefined ||
|
|
89
|
-
unpStart === undefined ||
|
|
90
|
-
unpEnd === undefined ||
|
|
91
|
-
structStart === undefined ||
|
|
92
|
-
structEnd === undefined
|
|
93
|
-
? undefined
|
|
94
|
-
: {
|
|
95
|
-
entityId: String(entityId),
|
|
96
|
-
...(typeof mapping.chain_id === 'string'
|
|
97
|
-
? { chainId: mapping.chain_id }
|
|
98
|
-
: {}),
|
|
99
|
-
unpStart,
|
|
100
|
-
unpEnd,
|
|
101
|
-
// SEQRES/label_seq_id is 1-based, structure positions are 0-based
|
|
102
|
-
structStart: structStart - 1,
|
|
103
|
-
structEnd: structEnd - 1,
|
|
104
|
-
...(authorStart === undefined ? {} : { authorStart }),
|
|
105
|
-
...(authorEnd === undefined ? {} : { authorEnd }),
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Parses a PDBe `mappings/uniprot/{pdbId}` response into one entry per UniProt
|
|
110
|
-
* accession. Unparseable segments are skipped rather than failing the whole
|
|
111
|
-
* response — a chimera with one malformed segment still maps its other chains.
|
|
112
|
-
* The response is keyed by pdb id, so the single entry is taken whatever its key.
|
|
113
|
-
*/
|
|
114
|
-
function parseUniProtStructureMappings(json) {
|
|
115
|
-
const entry = isRecord(json) ? Object.values(json)[0] : undefined;
|
|
116
|
-
const uniprot = isRecord(entry) ? entry.UniProt : undefined;
|
|
117
|
-
if (!isRecord(uniprot)) {
|
|
118
|
-
return [];
|
|
119
|
-
}
|
|
120
|
-
const result = [];
|
|
121
|
-
for (const [accession, value] of Object.entries(uniprot)) {
|
|
122
|
-
const mappings = isRecord(value) ? value.mappings : undefined;
|
|
123
|
-
const segments = Array.isArray(mappings)
|
|
124
|
-
? mappings.map(parseSegment).filter(s => s !== undefined)
|
|
125
|
-
: [];
|
|
126
|
-
if (segments.length > 0) {
|
|
127
|
-
result.push({
|
|
128
|
-
accession,
|
|
129
|
-
name: isRecord(value) && typeof value.name === 'string'
|
|
130
|
-
? value.name
|
|
131
|
-
: undefined,
|
|
132
|
-
segments,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
20
|
function coveredResidues(segments) {
|
|
139
21
|
return segments.reduce((a, s) => a + (s.structEnd - s.structStart + 1), 0);
|
|
140
22
|
}
|
|
141
23
|
/**
|
|
142
|
-
* The segments of one accession that describe this entity.
|
|
143
|
-
* entities as the mmCIF does, and a PDB-format file loaded through
|
|
144
|
-
* them per chain (1H26.pdb's chain C is entity 2, which in
|
|
145
|
-
* so a segment naming its chain is matched by chain.
|
|
24
|
+
* The segments of one accession that describe this entity. The mapping
|
|
25
|
+
* numbers entities as the mmCIF does, and a PDB-format file loaded through
|
|
26
|
+
* Mol* numbers them per chain (1H26.pdb's chain C is entity 2, which in the
|
|
27
|
+
* mmCIF is cyclin A), so a segment naming its chain is matched by chain.
|
|
146
28
|
*/
|
|
147
29
|
function segmentsForEntity(mapping, entity) {
|
|
148
30
|
return dedupeSegments(mapping.segments.filter(s => s.chainId === undefined
|
|
@@ -150,12 +32,11 @@ function segmentsForEntity(mapping, entity) {
|
|
|
150
32
|
: entity.chains.includes(s.chainId)));
|
|
151
33
|
}
|
|
152
34
|
/**
|
|
153
|
-
* Picks the UniProt entry
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* contributing the most residues wins.
|
|
35
|
+
* Picks the UniProt entry for a given entity, with its segments narrowed to
|
|
36
|
+
* that entity. Pass the entity mapped to the transcript: a heteromer's chains
|
|
37
|
+
* align to different accessions, and the wrong one would annotate the wrong
|
|
38
|
+
* protein. When several accessions cover one entity (a chimeric construct), the
|
|
39
|
+
* one covering the most residues wins.
|
|
159
40
|
*/
|
|
160
41
|
function chooseUniProtMappingForEntity(mappings, entity) {
|
|
161
42
|
if (entity === undefined) {
|
|
@@ -174,10 +55,11 @@ function chooseUniProtMappingForEntity(mappings, entity) {
|
|
|
174
55
|
const OWN_PSEUDOCOUNT = 5;
|
|
175
56
|
const MIN_OWN_IDENTITY = 0.5;
|
|
176
57
|
/**
|
|
177
|
-
* Mapped structure positions
|
|
178
|
-
* transcript's, on a chain that fuses two. Local
|
|
179
|
-
* boundary, and on every GPCR fusion construct
|
|
180
|
-
* residues onto the partner, 33 of them onto T4
|
|
58
|
+
* Mapped structure positions the entry's UniProt alignment assigns to a
|
|
59
|
+
* protein other than the transcript's, on a chain that fuses two. Local
|
|
60
|
+
* alignment bridges a fusion boundary, and on every GPCR fusion construct
|
|
61
|
+
* checked it scattered receptor residues onto the partner, 33 of them onto T4
|
|
62
|
+
* lysozyme in 2RH1.
|
|
181
63
|
*
|
|
182
64
|
* `mapped` is each mapped structure position and whether its pair is
|
|
183
65
|
* identical. The transcript's own accession is the one whose covered positions
|
|
@@ -186,7 +68,7 @@ const MIN_OWN_IDENTITY = 0.5;
|
|
|
186
68
|
* fused to CDK2 covers 11 positions against 224 chance hits on the kinase, and
|
|
187
69
|
* counting unmapped the peptide. Unless that accession reaches half identity
|
|
188
70
|
* the transcript is taken to be neither protein, and nothing is unmapped.
|
|
189
|
-
* Residues
|
|
71
|
+
* Residues assigned to no accession, such as tags, stay mapped.
|
|
190
72
|
*/
|
|
191
73
|
function fusionPartnerPositions(mappings, entity, mapped) {
|
|
192
74
|
const partners = new Set();
|
|
@@ -223,8 +105,8 @@ function fusionPartnerPositions(mappings, entity, mapped) {
|
|
|
223
105
|
}
|
|
224
106
|
return partners;
|
|
225
107
|
}
|
|
226
|
-
//
|
|
227
|
-
// repeat the same entity-level correspondence. They collapse to one
|
|
108
|
+
// The mapping lists one segment per *chain*, so the several chains of a
|
|
109
|
+
// homodimer repeat the same entity-level correspondence. They collapse to one.
|
|
228
110
|
function dedupeSegments(segments) {
|
|
229
111
|
const seen = new Set();
|
|
230
112
|
return segments.filter(s => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdbUniProtMapping.js","sourceRoot":"","sources":["../src/pdbUniProtMapping.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"pdbUniProtMapping.js","sourceRoot":"","sources":["../src/pdbUniProtMapping.ts"],"names":[],"mappings":";AAAA,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mD;AAC5C,MAAM,0BAA0B,GAAuB,UAAU,CAAC,EAAE,CACzE,UAAU,GAAG,CAAC,CAAA;AADH,QAAA,0BAA0B,8BACvB;AAEhB,SAAgB,sBAAsB,CACpC,QAAmC;IAEnC,OAAO,UAAU,CAAC,EAAE;QAClB,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAC3B,CAAC,CAAC,EAAE,CAAC,UAAU,IAAI,CAAC,CAAC,QAAQ,IAAI,UAAU,IAAI,CAAC,CAAC,MAAM,CACxD,CAAA;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,GAAG,CAAC,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;QACjE,OAAO,GAAG,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAA;IACnD,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Which molstar trajectory parser a structure needs.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* error.
|
|
4
|
+
* A wrong choice fails either way. Parsing a PDB file as mmCIF throws
|
|
5
|
+
* ("Unexpected token. Expected data_, loop_, or data name"). Parsing an mmCIF
|
|
6
|
+
* as PDB succeeds and yields a model with zero polymer entities and thousands of
|
|
7
|
+
* misread atoms, so the structure loads with no sequence, no alignment and no
|
|
8
|
+
* genome mapping, and with no error.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* The two names are the subset of molstar's `BuiltInTrajectoryFormat` a
|
|
15
|
-
* structure loaded from a file or a url can be, spelled out rather than
|
|
16
|
-
* imported so nothing here depends on molstar.
|
|
10
|
+
* The two names are the subset of molstar's `BuiltInTrajectoryFormat` that a
|
|
11
|
+
* structure file or URL can be, written out so nothing here imports molstar.
|
|
17
12
|
*/
|
|
18
13
|
export type StructureFormat = 'pdb' | 'mmcif';
|
|
19
14
|
/** Trailing extension of a filename or URL, lowercased, ignoring any query or
|
|
@@ -21,18 +16,16 @@ export type StructureFormat = 'pdb' | 'mmcif';
|
|
|
21
16
|
export declare function structureFileExtension(nameOrUrl: string): string;
|
|
22
17
|
/**
|
|
23
18
|
* Format for a filename or URL. Unknown extensions fall back to mmCIF, which is
|
|
24
|
-
* what
|
|
25
|
-
* hand out `.cif`).
|
|
19
|
+
* what AlphaFold and RCSB serve (`.cif`).
|
|
26
20
|
*/
|
|
27
21
|
export declare function structureFormatFromName(nameOrUrl: string): StructureFormat;
|
|
28
22
|
/** Whether a URL points at a binary-encoded structure, which molstar must be
|
|
29
23
|
* told to download as bytes rather than text. */
|
|
30
24
|
export declare function isBinaryStructureUrl(url: string): boolean;
|
|
31
25
|
/**
|
|
32
|
-
* Format for structure text
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* and is the only signal available here.
|
|
26
|
+
* Format for structure text with no filename, such as inline data, a pasted
|
|
27
|
+
* file, or a PDB built by `caCoordsToPdb`. The content is more reliable than a
|
|
28
|
+
* name, and here it is the only signal.
|
|
36
29
|
*
|
|
37
30
|
* mmCIF is line-oriented and its first meaningful line is a `data_` block
|
|
38
31
|
* header (comments and blank lines may precede it); PDB has none.
|
package/dist/structureFormat.js
CHANGED
|
@@ -20,8 +20,7 @@ function structureFileExtension(nameOrUrl) {
|
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Format for a filename or URL. Unknown extensions fall back to mmCIF, which is
|
|
23
|
-
* what
|
|
24
|
-
* hand out `.cif`).
|
|
23
|
+
* what AlphaFold and RCSB serve (`.cif`).
|
|
25
24
|
*/
|
|
26
25
|
function structureFormatFromName(nameOrUrl) {
|
|
27
26
|
return PDB_EXTENSIONS.has(structureFileExtension(nameOrUrl)) ? 'pdb' : 'mmcif';
|
|
@@ -32,10 +31,9 @@ function isBinaryStructureUrl(url) {
|
|
|
32
31
|
return structureFileExtension(url) === 'bcif';
|
|
33
32
|
}
|
|
34
33
|
/**
|
|
35
|
-
* Format for structure text
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* and is the only signal available here.
|
|
34
|
+
* Format for structure text with no filename, such as inline data, a pasted
|
|
35
|
+
* file, or a PDB built by `caCoordsToPdb`. The content is more reliable than a
|
|
36
|
+
* name, and here it is the only signal.
|
|
39
37
|
*
|
|
40
38
|
* mmCIF is line-oriented and its first meaningful line is a `data_` block
|
|
41
39
|
* header (comments and blank lines may precede it); PDB has none.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structureFormat.js","sourceRoot":"","sources":["../src/structureFormat.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"structureFormat.js","sourceRoot":"","sources":["../src/structureFormat.ts"],"names":[],"mappings":";;AAoBA,wDAQC;AAMD,0DAEC;AAID,oDAEC;AAUD,gEAUC;AAhDD,gFAAgF;AAChF,wEAAwE;AACxE,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;AAEtE;mEACmE;AACnE,SAAgB,sBAAsB,CAAC,SAAiB;IACtD,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAA;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC3C,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC1B,KAAK,CA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