p2s_mapper 1.0.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.
Files changed (172) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -0
  3. package/dist/alignmentQuality.d.ts +58 -0
  4. package/dist/alignmentQuality.js +108 -0
  5. package/dist/alignmentQuality.js.map +1 -0
  6. package/dist/alphaFoldModels.d.ts +29 -0
  7. package/dist/alphaFoldModels.js +60 -0
  8. package/dist/alphaFoldModels.js.map +1 -0
  9. package/dist/caCoordsToPdb.d.ts +18 -0
  10. package/dist/caCoordsToPdb.js +95 -0
  11. package/dist/caCoordsToPdb.js.map +1 -0
  12. package/dist/chooseMappedEntity.d.ts +55 -0
  13. package/dist/chooseMappedEntity.js +140 -0
  14. package/dist/chooseMappedEntity.js.map +1 -0
  15. package/dist/coordinates.d.ts +66 -0
  16. package/dist/coordinates.js +66 -0
  17. package/dist/coordinates.js.map +1 -0
  18. package/dist/dbIds.d.ts +16 -0
  19. package/dist/dbIds.js +42 -0
  20. package/dist/dbIds.js.map +1 -0
  21. package/dist/extractPerResidueConfidence.d.ts +49 -0
  22. package/dist/extractPerResidueConfidence.js +42 -0
  23. package/dist/extractPerResidueConfidence.js.map +1 -0
  24. package/dist/extractStructureSequences.d.ts +142 -0
  25. package/dist/extractStructureSequences.js +217 -0
  26. package/dist/extractStructureSequences.js.map +1 -0
  27. package/dist/fetchUtils.d.ts +34 -0
  28. package/dist/fetchUtils.js +91 -0
  29. package/dist/fetchUtils.js.map +1 -0
  30. package/dist/index.d.ts +23 -0
  31. package/dist/index.js +46 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/invertMap.d.ts +2 -0
  34. package/dist/invertMap.js +8 -0
  35. package/dist/invertMap.js.map +1 -0
  36. package/dist/isoformRanking.d.ts +47 -0
  37. package/dist/isoformRanking.js +91 -0
  38. package/dist/isoformRanking.js.map +1 -0
  39. package/dist/mappings.d.ts +58 -0
  40. package/dist/mappings.js +193 -0
  41. package/dist/mappings.js.map +1 -0
  42. package/dist/package.json +1 -0
  43. package/dist/pairwiseAlignment.d.ts +35 -0
  44. package/dist/pairwiseAlignment.js +337 -0
  45. package/dist/pairwiseAlignment.js.map +1 -0
  46. package/dist/pdbUniProtMapping.d.ts +75 -0
  47. package/dist/pdbUniProtMapping.js +241 -0
  48. package/dist/pdbUniProtMapping.js.map +1 -0
  49. package/dist/pdbeBestStructures.d.ts +23 -0
  50. package/dist/pdbeBestStructures.js +79 -0
  51. package/dist/pdbeBestStructures.js.map +1 -0
  52. package/dist/pdbeEntryMolecules.d.ts +7 -0
  53. package/dist/pdbeEntryMolecules.js +39 -0
  54. package/dist/pdbeEntryMolecules.js.map +1 -0
  55. package/dist/siftsNumbering.d.ts +23 -0
  56. package/dist/siftsNumbering.js +44 -0
  57. package/dist/siftsNumbering.js.map +1 -0
  58. package/dist/stripStopCodon.d.ts +15 -0
  59. package/dist/stripStopCodon.js +24 -0
  60. package/dist/stripStopCodon.js.map +1 -0
  61. package/dist/structureFormat.d.ts +40 -0
  62. package/dist/structureFormat.js +54 -0
  63. package/dist/structureFormat.js.map +1 -0
  64. package/dist/structureSources.d.ts +28 -0
  65. package/dist/structureSources.js +76 -0
  66. package/dist/structureSources.js.map +1 -0
  67. package/dist/structureUrls.d.ts +54 -0
  68. package/dist/structureUrls.js +147 -0
  69. package/dist/structureUrls.js.map +1 -0
  70. package/dist/types.d.ts +14 -0
  71. package/dist/types.js +27 -0
  72. package/dist/types.js.map +1 -0
  73. package/dist/uniProtSearch.d.ts +32 -0
  74. package/dist/uniProtSearch.js +114 -0
  75. package/dist/uniProtSearch.js.map +1 -0
  76. package/esm/alignmentQuality.d.ts +58 -0
  77. package/esm/alignmentQuality.js +100 -0
  78. package/esm/alignmentQuality.js.map +1 -0
  79. package/esm/alphaFoldModels.d.ts +29 -0
  80. package/esm/alphaFoldModels.js +55 -0
  81. package/esm/alphaFoldModels.js.map +1 -0
  82. package/esm/caCoordsToPdb.d.ts +18 -0
  83. package/esm/caCoordsToPdb.js +91 -0
  84. package/esm/caCoordsToPdb.js.map +1 -0
  85. package/esm/chooseMappedEntity.d.ts +55 -0
  86. package/esm/chooseMappedEntity.js +134 -0
  87. package/esm/chooseMappedEntity.js.map +1 -0
  88. package/esm/coordinates.d.ts +66 -0
  89. package/esm/coordinates.js +58 -0
  90. package/esm/coordinates.js.map +1 -0
  91. package/esm/dbIds.d.ts +16 -0
  92. package/esm/dbIds.js +35 -0
  93. package/esm/dbIds.js.map +1 -0
  94. package/esm/extractPerResidueConfidence.d.ts +49 -0
  95. package/esm/extractPerResidueConfidence.js +38 -0
  96. package/esm/extractPerResidueConfidence.js.map +1 -0
  97. package/esm/extractStructureSequences.d.ts +142 -0
  98. package/esm/extractStructureSequences.js +205 -0
  99. package/esm/extractStructureSequences.js.map +1 -0
  100. package/esm/fetchUtils.d.ts +34 -0
  101. package/esm/fetchUtils.js +82 -0
  102. package/esm/fetchUtils.js.map +1 -0
  103. package/esm/index.d.ts +23 -0
  104. package/esm/index.js +30 -0
  105. package/esm/index.js.map +1 -0
  106. package/esm/invertMap.d.ts +2 -0
  107. package/esm/invertMap.js +5 -0
  108. package/esm/invertMap.js.map +1 -0
  109. package/esm/isoformRanking.d.ts +47 -0
  110. package/esm/isoformRanking.js +86 -0
  111. package/esm/isoformRanking.js.map +1 -0
  112. package/esm/mappings.d.ts +58 -0
  113. package/esm/mappings.js +179 -0
  114. package/esm/mappings.js.map +1 -0
  115. package/esm/pairwiseAlignment.d.ts +35 -0
  116. package/esm/pairwiseAlignment.js +328 -0
  117. package/esm/pairwiseAlignment.js.map +1 -0
  118. package/esm/pdbUniProtMapping.d.ts +75 -0
  119. package/esm/pdbUniProtMapping.js +231 -0
  120. package/esm/pdbUniProtMapping.js.map +1 -0
  121. package/esm/pdbeBestStructures.d.ts +23 -0
  122. package/esm/pdbeBestStructures.js +73 -0
  123. package/esm/pdbeBestStructures.js.map +1 -0
  124. package/esm/pdbeEntryMolecules.d.ts +7 -0
  125. package/esm/pdbeEntryMolecules.js +35 -0
  126. package/esm/pdbeEntryMolecules.js.map +1 -0
  127. package/esm/siftsNumbering.d.ts +23 -0
  128. package/esm/siftsNumbering.js +40 -0
  129. package/esm/siftsNumbering.js.map +1 -0
  130. package/esm/stripStopCodon.d.ts +15 -0
  131. package/esm/stripStopCodon.js +20 -0
  132. package/esm/stripStopCodon.js.map +1 -0
  133. package/esm/structureFormat.d.ts +40 -0
  134. package/esm/structureFormat.js +48 -0
  135. package/esm/structureFormat.js.map +1 -0
  136. package/esm/structureSources.d.ts +28 -0
  137. package/esm/structureSources.js +71 -0
  138. package/esm/structureSources.js.map +1 -0
  139. package/esm/structureUrls.d.ts +54 -0
  140. package/esm/structureUrls.js +134 -0
  141. package/esm/structureUrls.js.map +1 -0
  142. package/esm/types.d.ts +14 -0
  143. package/esm/types.js +23 -0
  144. package/esm/types.js.map +1 -0
  145. package/esm/uniProtSearch.d.ts +32 -0
  146. package/esm/uniProtSearch.js +110 -0
  147. package/esm/uniProtSearch.js.map +1 -0
  148. package/package.json +63 -0
  149. package/src/alignmentQuality.ts +132 -0
  150. package/src/alphaFoldModels.ts +91 -0
  151. package/src/caCoordsToPdb.ts +111 -0
  152. package/src/chooseMappedEntity.ts +198 -0
  153. package/src/coordinates.ts +119 -0
  154. package/src/dbIds.ts +46 -0
  155. package/src/extractPerResidueConfidence.ts +88 -0
  156. package/src/extractStructureSequences.ts +342 -0
  157. package/src/fetchUtils.ts +110 -0
  158. package/src/index.ts +34 -0
  159. package/src/invertMap.ts +4 -0
  160. package/src/isoformRanking.ts +139 -0
  161. package/src/mappings.ts +230 -0
  162. package/src/pairwiseAlignment.ts +423 -0
  163. package/src/pdbUniProtMapping.ts +320 -0
  164. package/src/pdbeBestStructures.ts +94 -0
  165. package/src/pdbeEntryMolecules.ts +37 -0
  166. package/src/siftsNumbering.ts +61 -0
  167. package/src/stripStopCodon.ts +20 -0
  168. package/src/structureFormat.ts +70 -0
  169. package/src/structureSources.ts +101 -0
  170. package/src/structureUrls.ts +171 -0
  171. package/src/types.ts +30 -0
  172. package/src/uniProtSearch.ts +212 -0
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fillAuthSeqIds = fillAuthSeqIds;
4
+ exports.residueNumber = residueNumber;
5
+ exports.residueRangeToPositions = residueRangeToPositions;
6
+ exports.oneLetterSequence = oneLetterSequence;
7
+ exports.extractEntities = extractEntities;
8
+ exports.entityLabel = entityLabel;
9
+ exports.extractStructureSequences = extractStructureSequences;
10
+ exports.toLabelSeqIds = toLabelSeqIds;
11
+ exports.rangeToLabelSeqIds = rangeToLabelSeqIds;
12
+ exports.makeLabelSeqIdIndex = makeLabelSeqIdIndex;
13
+ /** Observed residues' label_seq_id -> auth_seq_id, per entity. The first chain
14
+ * carrying an entity wins, so a homodimer's copies agree. */
15
+ function authSeqIdsByEntity(model) {
16
+ const hierarchy = model.obj?.data.atomicHierarchy;
17
+ const byEntity = new Map();
18
+ const { residues, residueAtomSegments, chainAtomSegments, chains } = hierarchy ?? {};
19
+ if (!residues || !residueAtomSegments || !chainAtomSegments || !chains) {
20
+ return undefined;
21
+ }
22
+ for (let residue = 0; residue < residueAtomSegments.count; residue++) {
23
+ const atom = residueAtomSegments.offsets[residue];
24
+ const entityId = chains.label_entity_id.value(chainAtomSegments.index[atom]);
25
+ let ids = byEntity.get(entityId);
26
+ if (!ids) {
27
+ ids = new Map();
28
+ byEntity.set(entityId, ids);
29
+ }
30
+ const labelSeqId = residues.label_seq_id.value(residue);
31
+ if (!ids.has(labelSeqId)) {
32
+ ids.set(labelSeqId, residues.auth_seq_id.value(residue));
33
+ }
34
+ }
35
+ return byEntity;
36
+ }
37
+ /**
38
+ * Author numbering for every SEQRES position, observed or not. A residue with
39
+ * no atoms has no auth_seq_id of its own, so it takes the offset of the nearest
40
+ * observed residue before it (after it, at an unobserved N-terminus): a
41
+ * disordered loop keeps counting the way the paper does. With nothing observed
42
+ * the label numbering stands.
43
+ */
44
+ function fillAuthSeqIds(seqIds, observed) {
45
+ const out = [];
46
+ let offset;
47
+ const firstObserved = seqIds.find(id => observed?.has(id));
48
+ if (firstObserved !== undefined) {
49
+ offset = observed.get(firstObserved) - firstObserved;
50
+ }
51
+ for (const id of seqIds) {
52
+ const auth = observed?.get(id);
53
+ if (auth !== undefined) {
54
+ offset = auth - id;
55
+ }
56
+ out.push(id + (offset ?? 0));
57
+ }
58
+ return out;
59
+ }
60
+ /** The number a residue is called by: author numbering when the file carries
61
+ * it, else molstar's label_seq_id, which is the author numbering already for a
62
+ * SEQRES-less PDB and 1..N for everything else. */
63
+ function residueNumber(entity, pos) {
64
+ return entity?.authSeqIds?.[pos] ?? entity?.seqIds[pos] ?? pos + 1;
65
+ }
66
+ /**
67
+ * The 0-based half-open position range covering an inclusive range of author
68
+ * residue numbers, the form a paper or a spec names a site by ("R248",
69
+ * "residues 102-292"). Undefined when no residue of the entity carries a number
70
+ * in the range, so a typo selects nothing rather than something else.
71
+ */
72
+ function residueRangeToPositions(entity, range) {
73
+ if (!entity) {
74
+ return undefined;
75
+ }
76
+ let first;
77
+ let last;
78
+ for (let pos = 0; pos < entity.seq.length; pos++) {
79
+ const n = residueNumber(entity, pos);
80
+ if (n >= range.start && n <= range.end) {
81
+ first ??= pos;
82
+ last = pos;
83
+ }
84
+ }
85
+ return first === undefined || last === undefined
86
+ ? undefined
87
+ : { start: first, end: last + 1 };
88
+ }
89
+ function chainsByEntity(model) {
90
+ const chains = model.obj?.data.atomicHierarchy?.chains;
91
+ const byEntity = new Map();
92
+ if (chains) {
93
+ for (let i = 0; i < chains.label_entity_id.rowCount; i++) {
94
+ const entityId = chains.label_entity_id.value(i);
95
+ const chain = chains.auth_asym_id.value(i);
96
+ const list = byEntity.get(entityId) ?? [];
97
+ if (!list.includes(chain)) {
98
+ list.push(chain);
99
+ }
100
+ byEntity.set(entityId, list);
101
+ }
102
+ }
103
+ return byEntity;
104
+ }
105
+ // mmCIF entity_poly.type values for nucleic-acid polymers. Molstar derives the
106
+ // subtype from residue components when a file (PDB format) carries no
107
+ // entity_poly, so the flag is available for either format.
108
+ const NUCLEIC_ACID_SUBTYPES = new Set([
109
+ 'polydeoxyribonucleotide',
110
+ 'polyribonucleotide',
111
+ 'polydeoxyribonucleotide/polyribonucleotide hybrid',
112
+ 'peptide nucleic acid',
113
+ ]);
114
+ function isNucleicAcid(model, entityId) {
115
+ const entities = model.obj?.data.entities;
116
+ if (!entities) {
117
+ return false;
118
+ }
119
+ const index = entities.getEntityIndex(entityId);
120
+ return index >= 0 && NUCLEIC_ACID_SUBTYPES.has(entities.subtype.value(index));
121
+ }
122
+ function canonicalSequencesByEntity(model) {
123
+ const source = model.obj?.data.sourceData?.data;
124
+ const entityPoly = source?.db?.entity_poly;
125
+ const byEntity = new Map();
126
+ if (entityPoly) {
127
+ for (let i = 0; i < entityPoly.entity_id.rowCount; i++) {
128
+ byEntity.set(entityPoly.entity_id.value(i), entityPoly.pdbx_seq_one_letter_code_can.value(i).replaceAll(/\s/g, ''));
129
+ }
130
+ }
131
+ return byEntity;
132
+ }
133
+ /**
134
+ * One letter per position, so `seq[pos]` and `seqIds[pos]` name the same
135
+ * residue. Molstar's `label` column is not that: it spells a residue with no
136
+ * one-letter code by its component id (MSE, TPO, ACE) and an alternate site as
137
+ * "(S|P)", which shifted every later position. `code` writes X for those; the
138
+ * mmCIF canonical sequence then supplies the parent residue (MSE is M) when it
139
+ * has one letter per position, which a chromophore spelled "TYG" does not.
140
+ */
141
+ function oneLetterSequence(codes, canonical) {
142
+ const letters = Array.from(codes);
143
+ return letters
144
+ .map((c, i) => c === 'X' && canonical?.length === letters.length ? canonical[i] : c)
145
+ .join('');
146
+ }
147
+ function extractEntities(model) {
148
+ const chains = chainsByEntity(model);
149
+ const authIds = authSeqIdsByEntity(model);
150
+ const canonical = canonicalSequencesByEntity(model);
151
+ return model.obj?.data.sequence.sequences.map(s => {
152
+ const seqIds = Array.from(s.sequence.seqId.toArray());
153
+ return {
154
+ entityId: s.entityId,
155
+ seq: oneLetterSequence(s.sequence.code.toArray(), canonical.get(s.entityId)),
156
+ seqIds,
157
+ chains: chains.get(s.entityId) ?? [],
158
+ ...(isNucleicAcid(model, s.entityId) ? { nucleicAcid: true } : {}),
159
+ ...(authIds
160
+ ? { authSeqIds: fillAuthSeqIds(seqIds, authIds.get(s.entityId)) }
161
+ : {}),
162
+ };
163
+ });
164
+ }
165
+ /** A user-facing name for an entity: its chains when known, else its id. */
166
+ function entityLabel(entity) {
167
+ const chains = entity.chains.length > 0
168
+ ? `Chain ${entity.chains.join('/')}`
169
+ : `Entity ${entity.entityId}`;
170
+ return `${chains} (${entity.seq.length} ${entity.nucleicAcid ? 'nt' : 'aa'})`;
171
+ }
172
+ /** The protein chains' sequences, for the launch dialog's isoform matching,
173
+ * which has no use for a DNA strand that happens to align. */
174
+ function extractStructureSequences(model) {
175
+ return extractEntities(model)
176
+ ?.filter(e => !e.nucleicAcid)
177
+ .map(e => e.seq);
178
+ }
179
+ /**
180
+ * The molstar `label_seq_id`s for a set of 0-based structure positions. Unknown
181
+ * positions are dropped rather than guessed, so an out-of-range position paints
182
+ * nothing instead of painting something wrong.
183
+ */
184
+ function toLabelSeqIds(entity, positions) {
185
+ if (!entity) {
186
+ return [];
187
+ }
188
+ const out = [];
189
+ for (const pos of positions) {
190
+ const id = entity.seqIds[pos];
191
+ if (id !== undefined) {
192
+ out.push(id);
193
+ }
194
+ }
195
+ return out;
196
+ }
197
+ /** As toLabelSeqIds, for a half-open [start, end) structure-position range. */
198
+ function rangeToLabelSeqIds(entity, range) {
199
+ if (!entity || !range) {
200
+ return [];
201
+ }
202
+ const start = Math.max(0, range.start);
203
+ const end = Math.min(entity.seqIds.length, range.end);
204
+ return end > start ? entity.seqIds.slice(start, end) : [];
205
+ }
206
+ /** Reverse of `seqIds`: molstar's label_seq_id -> 0-based structure position. */
207
+ function makeLabelSeqIdIndex(entity) {
208
+ const index = new Map();
209
+ entity?.seqIds.forEach((id, pos) => {
210
+ // first wins: duplicate ids (micro-heterogeneity) collapse to one residue
211
+ if (!index.has(id)) {
212
+ index.set(id, pos);
213
+ }
214
+ });
215
+ return index;
216
+ }
217
+ //# sourceMappingURL=extractStructureSequences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractStructureSequences.js","sourceRoot":"","sources":["../src/extractStructureSequences.ts"],"names":[],"mappings":";;AAuHA,wCAkBC;AAKD,sCAEC;AAQD,0DAmBC;AAwED,8CAUC;AAED,0CAoBC;AAGD,kCAMC;AAID,8DAMC;AAOD,sCAeC;AAGD,gDAUC;AAGD,kDASC;AAjQD;6DAC6D;AAC7D,SAAS,kBAAkB,CAAC,KAAqB;IAC/C,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,CAAA;IACjD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA+B,CAAA;IACvD,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAChE,SAAS,IAAI,EAAE,CAAA;IACjB,IAAI,CAAC,QAAQ,IAAI,CAAC,mBAAmB,IAAI,CAAC,iBAAiB,IAAI,CAAC,MAAM,EAAE,CAAC;QACvE,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC;QACrE,MAAM,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAE,CAAA;QAClD,MAAM,QAAQ,GAAG,MAAM,CAAC,eAAe,CAAC,KAAK,CAC3C,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAE,CAC/B,CAAA;QACD,IAAI,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAChC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,GAAG,GAAG,IAAI,GAAG,EAAE,CAAA;Y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CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The error a failed response deserves: status and host, plus at most the first
3
+ * line of the body. A whole body is an HTML error page or a megabyte of JSON,
4
+ * and pasting it into the dialog buries the one line that says what went wrong.
5
+ */
6
+ export declare function httpError(response: Response, url: string): Promise<Error>;
7
+ /**
8
+ * `fetch` rejects with a bare `TypeError: Failed to fetch` for a DNS failure,
9
+ * an offline browser and a refused cross-origin request alike, naming neither
10
+ * the host nor the cause. Anything else — an abort, most notably — passes
11
+ * through untouched.
12
+ */
13
+ export declare function networkError(url: string, cause: unknown): unknown;
14
+ /**
15
+ * Request options plus the `fetch` to make the request with. Every network
16
+ * function here takes them, so a caller can hand in a host's instrumented
17
+ * fetch, a test double, or nothing at all and get `globalThis.fetch`. Resolved
18
+ * per call rather than captured at import, so a page that installs its fetch
19
+ * late is still honored.
20
+ */
21
+ export interface FetchOptions extends RequestInit {
22
+ fetch?: typeof globalThis.fetch;
23
+ }
24
+ export declare function rawfetch(url: string, args?: FetchOptions): Promise<Response>;
25
+ export declare function myfetch(url: string, args?: FetchOptions): Promise<Response>;
26
+ export declare function jsonfetch<T = unknown>(url: string, args?: FetchOptions): Promise<T>;
27
+ /**
28
+ * An AbortSignal's reason as a real Error. `signal.reason` is `any` — usually a
29
+ * DOMException, but a caller can abort with anything at all — and throwing a
30
+ * non-Error loses the stack and breaks `instanceof Error` checks in the UI's
31
+ * error rendering. Normalize at every throw site.
32
+ */
33
+ export declare function abortError(signal: AbortSignal): Error;
34
+ export declare function timeout(time: number, signal?: AbortSignal): Promise<void>;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.httpError = httpError;
4
+ exports.networkError = networkError;
5
+ exports.rawfetch = rawfetch;
6
+ exports.myfetch = myfetch;
7
+ exports.jsonfetch = jsonfetch;
8
+ exports.abortError = abortError;
9
+ exports.timeout = timeout;
10
+ function hostOf(url) {
11
+ try {
12
+ return new URL(url).host;
13
+ }
14
+ catch {
15
+ return url;
16
+ }
17
+ }
18
+ const MAX_DETAIL = 200;
19
+ function firstLine(body) {
20
+ const line = body.split('\n', 1)[0]?.trim() ?? '';
21
+ return line.length > MAX_DETAIL ? `${line.slice(0, MAX_DETAIL)}…` : line;
22
+ }
23
+ /**
24
+ * The error a failed response deserves: status and host, plus at most the first
25
+ * line of the body. A whole body is an HTML error page or a megabyte of JSON,
26
+ * and pasting it into the dialog buries the one line that says what went wrong.
27
+ */
28
+ async function httpError(response, url) {
29
+ const detail = firstLine(await response.text().catch(() => ''));
30
+ const status = `HTTP ${response.status}${response.statusText ? ` ${response.statusText}` : ''} from ${hostOf(url)}`;
31
+ return new Error(detail ? `${status}: ${detail}` : status);
32
+ }
33
+ /**
34
+ * `fetch` rejects with a bare `TypeError: Failed to fetch` for a DNS failure,
35
+ * an offline browser and a refused cross-origin request alike, naming neither
36
+ * the host nor the cause. Anything else — an abort, most notably — passes
37
+ * through untouched.
38
+ */
39
+ function networkError(url, cause) {
40
+ return cause instanceof TypeError
41
+ ? new Error(`Could not reach ${hostOf(url)}. Check your network connection; the server may also be refusing cross-origin requests from this page.`, { cause })
42
+ : cause;
43
+ }
44
+ async function rawfetch(url, args) {
45
+ const { fetch: f = globalThis.fetch, ...init } = args ?? {};
46
+ try {
47
+ return await f(url, init);
48
+ }
49
+ catch (e) {
50
+ throw networkError(url, e);
51
+ }
52
+ }
53
+ async function myfetch(url, args) {
54
+ const response = await rawfetch(url, args);
55
+ if (!response.ok) {
56
+ throw await httpError(response, url);
57
+ }
58
+ return response;
59
+ }
60
+ async function jsonfetch(url, args) {
61
+ // The caller names the shape it expects; `Response.json` promises `any`, and
62
+ // narrowing it here rather than at the return keeps the body free of casts.
63
+ const response = await myfetch(url, args);
64
+ return response.json();
65
+ }
66
+ /**
67
+ * An AbortSignal's reason as a real Error. `signal.reason` is `any` — usually a
68
+ * DOMException, but a caller can abort with anything at all — and throwing a
69
+ * non-Error loses the stack and breaks `instanceof Error` checks in the UI's
70
+ * error rendering. Normalize at every throw site.
71
+ */
72
+ function abortError(signal) {
73
+ return signal.reason instanceof Error
74
+ ? signal.reason
75
+ : new Error('Aborted', { cause: signal.reason });
76
+ }
77
+ function timeout(time, signal) {
78
+ return new Promise((resolve, reject) => {
79
+ if (signal?.aborted) {
80
+ reject(abortError(signal));
81
+ }
82
+ else {
83
+ const id = setTimeout(resolve, time);
84
+ signal?.addEventListener('abort', () => {
85
+ clearTimeout(id);
86
+ reject(abortError(signal));
87
+ }, { once: true });
88
+ }
89
+ });
90
+ }
91
+ //# sourceMappingURL=fetchUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchUtils.js","sourceRoot":"","sources":["../src/fetchUtils.ts"],"names":[],"mappings":";;AAoBA,8BAIC;AAQD,oCAOC;AAaD,4BAOC;AAED,0BAQC;AAED,8BAQC;AAQD,gCAIC;AAED,0BAgBC;AA7GD,SAAS,MAAM,CAAC,GAAW;IACzB,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAA;IACZ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,GAAG,GAAG,CAAA;AAEtB,SAAS,SAAS,CAAC,IAAY;IAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;IACjD,OAAO,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAA;AAC1E,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,SAAS,CAAC,QAAkB,EAAE,GAAW;IAC7D,MAAM,MAAM,GAAG,SA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AAQ,EAAE,GAAG,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC;AAEM,KAAK,UAAU,SAAS,CAC7B,GAAW,EACX,IAAmB;IAEnB,6EAA6E;IAC7E,4EAA4E;IAC5E,MAAM,QAAQ,GAA+B,MAAM,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACrE,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;AACxB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,MAAmB;IAC5C,OAAO,MAAM,CAAC,MAAM,YAAY,KAAK;QACnC,CAAC,CAAC,MAAM,CAAC,MAAM;QACf,CAAC,CAAC,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;AACpD,CAAC;AAED,SAAgB,OAAO,CAAC,IAAY,EAAE,MAAoB;IACxD,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACpB,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;QAC5B,CAAC;aAAM,CAAC;YACN,MAAM,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;YACpC,MAAM,EAAE,gBAAgB,CACtB,OAAO,EACP,GAAG,EAAE;gBACH,YAAY,CAAC,EAAE,CAAC,CAAA;gBAChB,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;YAC5B,CAAC,EACD,EAAE,IAAI,EAAE,IAAI,EAAE,CACf,CAAA;QACH,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ export * from './types.ts';
2
+ export * from './mappings.ts';
3
+ export * from './pairwiseAlignment.ts';
4
+ export * from './alignmentQuality.ts';
5
+ export * from './coordinates.ts';
6
+ export * from './invertMap.ts';
7
+ export * from './stripStopCodon.ts';
8
+ export * from './chooseMappedEntity.ts';
9
+ export * from './extractStructureSequences.ts';
10
+ export * from './extractPerResidueConfidence.ts';
11
+ export * from './isoformRanking.ts';
12
+ export * from './pdbUniProtMapping.ts';
13
+ export * from './siftsNumbering.ts';
14
+ export * from './alphaFoldModels.ts';
15
+ export * from './pdbeBestStructures.ts';
16
+ export * from './pdbeEntryMolecules.ts';
17
+ export * from './structureSources.ts';
18
+ export * from './uniProtSearch.ts';
19
+ export * from './dbIds.ts';
20
+ export * from './structureUrls.ts';
21
+ export * from './structureFormat.ts';
22
+ export * from './caCoordsToPdb.ts';
23
+ export * from './fetchUtils.ts';
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Alignment
18
+ __exportStar(require("./types.js"), exports);
19
+ __exportStar(require("./mappings.js"), exports);
20
+ __exportStar(require("./pairwiseAlignment.js"), exports);
21
+ __exportStar(require("./alignmentQuality.js"), exports);
22
+ // Coordinates
23
+ __exportStar(require("./coordinates.js"), exports);
24
+ __exportStar(require("./invertMap.js"), exports);
25
+ __exportStar(require("./stripStopCodon.js"), exports);
26
+ // Chain choice
27
+ __exportStar(require("./chooseMappedEntity.js"), exports);
28
+ __exportStar(require("./extractStructureSequences.js"), exports);
29
+ __exportStar(require("./extractPerResidueConfidence.js"), exports);
30
+ __exportStar(require("./isoformRanking.js"), exports);
31
+ // SIFTS
32
+ __exportStar(require("./pdbUniProtMapping.js"), exports);
33
+ __exportStar(require("./siftsNumbering.js"), exports);
34
+ // Structure sources
35
+ __exportStar(require("./alphaFoldModels.js"), exports);
36
+ __exportStar(require("./pdbeBestStructures.js"), exports);
37
+ __exportStar(require("./pdbeEntryMolecules.js"), exports);
38
+ __exportStar(require("./structureSources.js"), exports);
39
+ __exportStar(require("./uniProtSearch.js"), exports);
40
+ __exportStar(require("./dbIds.js"), exports);
41
+ // Urls and formats
42
+ __exportStar(require("./structureUrls.js"), exports);
43
+ __exportStar(require("./structureFormat.js"), exports);
44
+ __exportStar(require("./caCoordsToPdb.js"), exports);
45
+ __exportStar(require("./fetchUtils.js"), exports);
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,YAAY;AACZ,6CAA0B;AAC1B,gDAA6B;AAC7B,yDAAsC;AACtC,wDAAqC;AAErC,cAAc;AACd,mDAAgC;AAChC,iDAA8B;AAC9B,sDAAmC;AAEnC,eAAe;AACf,0DAAuC;AACvC,iEAA8C;AAC9C,mEAAgD;AAChD,sDAAmC;AAEnC,QAAQ;AACR,yDAAsC;AACtC,sDAAmC;AAEnC,oBAAoB;AACpB,uDAAoC;AACpC,0DAAuC;AACvC,0DAAuC;AACvC,wDAAqC;AACrC,qDAAkC;AAClC,6CAA0B;AAE1B,mBAAmB;AACnB,qDAAkC;AAClC,uDAAoC;AACpC,qDAAkC;AAClC,kDAA+B"}
@@ -0,0 +1,2 @@
1
+ /** Swap keys and values of a numeric map, for reading a position map backwards. */
2
+ export declare function invertMap(arg: Record<number, number>): Record<number, number>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.invertMap = invertMap;
4
+ /** Swap keys and values of a numeric map, for reading a position map backwards. */
5
+ function invertMap(arg) {
6
+ return Object.fromEntries(Object.entries(arg).map(([a, b]) => [b, +a]));
7
+ }
8
+ //# sourceMappingURL=invertMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invertMap.js","sourceRoot":"","sources":["../src/invertMap.ts"],"names":[],"mappings":";;AACA,8BAEC;AAHD,mFAAmF;AACnF,SAAgB,SAAS,CAAC,GAA2B;IACnD,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACzE,CAAC"}
@@ -0,0 +1,47 @@
1
+ /** A transcript isoform, named by whatever id the caller ranks by. `seq` is its
2
+ * translation, absent when none could be computed. */
3
+ export interface Isoform {
4
+ id: string;
5
+ seq?: string;
6
+ }
7
+ export interface RankedIsoform {
8
+ id: string;
9
+ length: number;
10
+ /** identical residues against the structure, for an isoform that does not
11
+ * match it exactly; undefined with no structure to compare to */
12
+ identical?: number;
13
+ /** that alignment's score, which is what ranks non-matching isoforms */
14
+ score?: number;
15
+ }
16
+ export interface ClassifiedIsoforms {
17
+ matches: RankedIsoform[];
18
+ nonMatches: RankedIsoform[];
19
+ noData: string[];
20
+ }
21
+ /**
22
+ * The single rule for ranking transcript isoforms against a structure, shared
23
+ * by a picker UI and an auto-selection. An isoform whose translation is the
24
+ * structure's sequence wins outright. Among the rest, the best alignment score
25
+ * comes first, then the most identical residues, then length.
26
+ *
27
+ * The score has to lead: an isoform carrying an exon the structure lacks
28
+ * aligns every structure residue too, across a gap, so it ties on identical
29
+ * residues with the isoform the structure was made from (1MH1 against Rac1
30
+ * and Rac1b).
31
+ */
32
+ export declare function classifyIsoforms({ isoforms, structureSequence, }: {
33
+ isoforms: readonly Isoform[];
34
+ structureSequence?: string;
35
+ }): ClassifiedIsoforms;
36
+ /** The id of the isoform to open, by the ranking above. */
37
+ export declare function selectBestTranscript(args: {
38
+ isoforms: readonly Isoform[];
39
+ structureSequence?: string;
40
+ }): string | undefined;
41
+ /**
42
+ * Which of a structure's protein chains isoforms are compared against: one some
43
+ * isoform translates to exactly, else the chain `chooseMappedEntity` would map
44
+ * the longest isoform to, never simply the first (CDK2, on 1H26).
45
+ * `structureSequences` must hold protein chains only.
46
+ */
47
+ export declare function pickStructureSequence(structureSequences: string[] | undefined, isoforms: readonly Isoform[] | undefined): string | undefined;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.classifyIsoforms = classifyIsoforms;
4
+ exports.selectBestTranscript = selectBestTranscript;
5
+ exports.pickStructureSequence = pickStructureSequence;
6
+ const stripStopCodon_ts_1 = require("./stripStopCodon.js");
7
+ const chooseMappedEntity_ts_1 = require("./chooseMappedEntity.js");
8
+ // The picker re-ranks on every render and each non-exact isoform costs an
9
+ // O(len²) alignment, so results are cached by sequence pair: a titin-sized
10
+ // isoform against a long chain is a second of main-thread work each time.
11
+ const alignmentCache = new Map();
12
+ const ALIGNMENT_CACHE_LIMIT = 200;
13
+ function alignToStructure(isoform, structure) {
14
+ const key = `${isoform}\n${structure}`;
15
+ let result = alignmentCache.get(key);
16
+ if (result === undefined) {
17
+ const scored = (0, chooseMappedEntity_ts_1.alignTranscriptToEntity)(isoform, structure, 'smith_waterman');
18
+ result = { identical: scored?.matches ?? 0, score: scored?.score ?? 0 };
19
+ if (alignmentCache.size >= ALIGNMENT_CACHE_LIMIT) {
20
+ alignmentCache.clear();
21
+ }
22
+ alignmentCache.set(key, result);
23
+ }
24
+ return result;
25
+ }
26
+ /**
27
+ * The single rule for ranking transcript isoforms against a structure, shared
28
+ * by a picker UI and an auto-selection. An isoform whose translation is the
29
+ * structure's sequence wins outright. Among the rest, the best alignment score
30
+ * comes first, then the most identical residues, then length.
31
+ *
32
+ * The score has to lead: an isoform carrying an exon the structure lacks
33
+ * aligns every structure residue too, across a gap, so it ties on identical
34
+ * residues with the isoform the structure was made from (1MH1 against Rac1
35
+ * and Rac1b).
36
+ */
37
+ function classifyIsoforms({ isoforms, structureSequence, }) {
38
+ const matches = [];
39
+ const nonMatches = [];
40
+ const noData = [];
41
+ const structure = structureSequence
42
+ ? (0, stripStopCodon_ts_1.stripStopCodon)(structureSequence)
43
+ : undefined;
44
+ for (const { id, seq } of isoforms) {
45
+ if (seq === undefined) {
46
+ noData.push(id);
47
+ }
48
+ else if (structure && (0, stripStopCodon_ts_1.stripStopCodon)(seq) === structure) {
49
+ matches.push({ id, length: seq.length });
50
+ }
51
+ else {
52
+ nonMatches.push({
53
+ id,
54
+ length: seq.length,
55
+ ...(structure ? alignToStructure(seq, structure) : {}),
56
+ });
57
+ }
58
+ }
59
+ const byLengthDesc = (a, b) => b.length - a.length;
60
+ const byAlignmentThenLength = (a, b) => (b.score ?? 0) - (a.score ?? 0) ||
61
+ (b.identical ?? 0) - (a.identical ?? 0) ||
62
+ byLengthDesc(a, b);
63
+ return {
64
+ matches: matches.toSorted(byLengthDesc),
65
+ nonMatches: nonMatches.toSorted(byAlignmentThenLength),
66
+ noData,
67
+ };
68
+ }
69
+ /** The id of the isoform to open, by the ranking above. */
70
+ function selectBestTranscript(args) {
71
+ const { matches, nonMatches } = classifyIsoforms(args);
72
+ return (matches[0] ?? nonMatches[0])?.id;
73
+ }
74
+ /**
75
+ * Which of a structure's protein chains isoforms are compared against: one some
76
+ * isoform translates to exactly, else the chain `chooseMappedEntity` would map
77
+ * the longest isoform to, never simply the first (CDK2, on 1H26).
78
+ * `structureSequences` must hold protein chains only.
79
+ */
80
+ function pickStructureSequence(structureSequences, isoforms) {
81
+ const translations = (isoforms ?? []).flatMap(({ seq }) => seq === undefined ? [] : [(0, stripStopCodon_ts_1.stripStopCodon)(seq)]);
82
+ const translated = new Set(translations);
83
+ const exact = structureSequences?.find(s => translated.has((0, stripStopCodon_ts_1.stripStopCodon)(s)));
84
+ const longest = translations.reduce((a, b) => (a !== undefined && a.length >= b.length ? a : b), undefined);
85
+ const aligned = structureSequences && longest
86
+ ? (0, chooseMappedEntity_ts_1.chooseMappedEntity)(longest, structureSequences, 'smith_waterman')
87
+ : undefined;
88
+ return (exact ??
89
+ (aligned ? structureSequences?.[aligned.index] : structureSequences?.[0]));
90
+ }
91
+ //# sourceMappingURL=isoformRanking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isoformRanking.js","sourceRoot":"","sources":["../src/isoformRanking.ts"],"names":[],"mappings":";;AA+DA,4CAqCC;AAGD,oDAMC;AAQD,sDAqBC;AA1ID,2DAAoD;AACpD,mEAGgC;AA4BhC,0EAA0E;AAC1E,2EAA2E;AAC3E,0EAA0E;AAC1E,MAAM,cAAc,GAAG,IAAI,GAAG,EAAgD,CAAA;AAC9E,MAAM,qBAAqB,GAAG,GAAG,CAAA;AAEjC,SAAS,gBAAgB,CAAC,OAAe,EAAE,SAAiB;IAC1D,MAAM,GAAG,GAAG,GAAG,OAAO,KAAK,SAAS,EAAE,CAAA;IACtC,IAAI,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACpC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,IAAA,+CAAuB,EAAC,OAAO,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAA;QAC5E,MAAM,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAA;QACvE,IAAI,cAAc,CAAC,IAAI,IAAI,qBAAqB,EAAE,CAAC;YACjD,cAAc,CAAC,KAAK,EAAE,CAAA;QACxB,CAAC;QACD,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IACjC,CAAC;IACD,OAAO,MA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