@jbrowse/plugin-alignments 2.16.0 → 2.17.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 (221) hide show
  1. package/dist/AlignmentsFeatureDetail/AlignmentsFeatureDetail.js +2 -3
  2. package/dist/AlignmentsFeatureDetail/Flags.js +2 -2
  3. package/dist/AlignmentsFeatureDetail/LinkedPairedAlignments.js +2 -2
  4. package/dist/AlignmentsFeatureDetail/SupplementaryAlignments.js +2 -2
  5. package/dist/AlignmentsFeatureDetail/getSAFeatures.js +2 -2
  6. package/dist/AlignmentsFeatureDetail/stateModelFactory.d.ts +1 -1
  7. package/dist/BamAdapter/BamAdapter.d.ts +3 -2
  8. package/dist/BamAdapter/BamAdapter.js +34 -11
  9. package/dist/BamAdapter/BamSlightlyLazyFeature.d.ts +3 -17
  10. package/dist/BamAdapter/BamSlightlyLazyFeature.js +42 -72
  11. package/dist/CramAdapter/CramAdapter.d.ts +4 -3
  12. package/dist/CramAdapter/CramAdapter.js +24 -7
  13. package/dist/CramAdapter/CramSlightlyLazyFeature.d.ts +21 -27
  14. package/dist/CramAdapter/CramSlightlyLazyFeature.js +74 -73
  15. package/dist/CramAdapter/util.d.ts +1 -10
  16. package/dist/LinearAlignmentsDisplay/components/AlignmentsDisplay.d.ts +1 -1
  17. package/dist/LinearAlignmentsDisplay/index.js +2 -2
  18. package/dist/LinearAlignmentsDisplay/{models/model.d.ts → model.d.ts} +6 -3
  19. package/dist/LinearAlignmentsDisplay/{models/model.js → model.js} +11 -7
  20. package/dist/LinearPileupDisplay/SharedLinearPileupDisplayMixin.d.ts +6 -27
  21. package/dist/LinearPileupDisplay/SharedLinearPileupDisplayMixin.js +43 -21
  22. package/dist/LinearPileupDisplay/components/ColorByTagDialog.d.ts +5 -4
  23. package/dist/LinearPileupDisplay/components/ColorByTagDialog.js +3 -1
  24. package/dist/LinearPileupDisplay/components/GroupByDialog.js +8 -6
  25. package/dist/LinearPileupDisplay/components/SortByTagDialog.js +6 -4
  26. package/dist/LinearPileupDisplay/model.d.ts +41 -45
  27. package/dist/LinearPileupDisplay/model.js +118 -41
  28. package/dist/LinearReadArcsDisplay/components/ReactComponent.js +1 -1
  29. package/dist/LinearReadArcsDisplay/model.d.ts +22 -21
  30. package/dist/LinearReadArcsDisplay/model.js +13 -14
  31. package/dist/LinearReadCloudDisplay/components/ReactComponent.js +1 -1
  32. package/dist/LinearReadCloudDisplay/model.d.ts +14 -22
  33. package/dist/LinearReadCloudDisplay/model.js +12 -13
  34. package/dist/LinearSNPCoverageDisplay/components/Tooltip.js +49 -19
  35. package/dist/LinearSNPCoverageDisplay/index.js +3 -2
  36. package/dist/LinearSNPCoverageDisplay/{models/model.d.ts → model.d.ts} +3 -13
  37. package/dist/LinearSNPCoverageDisplay/{models/model.js → model.js} +71 -45
  38. package/dist/MismatchParser/cigarToMismatches.d.ts +3 -0
  39. package/dist/MismatchParser/cigarToMismatches.js +94 -0
  40. package/dist/MismatchParser/getNextRefPos.d.ts +4 -0
  41. package/dist/MismatchParser/getNextRefPos.js +40 -0
  42. package/dist/MismatchParser/index.d.ts +4 -29
  43. package/dist/MismatchParser/index.js +10 -321
  44. package/dist/MismatchParser/mdToMismatches.d.ts +3 -0
  45. package/dist/MismatchParser/mdToMismatches.js +80 -0
  46. package/dist/ModificationParser/index.d.ts +19 -0
  47. package/dist/ModificationParser/index.js +144 -0
  48. package/dist/PileupRPC/methods/GetGlobalValueForTag.js +1 -2
  49. package/dist/PileupRPC/methods/GetReducedFeatures.d.ts +1 -1
  50. package/dist/PileupRPC/methods/GetReducedFeatures.js +19 -16
  51. package/dist/PileupRPC/methods/GetVisibleModifications.d.ts +2 -1
  52. package/dist/PileupRPC/methods/GetVisibleModifications.js +9 -6
  53. package/dist/PileupRenderer/PileupLayoutSession.d.ts +8 -7
  54. package/dist/PileupRenderer/PileupRenderer.d.ts +6 -14
  55. package/dist/PileupRenderer/PileupRenderer.js +7 -5
  56. package/dist/PileupRenderer/renderAlignment.js +17 -4
  57. package/dist/PileupRenderer/renderAlignmentShape.js +102 -21
  58. package/dist/PileupRenderer/renderMethylation.d.ts +2 -1
  59. package/dist/PileupRenderer/renderMethylation.js +17 -9
  60. package/dist/PileupRenderer/renderMismatches.js +19 -19
  61. package/dist/PileupRenderer/renderModifications.d.ts +3 -2
  62. package/dist/PileupRenderer/renderModifications.js +31 -34
  63. package/dist/PileupRenderer/renderPerBaseLettering.d.ts +2 -1
  64. package/dist/PileupRenderer/renderPerBaseLettering.js +1 -3
  65. package/dist/PileupRenderer/renderPerBaseQuality.d.ts +2 -1
  66. package/dist/PileupRenderer/renderPerBaseQuality.js +1 -3
  67. package/dist/PileupRenderer/renderSoftClipping.js +6 -6
  68. package/dist/PileupRenderer/sortUtil.d.ts +2 -7
  69. package/dist/PileupRenderer/sortUtil.js +13 -13
  70. package/dist/SNPCoverageAdapter/SNPCoverageAdapter.js +10 -5
  71. package/dist/SNPCoverageAdapter/generateCoverageBins.d.ts +13 -9
  72. package/dist/SNPCoverageAdapter/generateCoverageBins.js +269 -166
  73. package/dist/SNPCoverageRenderer/SNPCoverageRenderer.d.ts +2 -1
  74. package/dist/SNPCoverageRenderer/SNPCoverageRenderer.js +171 -54
  75. package/dist/shared/color.d.ts +0 -10
  76. package/dist/shared/color.js +1 -7
  77. package/{esm/shared → dist/shared/components}/BaseDisplayComponent.d.ts +2 -2
  78. package/{esm/shared → dist/shared/components}/FilterByTagDialog.d.ts +3 -3
  79. package/dist/shared/{FilterByTagDialog.js → components/FilterByTagDialog.js} +5 -1
  80. package/dist/shared/fetchChains.js +1 -2
  81. package/dist/shared/getMaximumModificationAtEachPosition.d.ts +8 -0
  82. package/dist/shared/getMaximumModificationAtEachPosition.js +42 -0
  83. package/dist/shared/getUniqueModifications.d.ts +14 -0
  84. package/dist/shared/getUniqueModifications.js +16 -0
  85. package/dist/shared/getUniqueTags.d.ts +15 -0
  86. package/dist/shared/getUniqueTags.js +18 -0
  87. package/dist/shared/types.d.ts +94 -0
  88. package/dist/shared/util.d.ts +8 -0
  89. package/dist/shared/util.js +26 -0
  90. package/dist/util.d.ts +7 -4
  91. package/dist/util.js +30 -30
  92. package/esm/AlignmentsFeatureDetail/AlignmentsFeatureDetail.js +2 -3
  93. package/esm/AlignmentsFeatureDetail/Flags.js +1 -1
  94. package/esm/AlignmentsFeatureDetail/LinkedPairedAlignments.js +1 -1
  95. package/esm/AlignmentsFeatureDetail/SupplementaryAlignments.js +1 -1
  96. package/esm/AlignmentsFeatureDetail/getSAFeatures.js +2 -2
  97. package/esm/AlignmentsFeatureDetail/stateModelFactory.d.ts +1 -1
  98. package/esm/BamAdapter/BamAdapter.d.ts +3 -2
  99. package/esm/BamAdapter/BamAdapter.js +31 -8
  100. package/esm/BamAdapter/BamSlightlyLazyFeature.d.ts +3 -17
  101. package/esm/BamAdapter/BamSlightlyLazyFeature.js +43 -73
  102. package/esm/CramAdapter/CramAdapter.d.ts +4 -3
  103. package/esm/CramAdapter/CramAdapter.js +22 -5
  104. package/esm/CramAdapter/CramSlightlyLazyFeature.d.ts +21 -27
  105. package/esm/CramAdapter/CramSlightlyLazyFeature.js +74 -73
  106. package/esm/CramAdapter/util.d.ts +1 -10
  107. package/esm/LinearAlignmentsDisplay/components/AlignmentsDisplay.d.ts +1 -1
  108. package/esm/LinearAlignmentsDisplay/index.js +2 -2
  109. package/esm/LinearAlignmentsDisplay/{models/model.d.ts → model.d.ts} +6 -3
  110. package/esm/LinearAlignmentsDisplay/{models/model.js → model.js} +11 -7
  111. package/esm/LinearPileupDisplay/SharedLinearPileupDisplayMixin.d.ts +6 -27
  112. package/esm/LinearPileupDisplay/SharedLinearPileupDisplayMixin.js +45 -23
  113. package/esm/LinearPileupDisplay/components/ColorByTagDialog.d.ts +5 -4
  114. package/esm/LinearPileupDisplay/components/ColorByTagDialog.js +3 -1
  115. package/esm/LinearPileupDisplay/components/GroupByDialog.js +8 -6
  116. package/esm/LinearPileupDisplay/components/SortByTagDialog.js +6 -4
  117. package/esm/LinearPileupDisplay/model.d.ts +41 -45
  118. package/esm/LinearPileupDisplay/model.js +119 -42
  119. package/esm/LinearReadArcsDisplay/components/ReactComponent.js +1 -1
  120. package/esm/LinearReadArcsDisplay/model.d.ts +22 -21
  121. package/esm/LinearReadArcsDisplay/model.js +14 -15
  122. package/esm/LinearReadCloudDisplay/components/ReactComponent.js +1 -1
  123. package/esm/LinearReadCloudDisplay/model.d.ts +14 -22
  124. package/esm/LinearReadCloudDisplay/model.js +13 -14
  125. package/esm/LinearSNPCoverageDisplay/components/Tooltip.js +49 -19
  126. package/esm/LinearSNPCoverageDisplay/index.js +3 -2
  127. package/esm/LinearSNPCoverageDisplay/{models/model.d.ts → model.d.ts} +3 -13
  128. package/esm/LinearSNPCoverageDisplay/{models/model.js → model.js} +72 -46
  129. package/esm/MismatchParser/cigarToMismatches.d.ts +3 -0
  130. package/esm/MismatchParser/cigarToMismatches.js +91 -0
  131. package/esm/MismatchParser/getNextRefPos.d.ts +4 -0
  132. package/esm/MismatchParser/getNextRefPos.js +37 -0
  133. package/esm/MismatchParser/index.d.ts +4 -29
  134. package/esm/MismatchParser/index.js +5 -311
  135. package/esm/MismatchParser/mdToMismatches.d.ts +3 -0
  136. package/esm/MismatchParser/mdToMismatches.js +77 -0
  137. package/esm/ModificationParser/index.d.ts +19 -0
  138. package/esm/ModificationParser/index.js +138 -0
  139. package/esm/PileupRPC/methods/GetGlobalValueForTag.js +1 -2
  140. package/esm/PileupRPC/methods/GetReducedFeatures.d.ts +1 -1
  141. package/esm/PileupRPC/methods/GetReducedFeatures.js +19 -16
  142. package/esm/PileupRPC/methods/GetVisibleModifications.d.ts +2 -1
  143. package/esm/PileupRPC/methods/GetVisibleModifications.js +9 -6
  144. package/esm/PileupRenderer/PileupLayoutSession.d.ts +8 -7
  145. package/esm/PileupRenderer/PileupRenderer.d.ts +6 -14
  146. package/esm/PileupRenderer/PileupRenderer.js +8 -6
  147. package/esm/PileupRenderer/renderAlignment.js +17 -4
  148. package/esm/PileupRenderer/renderAlignmentShape.js +102 -21
  149. package/esm/PileupRenderer/renderMethylation.d.ts +2 -1
  150. package/esm/PileupRenderer/renderMethylation.js +17 -9
  151. package/esm/PileupRenderer/renderMismatches.js +19 -19
  152. package/esm/PileupRenderer/renderModifications.d.ts +3 -2
  153. package/esm/PileupRenderer/renderModifications.js +30 -33
  154. package/esm/PileupRenderer/renderPerBaseLettering.d.ts +2 -1
  155. package/esm/PileupRenderer/renderPerBaseLettering.js +1 -3
  156. package/esm/PileupRenderer/renderPerBaseQuality.d.ts +2 -1
  157. package/esm/PileupRenderer/renderPerBaseQuality.js +1 -3
  158. package/esm/PileupRenderer/renderSoftClipping.js +6 -6
  159. package/esm/PileupRenderer/sortUtil.d.ts +2 -7
  160. package/esm/PileupRenderer/sortUtil.js +13 -13
  161. package/esm/SNPCoverageAdapter/SNPCoverageAdapter.js +10 -5
  162. package/esm/SNPCoverageAdapter/generateCoverageBins.d.ts +13 -9
  163. package/esm/SNPCoverageAdapter/generateCoverageBins.js +269 -166
  164. package/esm/SNPCoverageRenderer/SNPCoverageRenderer.d.ts +2 -1
  165. package/esm/SNPCoverageRenderer/SNPCoverageRenderer.js +171 -54
  166. package/esm/shared/color.d.ts +0 -10
  167. package/esm/shared/color.js +0 -6
  168. package/{dist/shared → esm/shared/components}/BaseDisplayComponent.d.ts +2 -2
  169. package/{dist/shared → esm/shared/components}/FilterByTagDialog.d.ts +3 -3
  170. package/esm/shared/{FilterByTagDialog.js → components/FilterByTagDialog.js} +5 -1
  171. package/esm/shared/fetchChains.js +1 -2
  172. package/esm/shared/getMaximumModificationAtEachPosition.d.ts +8 -0
  173. package/esm/shared/getMaximumModificationAtEachPosition.js +39 -0
  174. package/esm/shared/getUniqueModifications.d.ts +14 -0
  175. package/esm/shared/getUniqueModifications.js +13 -0
  176. package/esm/shared/getUniqueTags.d.ts +15 -0
  177. package/esm/shared/getUniqueTags.js +15 -0
  178. package/esm/shared/types.d.ts +94 -0
  179. package/esm/shared/util.d.ts +8 -0
  180. package/esm/shared/util.js +23 -0
  181. package/esm/util.d.ts +7 -4
  182. package/esm/util.js +28 -27
  183. package/package.json +4 -4
  184. package/dist/LinearPileupDisplay/components/ColorByModificationsDialog.d.ts +0 -15
  185. package/dist/LinearPileupDisplay/components/ColorByModificationsDialog.js +0 -41
  186. package/dist/LinearPileupDisplay/components/ModificationsTable.d.ts +0 -4
  187. package/dist/LinearPileupDisplay/components/ModificationsTable.js +0 -28
  188. package/dist/SNPCoverageAdapter/util.d.ts +0 -25
  189. package/dist/shared/index.d.ts +0 -49
  190. package/dist/shared/index.js +0 -41
  191. package/esm/LinearPileupDisplay/components/ColorByModificationsDialog.d.ts +0 -15
  192. package/esm/LinearPileupDisplay/components/ColorByModificationsDialog.js +0 -36
  193. package/esm/LinearPileupDisplay/components/ModificationsTable.d.ts +0 -4
  194. package/esm/LinearPileupDisplay/components/ModificationsTable.js +0 -22
  195. package/esm/SNPCoverageAdapter/util.d.ts +0 -25
  196. package/esm/shared/index.d.ts +0 -49
  197. package/esm/shared/index.js +0 -36
  198. /package/dist/LinearAlignmentsDisplay/{models/alignmentsModel.d.ts → alignmentsModel.d.ts} +0 -0
  199. /package/dist/LinearAlignmentsDisplay/{models/alignmentsModel.js → alignmentsModel.js} +0 -0
  200. /package/dist/LinearAlignmentsDisplay/{models/configSchema.d.ts → configSchema.d.ts} +0 -0
  201. /package/dist/LinearAlignmentsDisplay/{models/configSchema.js → configSchema.js} +0 -0
  202. /package/dist/LinearAlignmentsDisplay/{models/util.d.ts → util.d.ts} +0 -0
  203. /package/dist/LinearAlignmentsDisplay/{models/util.js → util.js} +0 -0
  204. /package/dist/LinearSNPCoverageDisplay/{models/configSchema.d.ts → configSchema.d.ts} +0 -0
  205. /package/dist/LinearSNPCoverageDisplay/{models/configSchema.js → configSchema.js} +0 -0
  206. /package/dist/shared/{BaseDisplayComponent.js → components/BaseDisplayComponent.js} +0 -0
  207. /package/dist/shared/{renderSvg.d.ts → renderSvgUtil.d.ts} +0 -0
  208. /package/dist/shared/{renderSvg.js → renderSvgUtil.js} +0 -0
  209. /package/dist/{SNPCoverageAdapter/util.js → shared/types.js} +0 -0
  210. /package/esm/LinearAlignmentsDisplay/{models/alignmentsModel.d.ts → alignmentsModel.d.ts} +0 -0
  211. /package/esm/LinearAlignmentsDisplay/{models/alignmentsModel.js → alignmentsModel.js} +0 -0
  212. /package/esm/LinearAlignmentsDisplay/{models/configSchema.d.ts → configSchema.d.ts} +0 -0
  213. /package/esm/LinearAlignmentsDisplay/{models/configSchema.js → configSchema.js} +0 -0
  214. /package/esm/LinearAlignmentsDisplay/{models/util.d.ts → util.d.ts} +0 -0
  215. /package/esm/LinearAlignmentsDisplay/{models/util.js → util.js} +0 -0
  216. /package/esm/LinearSNPCoverageDisplay/{models/configSchema.d.ts → configSchema.d.ts} +0 -0
  217. /package/esm/LinearSNPCoverageDisplay/{models/configSchema.js → configSchema.js} +0 -0
  218. /package/esm/shared/{BaseDisplayComponent.js → components/BaseDisplayComponent.js} +0 -0
  219. /package/esm/shared/{renderSvg.d.ts → renderSvgUtil.d.ts} +0 -0
  220. /package/esm/shared/{renderSvg.js → renderSvgUtil.js} +0 -0
  221. /package/esm/{SNPCoverageAdapter/util.js → shared/types.js} +0 -0
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = generateCoverageBins;
4
- const util_1 = require("../util");
3
+ exports.generateCoverageBins = generateCoverageBins;
4
+ const util_1 = require("@jbrowse/core/util");
5
+ // locals
5
6
  const MismatchParser_1 = require("../MismatchParser");
