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,82 @@
1
+ function hostOf(url) {
2
+ try {
3
+ return new URL(url).host;
4
+ }
5
+ catch {
6
+ return url;
7
+ }
8
+ }
9
+ const MAX_DETAIL = 200;
10
+ function firstLine(body) {
11
+ const line = body.split('\n', 1)[0]?.trim() ?? '';
12
+ return line.length > MAX_DETAIL ? `${line.slice(0, MAX_DETAIL)}…` : line;
13
+ }
14
+ /**
15
+ * The error a failed response deserves: status and host, plus at most the first
16
+ * line of the body. A whole body is an HTML error page or a megabyte of JSON,
17
+ * and pasting it into the dialog buries the one line that says what went wrong.
18
+ */
19
+ export async function httpError(response, url) {
20
+ const detail = firstLine(await response.text().catch(() => ''));
21
+ const status = `HTTP ${response.status}${response.statusText ? ` ${response.statusText}` : ''} from ${hostOf(url)}`;
22
+ return new Error(detail ? `${status}: ${detail}` : status);
23
+ }
24
+ /**
25
+ * `fetch` rejects with a bare `TypeError: Failed to fetch` for a DNS failure,
26
+ * an offline browser and a refused cross-origin request alike, naming neither
27
+ * the host nor the cause. Anything else — an abort, most notably — passes
28
+ * through untouched.
29
+ */
30
+ export function networkError(url, cause) {
31
+ return cause instanceof TypeError
32
+ ? new Error(`Could not reach ${hostOf(url)}. Check your network connection; the server may also be refusing cross-origin requests from this page.`, { cause })
33
+ : cause;
34
+ }
35
+ export async function rawfetch(url, args) {
36
+ const { fetch: f = globalThis.fetch, ...init } = args ?? {};
37
+ try {
38
+ return await f(url, init);
39
+ }
40
+ catch (e) {
41
+ throw networkError(url, e);
42
+ }
43
+ }
44
+ export async function myfetch(url, args) {
45
+ const response = await rawfetch(url, args);
46
+ if (!response.ok) {
47
+ throw await httpError(response, url);
48
+ }
49
+ return response;
50
+ }
51
+ export async function jsonfetch(url, args) {
52
+ // The caller names the shape it expects; `Response.json` promises `any`, and
53
+ // narrowing it here rather than at the return keeps the body free of casts.
54
+ const response = await myfetch(url, args);
55
+ return response.json();
56
+ }
57
+ /**
58
+ * An AbortSignal's reason as a real Error. `signal.reason` is `any` — usually a
59
+ * DOMException, but a caller can abort with anything at all — and throwing a
60
+ * non-Error loses the stack and breaks `instanceof Error` checks in the UI's
61
+ * error rendering. Normalize at every throw site.
62
+ */
63
+ export function abortError(signal) {
64
+ return signal.reason instanceof Error
65
+ ? signal.reason
66
+ : new Error('Aborted', { cause: signal.reason });
67
+ }
68
+ export function timeout(time, signal) {
69
+ return new Promise((resolve, reject) => {
70
+ if (signal?.aborted) {
71
+ reject(abortError(signal));
72
+ }
73
+ else {
74
+ const id = setTimeout(resolve, time);
75
+ signal?.addEventListener('abort', () => {
76
+ clearTimeout(id);
77
+ reject(abortError(signal));
78
+ }, { once: true });
79
+ }
80
+ });
81
+ }
82
+ //# sourceMappingURL=fetchUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchUtils.js","sourceRoot":"","sources":["../src/fetchUtils.ts"],"names":[],"mappings":"AAAA,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;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,QAAkB,EAAE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.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/esm/index.js ADDED
@@ -0,0 +1,30 @@
1
+ // Alignment
2
+ export * from "./types.js";
3
+ export * from "./mappings.js";
4
+ export * from "./pairwiseAlignment.js";
5
+ export * from "./alignmentQuality.js";
6
+ // Coordinates
7
+ export * from "./coordinates.js";
8
+ export * from "./invertMap.js";
9
+ export * from "./stripStopCodon.js";
10
+ // Chain choice
11
+ export * from "./chooseMappedEntity.js";
12
+ export * from "./extractStructureSequences.js";
13
+ export * from "./extractPerResidueConfidence.js";
14
+ export * from "./isoformRanking.js";
15
+ // SIFTS
16
+ export * from "./pdbUniProtMapping.js";
17
+ export * from "./siftsNumbering.js";
18
+ // Structure sources
19
+ export * from "./alphaFoldModels.js";
20
+ export * from "./pdbeBestStructures.js";
21
+ export * from "./pdbeEntryMolecules.js";
22
+ export * from "./structureSources.js";
23
+ export * from "./uniProtSearch.js";
24
+ export * from "./dbIds.js";
25
+ // Urls and formats
26
+ export * from "./structureUrls.js";
27
+ export * from "./structureFormat.js";
28
+ export * from "./caCoordsToPdb.js";
29
+ export * from "./fetchUtils.js";
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AAErC,cAAc;AACd,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AAEnC,eAAe;AACf,cAAc,yBAAyB,CAAA;AACvC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,kCAAkC,CAAA;AAChD,cAAc,qBAAqB,CAAA;AAEnC,QAAQ;AACR,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AAEnC,oBAAoB;AACpB,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAE1B,mBAAmB;AACnB,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA"}
@@ -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,5 @@
1
+ /** Swap keys and values of a numeric map, for reading a position map backwards. */
2
+ export function invertMap(arg) {
3
+ return Object.fromEntries(Object.entries(arg).map(([a, b]) => [b, +a]));
4
+ }
5
+ //# sourceMappingURL=invertMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invertMap.js","sourceRoot":"","sources":["../src/invertMap.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,UAAU,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,86 @@
1
+ import { stripStopCodon } from "./stripStopCodon.js";
2
+ import { alignTranscriptToEntity, chooseMappedEntity, } from "./chooseMappedEntity.js";
3
+ // The picker re-ranks on every render and each non-exact isoform costs an
4
+ // O(len²) alignment, so results are cached by sequence pair: a titin-sized
5
+ // isoform against a long chain is a second of main-thread work each time.
6
+ const alignmentCache = new Map();
7
+ const ALIGNMENT_CACHE_LIMIT = 200;
8
+ function alignToStructure(isoform, structure) {
9
+ const key = `${isoform}\n${structure}`;
10
+ let result = alignmentCache.get(key);
11
+ if (result === undefined) {
12
+ const scored = alignTranscriptToEntity(isoform, structure, 'smith_waterman');
13
+ result = { identical: scored?.matches ?? 0, score: scored?.score ?? 0 };
14
+ if (alignmentCache.size >= ALIGNMENT_CACHE_LIMIT) {
15
+ alignmentCache.clear();
16
+ }
17
+ alignmentCache.set(key, result);
18
+ }
19
+ return result;
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 function classifyIsoforms({ isoforms, structureSequence, }) {
33
+ const matches = [];
34
+ const nonMatches = [];
35
+ const noData = [];
36
+ const structure = structureSequence
37
+ ? stripStopCodon(structureSequence)
38
+ : undefined;
39
+ for (const { id, seq } of isoforms) {
40
+ if (seq === undefined) {
41
+ noData.push(id);
42
+ }
43
+ else if (structure && stripStopCodon(seq) === structure) {
44
+ matches.push({ id, length: seq.length });
45
+ }
46
+ else {
47
+ nonMatches.push({
48
+ id,
49
+ length: seq.length,
50
+ ...(structure ? alignToStructure(seq, structure) : {}),
51
+ });
52
+ }
53
+ }
54
+ const byLengthDesc = (a, b) => b.length - a.length;
55
+ const byAlignmentThenLength = (a, b) => (b.score ?? 0) - (a.score ?? 0) ||
56
+ (b.identical ?? 0) - (a.identical ?? 0) ||
57
+ byLengthDesc(a, b);
58
+ return {
59
+ matches: matches.toSorted(byLengthDesc),
60
+ nonMatches: nonMatches.toSorted(byAlignmentThenLength),
61
+ noData,
62
+ };
63
+ }
64
+ /** The id of the isoform to open, by the ranking above. */
65
+ export function selectBestTranscript(args) {
66
+ const { matches, nonMatches } = classifyIsoforms(args);
67
+ return (matches[0] ?? nonMatches[0])?.id;
68
+ }
69
+ /**
70
+ * Which of a structure's protein chains isoforms are compared against: one some
71
+ * isoform translates to exactly, else the chain `chooseMappedEntity` would map
72
+ * the longest isoform to, never simply the first (CDK2, on 1H26).
73
+ * `structureSequences` must hold protein chains only.
74
+ */
75
+ export function pickStructureSequence(structureSequences, isoforms) {
76
+ const translations = (isoforms ?? []).flatMap(({ seq }) => seq === undefined ? [] : [stripStopCodon(seq)]);
77
+ const translated = new Set(translations);
78
+ const exact = structureSequences?.find(s => translated.has(stripStopCodon(s)));
79
+ const longest = translations.reduce((a, b) => (a !== undefined && a.length >= b.length ? a : b), undefined);
80
+ const aligned = structureSequences && longest
81
+ ? chooseMappedEntity(longest, structureSequences, 'smith_waterman')
82
+ : undefined;
83
+ return (exact ??
84
+ (aligned ? structureSequences?.[aligned.index] : structureSequences?.[0]));
85
+ }
86
+ //# sourceMappingURL=isoformRanking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isoformRanking.js","sourceRoot":"","sources":["../src/isoformRanking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EACL,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,yBAAyB,CAAA;AA4BhC,0EAA0E;AAC1E,2EAA2E;AAC3E,0EAA0E;AAC1E,MAAM,cAAc,GAAG,IAAI,GAAG,EAAgD,CAAA;AAC9E,MAAM,qBAAqB,GAAG,GAAG,CAAA;AAEjC,SAAS,gBAAgB,C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C,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CACxD,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAC/C,CAAA;IACD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAA;IACxC,MAAM,KAAK,GAAG,kBAAkB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9E,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CACjC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC3D,SAAS,CACV,CAAA;IACD,MAAM,OAAO,GACX,kBAAkB,IAAI,OAAO;QAC3B,CAAC,CAAC,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,CAAC;QACnE,CAAC,CAAC,SAAS,CAAA;IACf,OAAO,CACL,KAAK;QACL,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,CAAC,CAC1E,CAAA;AACH,CAAC"}
@@ -0,0 +1,58 @@
1
+ export interface AlignmentRow {
2
+ id: string;
3
+ seq: string;
4
+ }
5
+ /**
6
+ * A two-row alignment whose ROW ORDER IS A CONTRACT: row 0 is the transcript,
7
+ * row 1 is the structure. Every producer honors it — runLocalAlignment is
8
+ * always called as (transcript, structure), and the manual-import dialog tells
9
+ * the user to paste them in that order — and every consumer depends on it, but
10
+ * nothing in the type can enforce it, and swapping the two silently inverts
11
+ * every coordinate map. Read the rows through the accessors below rather than
12
+ * indexing, so a call site states which sequence it means.
13
+ */
14
+ export interface PairwiseAlignment {
15
+ consensus: string;
16
+ alns: readonly [AlignmentRow, AlignmentRow];
17
+ }
18
+ export declare const transcriptAlignedSeq: (pa: PairwiseAlignment) => string;
19
+ export declare const structureAlignedSeq: (pa: PairwiseAlignment) => string;
20
+ /** Number of columns, gaps included. Both rows have this length by definition;
21
+ * `pairwiseAlignmentProblem` is what guarantees it. */
22
+ export declare const alignmentLength: (pa: PairwiseAlignment) => number;
23
+ /**
24
+ * Why a pairwise alignment can't be used, or undefined if it's usable. The two
25
+ * rows must be the same non-zero length — every coordinate map walks them in
26
+ * lockstep, so a ragged pair would map positions to nonsense. Callers that
27
+ * accept alignments from outside (the manual-import dialog) check this and
28
+ * report it; the internal map builders assert on it.
29
+ */
30
+ export declare function pairwiseAlignmentProblem(pa: PairwiseAlignment): string | undefined;
31
+ /**
32
+ * Why an externally supplied alignment does not describe these two sequences,
33
+ * or undefined if it does. The coordinate maps index the transcript and the
34
+ * structure by counting residues along each row, so a row whose residues are
35
+ * not the sequence being mapped (an alignment made against UniProt canonical
36
+ * for a different isoform, or against another chain) shifts every position
37
+ * after the first difference without any map noticing.
38
+ */
39
+ export declare function pairwiseAlignmentSequenceProblem(pa: PairwiseAlignment, transcript: string, structure: string): string | undefined;
40
+ export declare function structureSeqVsTranscriptSeqMap(pairwiseAlignment: PairwiseAlignment): {
41
+ structureSeqToTranscriptSeqPosition: Record<number, number>;
42
+ transcriptSeqToStructureSeqPosition: Record<number, number>;
43
+ };
44
+ /** Each 0-based structure position opposite a transcript residue, and whether
45
+ * the two residues are identical. */
46
+ export declare function mappedStructureIdentity(pa: PairwiseAlignment): Map<number, boolean>;
47
+ /**
48
+ * The alignment with each listed structure position taken out of its column,
49
+ * so both rows still spell their sequences and those residues map to nothing.
50
+ * An unmapped region, including the gap columns inside it, becomes its
51
+ * transcript residues against gaps, then gaps against its structure residues,
52
+ * rather than alternating column by column. Returns `pa` itself when nothing
53
+ * changes.
54
+ */
55
+ export declare function unmapStructurePositions(pa: PairwiseAlignment, positions: ReadonlySet<number>): PairwiseAlignment;
56
+ export declare function structurePositionToAlignmentMap(pairwiseAlignment: PairwiseAlignment): Record<number, number>;
57
+ export declare function transcriptPositionToAlignmentMap(pairwiseAlignment: PairwiseAlignment): Record<number, number>;
58
+ export declare function codonGenomeSpan(p2gCodon: Record<number, number[]>, proteinPos: number): readonly [number, number] | undefined;
@@ -0,0 +1,179 @@
1
+ import { getCodonRanges } from 'g2p_mapper';
2
+ export const transcriptAlignedSeq = (pa) => pa.alns[0].seq;
3
+ export const structureAlignedSeq = (pa) => pa.alns[1].seq;
4
+ /** Number of columns, gaps included. Both rows have this length by definition;
5
+ * `pairwiseAlignmentProblem` is what guarantees it. */
6
+ export const alignmentLength = (pa) => transcriptAlignedSeq(pa).length;
7
+ /**
8
+ * Why a pairwise alignment can't be used, or undefined if it's usable. The two
9
+ * rows must be the same non-zero length — every coordinate map walks them in
10
+ * lockstep, so a ragged pair would map positions to nonsense. Callers that
11
+ * accept alignments from outside (the manual-import dialog) check this and
12
+ * report it; the internal map builders assert on it.
13
+ */
14
+ export function pairwiseAlignmentProblem(pa) {
15
+ const transcript = transcriptAlignedSeq(pa);
16
+ const structure = structureAlignedSeq(pa);
17
+ if (transcript.length === 0 || structure.length === 0) {
18
+ return 'The aligned sequences must not be empty';
19
+ }
20
+ if (transcript.length !== structure.length) {
21
+ return `The two aligned sequences must be the same length (got ${transcript.length} and ${structure.length})`;
22
+ }
23
+ return undefined;
24
+ }
25
+ const ungapped = (row) => row.replaceAll('-', '').toUpperCase();
26
+ /**
27
+ * Why an externally supplied alignment does not describe these two sequences,
28
+ * or undefined if it does. The coordinate maps index the transcript and the
29
+ * structure by counting residues along each row, so a row whose residues are
30
+ * not the sequence being mapped (an alignment made against UniProt canonical
31
+ * for a different isoform, or against another chain) shifts every position
32
+ * after the first difference without any map noticing.
33
+ */
34
+ export function pairwiseAlignmentSequenceProblem(pa, transcript, structure) {
35
+ const t = ungapped(transcriptAlignedSeq(pa));
36
+ const s = ungapped(structureAlignedSeq(pa));
37
+ if (t !== transcript.toUpperCase()) {
38
+ return `The first sequence is not this transcript's translation (${t.length} vs ${transcript.length} residues)`;
39
+ }
40
+ if (s !== structure.toUpperCase()) {
41
+ return `The second sequence is not the mapped chain's sequence (${s.length} vs ${structure.length} residues)`;
42
+ }
43
+ return undefined;
44
+ }
45
+ export function structureSeqVsTranscriptSeqMap(pairwiseAlignment) {
46
+ const problem = pairwiseAlignmentProblem(pairwiseAlignment);
47
+ if (problem) {
48
+ throw new Error(problem);
49
+ }
50
+ const structureSeq = structureAlignedSeq(pairwiseAlignment);
51
+ const transcriptSeq = transcriptAlignedSeq(pairwiseAlignment);
52
+ let j = 0;
53
+ let k = 0;
54
+ const structureSeqToTranscriptSeqPosition = {};
55
+ const transcriptSeqToStructureSeqPosition = {};
56
+ for (let i = 0; i < structureSeq.length; i++) {
57
+ const inStructure = structureSeq[i] !== '-';
58
+ const inTranscript = transcriptSeq[i] !== '-';
59
+ if (inStructure && inTranscript) {
60
+ structureSeqToTranscriptSeqPosition[j] = k;
61
+ transcriptSeqToStructureSeqPosition[k] = j;
62
+ }
63
+ if (inStructure) {
64
+ j++;
65
+ }
66
+ if (inTranscript) {
67
+ k++;
68
+ }
69
+ }
70
+ return {
71
+ structureSeqToTranscriptSeqPosition,
72
+ transcriptSeqToStructureSeqPosition,
73
+ };
74
+ }
75
+ /** Each 0-based structure position opposite a transcript residue, and whether
76
+ * the two residues are identical. */
77
+ export function mappedStructureIdentity(pa) {
78
+ const transcript = transcriptAlignedSeq(pa);
79
+ const structure = structureAlignedSeq(pa);
80
+ const mapped = new Map();
81
+ for (let i = 0, j = 0; i < structure.length; i++) {
82
+ if (structure[i] !== '-') {
83
+ if (transcript[i] !== '-') {
84
+ mapped.set(j, transcript[i].toUpperCase() === structure[i].toUpperCase());
85
+ }
86
+ j++;
87
+ }
88
+ }
89
+ return mapped;
90
+ }
91
+ /**
92
+ * The alignment with each listed structure position taken out of its column,
93
+ * so both rows still spell their sequences and those residues map to nothing.
94
+ * An unmapped region, including the gap columns inside it, becomes its
95
+ * transcript residues against gaps, then gaps against its structure residues,
96
+ * rather than alternating column by column. Returns `pa` itself when nothing
97
+ * changes.
98
+ */
99
+ export function unmapStructurePositions(pa, positions) {
100
+ const transcript = transcriptAlignedSeq(pa);
101
+ const structure = structureAlignedSeq(pa);
102
+ const t = [];
103
+ const s = [];
104
+ const c = [];
105
+ const runT = [];
106
+ const runS = [];
107
+ const flushRun = () => {
108
+ t.push(...runT, ...runS.map(() => '-'));
109
+ s.push(...runT.map(() => '-'), ...runS);
110
+ c.push(...runT.map(() => ' '), ...runS.map(() => ' '));
111
+ runT.length = 0;
112
+ runS.length = 0;
113
+ };
114
+ let j = 0;
115
+ let changed = false;
116
+ for (let i = 0; i < structure.length; i++) {
117
+ const inStructure = structure[i] !== '-';
118
+ const inTranscript = transcript[i] !== '-';
119
+ if (inStructure && inTranscript && positions.has(j)) {
120
+ runT.push(transcript[i]);
121
+ runS.push(structure[i]);
122
+ changed = true;
123
+ }
124
+ else if (runT.length > 0 && !(inStructure && inTranscript)) {
125
+ if (inTranscript) {
126
+ runT.push(transcript[i]);
127
+ }
128
+ if (inStructure) {
129
+ runS.push(structure[i]);
130
+ }
131
+ }
132
+ else {
133
+ flushRun();
134
+ t.push(transcript[i]);
135
+ s.push(structure[i]);
136
+ c.push(pa.consensus[i] ?? ' ');
137
+ }
138
+ if (inStructure) {
139
+ j++;
140
+ }
141
+ }
142
+ flushRun();
143
+ return changed
144
+ ? {
145
+ consensus: c.join(''),
146
+ alns: [
147
+ { ...pa.alns[0], seq: t.join('') },
148
+ { ...pa.alns[1], seq: s.join('') },
149
+ ],
150
+ }
151
+ : pa;
152
+ }
153
+ function seqPositionToAlignmentMap(seq) {
154
+ const map = {};
155
+ for (let i = 0, j = 0; i < seq.length; i++) {
156
+ if (seq[i] !== '-') {
157
+ map[j] = i;
158
+ j++;
159
+ }
160
+ }
161
+ return map;
162
+ }
163
+ export function structurePositionToAlignmentMap(pairwiseAlignment) {
164
+ return seqPositionToAlignmentMap(structureAlignedSeq(pairwiseAlignment));
165
+ }
166
+ export function transcriptPositionToAlignmentMap(pairwiseAlignment) {
167
+ return seqPositionToAlignmentMap(transcriptAlignedSeq(pairwiseAlignment));
168
+ }
169
+ // Enclosing 0-based half-open [start, end) genome span for a codon. getCodonRanges
170
+ // returns the codon's separate genomic pieces (multiple when it straddles an
171
+ // exon/intron boundary); this collapses them to the outer span for navigation
172
+ // and highlighting. undefined when the protein position isn't mapped.
173
+ export function codonGenomeSpan(p2gCodon, proteinPos) {
174
+ const ranges = getCodonRanges(p2gCodon, proteinPos);
175
+ return ranges && ranges.length > 0
176
+ ? [Math.min(...ranges.map(r => r[0])), Math.max(...ranges.map(r => r[1]))]
177
+ : undefined;
178
+ }
179
+ //# sourceMappingURL=mappings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mappings.js","sourceRoot":"","sources":["../src/mappings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAqB3C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,EAAqB,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;AAC7E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAAqB,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;AAE5E;uDACuD;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAqB,EAAE,EAAE,CACvD,oBAAoB,CAAC,EAAE,CAAC,CAAC,MAAM,CAAA;AAEjC;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,EAAqB;IAC5D,MAAM,UAAU,GAAG,oBAAoB,CAAC,EAAE,CAAC,CAAA;IAC3C,MAAM,SAAS,GAAG,mBAA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AAC,CAAA;IACnD,OAAO,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAChC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1E,CAAC,CAAC,SAAS,CAAA;AACf,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { PairwiseAlignment } from './mappings.ts';
2
+ import type { AlignmentAlgorithm } from './types.ts';
3
+ interface AlignmentResult {
4
+ alignedSeq1: string;
5
+ alignedSeq2: string;
6
+ score: number;
7
+ }
8
+ /**
9
+ * Ceiling on the dynamic-programming table, in cells. Both algorithms are
10
+ * O(m*n) time and hold one byte of traceback per cell, so this bounds the
11
+ * alignment at ~40 MB and roughly a second of main-thread work. Without it a
12
+ * titin-sized transcript or a long nucleic-acid chain locks up or OOMs the tab.
13
+ * Callers that have several candidates to align should check `alignmentTooLarge`
14
+ * and skip the oversized ones rather than let this throw.
15
+ */
16
+ export declare const MAX_ALIGNMENT_CELLS = 40000000;
17
+ export declare function alignmentTooLarge(len1: number, len2: number): boolean;
18
+ /**
19
+ * Needleman-Wunsch global alignment algorithm
20
+ * Aligns entire sequences end-to-end
21
+ */
22
+ export declare function needlemanWunsch(seq1: string, seq2: string, gapOpen?: number, gapExtend?: number): AlignmentResult;
23
+ /**
24
+ * Smith-Waterman local alignment algorithm
25
+ * Finds the best local alignment between subsequences
26
+ */
27
+ export declare function smithWaterman(seq1: string, seq2: string, gapOpen?: number, gapExtend?: number): AlignmentResult;
28
+ /** The score of a sequence aligned to itself with no gaps. */
29
+ export declare function selfScore(seq: string): number;
30
+ export declare function scoredAlignment(seq1: string, seq2: string, algorithm: AlignmentAlgorithm): {
31
+ alignment: PairwiseAlignment;
32
+ score: number;
33
+ };
34
+ export declare function runLocalAlignment(seq1: string, seq2: string, algorithm: AlignmentAlgorithm): PairwiseAlignment;
35
+ export {};