6
- const util_2 = require("@jbrowse/core/util");
7
+ const ModificationParser_1 = require("../ModificationParser");
8
+ const getMaximumModificationAtEachPosition_1 = require("../shared/getMaximumModificationAtEachPosition");
7
9
  function mismatchLen(mismatch) {
8
10
  return !isInterbase(mismatch.type) ? mismatch.length : 1;
9
11
  }
@@ -14,192 +16,293 @@ function inc(bin, strand, type, field) {
14
16
  let thisBin = bin[type][field];
15
17
  if (thisBin === undefined) {
16
18
  thisBin = bin[type][field] = {
17
- total: 0,
19
+ entryDepth: 0,
20
+ probabilities: [],
18
21
  '-1': 0,
19
22
  '0': 0,
20
23
  '1': 0,
21
24
  };
22
25
  }
23
- thisBin.total++;
26
+ thisBin.entryDepth++;
24
27
  thisBin[strand]++;
25
28
  }
26
- async function generateCoverageBins(features, region, opts, fetchSequence) {
27
- var _a, _b, _c;
28
- const { colorBy } = opts;
29
- const extendedRegion = {
30
- ...region,
31
- start: Math.max(0, region.start - 1),
32
- end: region.end + 1,
33
- };
34
- const binMax = Math.ceil(extendedRegion.end - extendedRegion.start);
35
- const skipmap = {};
36
- const regionSequence = features.length && (0, util_1.shouldFetchReferenceSequence)((_a = opts.colorBy) === null || _a === void 0 ? void 0 : _a.type)
37
- ? await fetchSequence(region)
38
- : undefined;
39
- const bins = [];
40
- for (const feature of features) {
41
- const fstart = feature.get('start');
42
- const fend = feature.get('end');
43
- const fstrand = feature.get('strand');
44
- const mismatches = feature.get('mismatches') || [];
45
- for (let j = fstart; j < fend + 1; j++) {
46
- const i = j - region.start;
47
- if (i >= 0 && i < binMax) {
48
- if (bins[i] === undefined) {
49
- bins[i] = {
50
- total: 0,
51
- all: 0,
52
- ref: 0,
29
+ function processDepth({ feature, bins, region, regionSequence, }) {
30
+ const fstart = feature.get('start');
31
+ const fend = feature.get('end');
32
+ const fstrand = feature.get('strand');
33
+ const regionLength = region.end - region.start;
34
+ for (let j = fstart; j < fend + 1; j++) {
35
+ const i = j - region.start;
36
+ if (i >= 0 && i < regionLength) {
37
+ if (bins[i] === undefined) {
38
+ bins[i] = {
39
+ depth: 0,
40
+ readsCounted: 0,
41
+ refbase: regionSequence[i],
42
+ ref: {
43
+ probabilities: [],
44
+ entryDepth: 0,
53
45
  '-1': 0,
54
- '0': 0,
55
- '1': 0,
56
- lowqual: {},
57
- cov: {},
58
- delskips: {},
59
- noncov: {},
60
- };
61
- }
62
- if (j !== fend) {
63
- bins[i].total++;
64
- bins[i].all++;
65
- bins[i].ref++;
66
- bins[i][fstrand]++;
67
- }
46
+ 0: 0,
47
+ 1: 0,
48
+ },
49
+ snps: {},
50
+ mods: {},
51
+ nonmods: {},
52
+ delskips: {},
53
+ noncov: {},
54
+ };
55
+ }
56
+ if (j !== fend) {
57
+ bins[i].depth++;
58
+ bins[i].readsCounted++;
59
+ bins[i].ref.entryDepth++;
60
+ bins[i].ref[fstrand]++;
68
61
  }
69
62
  }
70
- if ((colorBy === null || colorBy === void 0 ? void 0 : colorBy.type) === 'modifications') {
71
- const seq = feature.get('seq');
72
- const mm = (0, util_1.getTagAlt)(feature, 'MM', 'Mm') || '';
73
- const ops = (0, MismatchParser_1.parseCigar)(feature.get('CIGAR'));
74
- const fend = feature.get('end');
75
- if (seq) {
76
- const modifications = (0, MismatchParser_1.getModificationPositions)(mm, seq, fstrand);
77
- for (const { type, positions } of modifications) {
78
- const mod = `mod_${type}`;
79
- for (const pos of (0, MismatchParser_1.getNextRefPos)(ops, positions)) {
80
- const epos = pos + fstart - region.start;
81
- if (epos >= 0 && epos < bins.length && pos + fstart < fend) {
82
- if (bins[epos] === undefined) {
83
- bins[epos] = {
84
- total: 0,
85
- all: 0,
86
- ref: 0,
87
- '-1': 0,
88
- '0': 0,
89
- '1': 0,
90
- lowqual: {},
91
- cov: {},
92
- delskips: {},
93
- noncov: {},
94
- };
95
- }
96
- const bin = bins[epos];
97
- inc(bin, fstrand, 'cov', mod);
98
- }
99
- }
63
+ }
64
+ }
65
+ function processSNPs({ feature, region, bins, skipmap, }) {
66
+ var _a;
67
+ const fstart = feature.get('start');
68
+ const fstrand = feature.get('strand');
69
+ const mismatches = (_a = feature.get('mismatches')) !== null && _a !== void 0 ? _a : [];
70
+ // normal SNP based coloring
71
+ for (const mismatch of mismatches) {
72
+ const mstart = fstart + mismatch.start;
73
+ const mlen = mismatchLen(mismatch);
74
+ const mend = mstart + mlen;
75
+ for (let j = mstart; j < mstart + mlen; j++) {
76
+ const epos = j - region.start;
77
+ if (epos >= 0 && epos < bins.length) {
78
+ const bin = bins[epos];
79
+ const { base, type } = mismatch;
80
+ const interbase = isInterbase(type);
81
+ if (type === 'deletion' || type === 'skip') {
82
+ inc(bin, fstrand, 'delskips', type);
83
+ bin.depth--;
84
+ }
85
+ else if (!interbase) {
86
+ inc(bin, fstrand, 'snps', base);
87
+ bin.ref.entryDepth--;
88
+ bin.ref[fstrand]--;
89
+ }
90
+ else {
91
+ inc(bin, fstrand, 'noncov', type);
100
92
  }
101
93
  }
102
94
  }
103
- if ((colorBy === null || colorBy === void 0 ? void 0 : colorBy.type) === 'methylation') {
104
- if (!regionSequence) {
105
- throw new Error('no region sequence detected, need sequenceAdapter configuration');
95
+ if (mismatch.type === 'skip') {
96
+ // for upper case XS and TS: reports the literal strand of the genomic
97
+ // transcript
98
+ const tags = feature.get('tags');
99
+ const xs = (tags === null || tags === void 0 ? void 0 : tags.XS) || (tags === null || tags === void 0 ? void 0 : tags.TS);
100
+ // for lower case ts from minimap2: genomic transcript flipped by read
101
+ // strand
102
+ const ts = tags === null || tags === void 0 ? void 0 : tags.ts;
103
+ const effectiveStrand = xs === '+'
104
+ ? 1
105
+ : xs === '-'
106
+ ? -1
107
+ : (ts === '+' ? 1 : xs === '-' ? -1 : 0) * fstrand;
108
+ const hash = `${mstart}_${mend}_${effectiveStrand}`;
109
+ if (skipmap[hash] === undefined) {
110
+ skipmap[hash] = {
111
+ feature: feature,
112
+ start: mstart,
113
+ end: mend,
114
+ strand: fstrand,
115
+ effectiveStrand,
116
+ score: 0,
117
+ };
106
118
  }
107
- const seq = feature.get('seq');
108
- if (!seq) {
109
- continue;
110
- }
111
- const { methBins, methProbs } = (0, MismatchParser_1.getMethBins)(feature);
112
- const dels = mismatches.filter(f => f.type === 'deletion');
113
- // methylation based coloring takes into account both reference sequence
114
- // CpG detection and reads
115
- for (let i = 0; i < fend - fstart; i++) {
116
- const j = i + fstart;
117
- const l1 = (_b = regionSequence[j - region.start + 1]) === null || _b === void 0 ? void 0 : _b.toLowerCase();
118
- const l2 = (_c = regionSequence[j - region.start + 2]) === null || _c === void 0 ? void 0 : _c.toLowerCase();
119
- if (l1 === 'c' && l2 === 'g') {
120
- const bin0 = bins[j - region.start];
121
- const bin1 = bins[j - region.start + 1];
122
- const b0 = methBins[i];
123
- const b1 = methBins[i + 1];
124
- const p0 = methProbs[i];
125
- const p1 = methProbs[i + 1];
126
- // color
127
- if ((b0 && (p0 !== undefined ? p0 > 0.5 : true)) ||
128
- (b1 && (p1 !== undefined ? p1 > 0.5 : true))) {
129
- if (bin0) {
130
- inc(bin0, fstrand, 'cov', 'meth');
131
- bin0.ref--;
132
- bin0[fstrand]--;
133
- }
134
- if (bin1) {
135
- inc(bin1, fstrand, 'cov', 'meth');
136
- bin1.ref--;
137
- bin1[fstrand]--;
138
- }
119
+ skipmap[hash].score++;
120
+ }
121
+ }
122
+ }
123
+ function processReferenceCpGs({ feature, region, bins, regionSequence, }) {
124
+ var _a;
125
+ const fstart = feature.get('start');
126
+ const fend = feature.get('end');
127
+ const fstrand = feature.get('strand');
128
+ const seq = feature.get('seq');
129
+ const mismatches = (_a = feature.get('mismatches')) !== null && _a !== void 0 ? _a : [];
130
+ const r = regionSequence.toLowerCase();
131
+ if (seq) {
132
+ const cigarOps = (0, MismatchParser_1.parseCigar)(feature.get('CIGAR'));
133
+ const { methBins, methProbs } = (0, ModificationParser_1.getMethBins)(feature, cigarOps);
134
+ const dels = mismatches.filter(f => f.type === 'deletion');
135
+ // methylation based coloring takes into account both reference sequence
136
+ // CpG detection and reads
137
+ for (let i = 0; i < fend - fstart; i++) {
138
+ const j = i + fstart;
139
+ const l1 = r[j - region.start + 1];
140
+ const l2 = r[j - region.start + 2];
141
+ if (l1 === 'c' && l2 === 'g') {
142
+ const bin0 = bins[j - region.start];
143
+ const bin1 = bins[j - region.start + 1];
144
+ const b0 = methBins[i];
145
+ const b1 = methBins[i + 1];
146
+ const p0 = methProbs[i];
147
+ const p1 = methProbs[i + 1];
148
+ // color
149
+ if ((b0 && (p0 !== undefined ? p0 > 0.5 : true)) ||
150
+ (b1 && (p1 !== undefined ? p1 > 0.5 : true))) {
151
+ if (bin0) {
152
+ incWithProbabilities(bin0, fstrand, 'mods', 'cpg_meth', p0 || 0);
153
+ bin0.ref.entryDepth--;
154
+ bin0.ref[fstrand]--;
139
155
  }
140
- else {
141
- if (bin0) {
142
- if (!dels.some(d => (0, util_2.doesIntersect2)(j, j + 1, d.start + fstart, d.start + fstart + d.length))) {
143
- inc(bin0, fstrand, 'cov', 'unmeth');
144
- bin0.ref--;
145
- bin0[fstrand]--;
146
- }
156
+ if (bin1) {
157
+ incWithProbabilities(bin1, fstrand, 'mods', 'cpg_meth', p1 || 0);
158
+ bin1.ref.entryDepth--;
159
+ bin1.ref[fstrand]--;
160
+ }
161
+ }
162
+ else {
163
+ if (bin0) {
164
+ if (!dels.some(d => (0, util_1.doesIntersect2)(j, j + 1, d.start + fstart, d.start + fstart + d.length))) {
165
+ incWithProbabilities(bin0, fstrand, 'nonmods', 'cpg_unmeth', 1 - (p0 || 0));
166
+ bin0.ref.entryDepth--;
167
+ bin0.ref[fstrand]--;
147
168
  }
148
- if (bin1) {
149
- if (!dels.some(d => (0, util_2.doesIntersect2)(j + 1, j + 2, d.start + fstart, d.start + fstart + d.length))) {
150
- inc(bin1, fstrand, 'cov', 'unmeth');
151
- bin1.ref--;
152
- bin1[fstrand]--;
153
- }
169
+ }
170
+ if (bin1) {
171
+ if (!dels.some(d => (0, util_1.doesIntersect2)(j + 1, j + 2, d.start + fstart, d.start + fstart + d.length))) {
172
+ incWithProbabilities(bin1, fstrand, 'nonmods', 'cpg_unmeth', 1 - (p1 || 0));
173
+ bin1.ref.entryDepth--;
174
+ bin1.ref[fstrand]--;
154
175
  }
155
176
  }
156
177
  }
157
178
  }
158
179
  }
159
- // normal SNP based coloring
160
- const colorSNPs = (colorBy === null || colorBy === void 0 ? void 0 : colorBy.type) !== 'modifications' && (colorBy === null || colorBy === void 0 ? void 0 : colorBy.type) !== 'methylation';
161
- for (const mismatch of mismatches) {
162
- const mstart = fstart + mismatch.start;
163
- const mlen = mismatchLen(mismatch);
164
- const mend = mstart + mlen;
165
- for (let j = mstart; j < mstart + mlen; j++) {
166
- const epos = j - region.start;
167
- if (epos >= 0 && epos < bins.length) {
168
- const bin = bins[epos];
169
- const { base, type } = mismatch;
170
- const interbase = isInterbase(type);
171
- if (!interbase) {
172
- bin.ref--;
173
- bin[fstrand]--;
174
- }
175
- else {
176
- inc(bin, fstrand, 'noncov', type);
177
- }
178
- if (type === 'deletion' || type === 'skip') {
179
- inc(bin, fstrand, 'delskips', type);
180
- bin.total--;
181
- }
182
- else if (!interbase && colorSNPs) {
183
- inc(bin, fstrand, 'cov', base);
184
- bin.refbase = mismatch.altbase;
185
- }
186
- }
180
+ }
181
+ }
182
+ function processModification({ feature, colorBy, region, bins, regionSequence, }) {
183
+ var _a, _b, _c;
184
+ const fstart = feature.get('start');
185
+ const fstrand = feature.get('strand');
186
+ const fend = feature.get('end');
187
+ const twoColor = (_a = colorBy === null || colorBy === void 0 ? void 0 : colorBy.modifications) === null || _a === void 0 ? void 0 : _a.twoColor;
188
+ const isolatedModification = (_b = colorBy === null || colorBy === void 0 ? void 0 : colorBy.modifications) === null || _b === void 0 ? void 0 : _b.isolatedModification;
189
+ (_c = (0, getMaximumModificationAtEachPosition_1.getMaxProbModAtEachPosition)(feature)) === null || _c === void 0 ? void 0 : _c.forEach(({ type, prob, allProbs }, pos) => {
190
+ if (isolatedModification && type !== isolatedModification) {
191
+ return;
192
+ }
193
+ const epos = pos + fstart - region.start;
194
+ if (epos >= 0 && epos < bins.length && pos + fstart < fend) {
195
+ if (bins[epos] === undefined) {
196
+ bins[epos] = {
197
+ depth: 0,
198
+ readsCounted: 0,
199
+ refbase: regionSequence[epos],
200
+ snps: {},
201
+ ref: {
202
+ probabilities: [],
203
+ entryDepth: 0,
204
+ '-1': 0,
205
+ 0: 0,
206
+ 1: 0,
207
+ },
208
+ mods: {},
209
+ nonmods: {},
210
+ delskips: {},
211
+ noncov: {},
212
+ };
187
213
  }
188
- if (mismatch.type === 'skip') {
189
- const hash = `${mstart}_${mend}_${fstrand}`;
190
- if (skipmap[hash] === undefined) {
191
- skipmap[hash] = {
192
- feature: feature,
193
- start: mstart,
194
- end: mend,
195
- strand: fstrand,
196
- xs: (0, util_1.getTag)(feature, 'XS') || (0, util_1.getTag)(feature, 'TS'),
197
- score: 0,
198
- };
199
- }
200
- skipmap[hash].score++;
214
+ const s = 1 - (0, util_1.sum)(allProbs);
215
+ const bin = bins[epos];
216
+ if (twoColor && s > (0, util_1.max)(allProbs)) {
217
+ incWithProbabilities(bin, fstrand, 'nonmods', `nonmod_${type}`, s);
218
+ }
219
+ else {
220
+ incWithProbabilities(bin, fstrand, 'mods', `mod_${type}`, prob);
201
221
  }
202
222
  }
223
+ });
224
+ }
225
+ function incWithProbabilities(bin, strand, type, field, probability) {
226
+ let thisBin = bin[type][field];
227
+ if (thisBin === undefined) {
228
+ thisBin = bin[type][field] = {
229
+ entryDepth: 0,
230
+ probabilities: [],
231
+ '-1': 0,
232
+ '0': 0,
233
+ '1': 0,
234
+ };
203
235
  }
204
- return { bins, skipmap };
236
+ thisBin.entryDepth++;
237
+ thisBin.probabilities.push(probability);
238
+ thisBin[strand]++;
239
+ }
240
+ async function generateCoverageBins({ fetchSequence, features, region, opts, }) {
241
+ const { colorBy } = opts;
242
+ const skipmap = {};
243
+ const bins = [];
244
+ const start2 = Math.max(0, region.start - 1);
245
+ const diff = region.start - start2;
246
+ const regionSequence = (await fetchSequence({
247
+ ...region,
248
+ start: start2,
249
+ end: region.end + 1,
250
+ })) || '';
251
+ for (const feature of features) {
252
+ processDepth({
253
+ feature,
254
+ bins,
255
+ region,
256
+ regionSequence: regionSequence.slice(diff),
257
+ });
258
+ if ((colorBy === null || colorBy === void 0 ? void 0 : colorBy.type) === 'modifications') {
259
+ processModification({
260
+ feature,
261
+ colorBy,
262
+ bins,
263
+ region,
264
+ regionSequence: regionSequence.slice(diff),
265
+ });
266
+ }
267
+ else if ((colorBy === null || colorBy === void 0 ? void 0 : colorBy.type) === 'methylation') {
268
+ processReferenceCpGs({
269
+ feature,
270
+ bins,
271
+ region,
272
+ regionSequence,
273
+ });
274
+ }
275
+ processSNPs({ feature, skipmap, bins, region });
276
+ }
277
+ for (const bin of bins) {
278
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
279
+ if (bin) {
280
+ bin.mods = Object.fromEntries(Object.entries(bin.mods).map(([key, val]) => {
281
+ return [
282
+ key,
283
+ {
284
+ ...val,
285
+ avgProbability: val.probabilities.length
286
+ ? (0, util_1.sum)(val.probabilities) / val.probabilities.length
287
+ : undefined,
288
+ },
289
+ ];
290
+ }));
291
+ bin.nonmods = Object.fromEntries(Object.entries(bin.nonmods).map(([key, val]) => {
292
+ return [
293
+ key,
294
+ {
295
+ ...val,
296
+ avgProbability: val.probabilities.length
297
+ ? (0, util_1.sum)(val.probabilities) / val.probabilities.length
298
+ : undefined,
299
+ },
300
+ ];
301
+ }));
302
+ }
303
+ }
304
+ return {
305
+ bins,
306
+ skipmap,
307
+ };
205
308
  }
@@ -1,6 +1,7 @@
1
1
  import { Feature } from '@jbrowse/core/util';
2
2
  import { RenderArgsDeserialized as FeatureRenderArgsDeserialized } from '@jbrowse/core/pluggableElementTypes/renderers/FeatureRendererType';
3
3
  import { ScaleOpts, WiggleBaseRenderer } from '@jbrowse/plugin-wiggle';
4
+ import { ModificationTypeWithColor } from '../shared/types';
4
5
  export interface RenderArgsDeserialized extends FeatureRenderArgsDeserialized {
5
6
  bpPerPx: number;
6
7
  height: number;
@@ -13,7 +14,7 @@ export interface RenderArgsDeserializedWithFeatures extends RenderArgsDeserializ
13
14
  values: number[];
14
15
  };
15
16
  displayCrossHatches: boolean;
16
- modificationTagMap?: Record<string, string>;
17
+ visibleModifications?: Record<string, ModificationTypeWithColor>;
17
18
  }
18
19
  export default class SNPCoverageRenderer extends WiggleBaseRenderer {
19
20
  draw(ctx: CanvasRenderingContext2D, props: RenderArgsDeserializedWithFeatures): Promise<undefined>;