@teselagen/ove 0.8.39 → 0.8.41

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.
@@ -88,19 +88,44 @@ function addHighlightedDifferences(alignmentTracks) {
88
88
  );
89
89
  // .filter by the user-specified mismatch overrides (initially [])
90
90
  const mismatches = matchHighlightRanges.filter(({ isMatch }) => !isMatch);
91
+
92
+ // Compute non-aligned (gap) regions from leading/trailing dashes
93
+ const alignedSeq = track.alignmentData.sequence;
94
+ const seqLen = alignedSeq.length;
95
+ const startIndex = seqLen - alignedSeq.replace(/^-+/, "").length;
96
+ const endIndex = alignedSeq.replace(/-+$/, "").length;
97
+ const gapRanges = [
98
+ startIndex > 0 && {
99
+ start: 0,
100
+ end: startIndex - 1,
101
+ differenceType: "gap"
102
+ },
103
+ endIndex < seqLen && {
104
+ start: endIndex,
105
+ end: seqLen - 1,
106
+ differenceType: "gap"
107
+ }
108
+ ].filter(Boolean);
109
+
91
110
  return {
92
111
  ...track,
93
112
  sequenceData,
94
113
  matchHighlightRanges,
95
- additionalSelectionLayers: matchHighlightRanges
96
- .filter(({ isMatch }) => !isMatch)
97
- .map(range => {
98
- return {
114
+ additionalSelectionLayers: [
115
+ ...matchHighlightRanges
116
+ .filter(({ isMatch }) => !isMatch)
117
+ .map(range => ({
99
118
  ...range,
100
119
  ...highlightRangeProps,
101
120
  className: "veAlignmentMismatch"
102
- };
103
- }),
121
+ })),
122
+ ...gapRanges.map(range => ({
123
+ ...range,
124
+ ...highlightRangeProps,
125
+ className: "veAlignmentMismatch"
126
+ }))
127
+ ],
128
+ gapRanges,
104
129
  mismatches
105
130
  };
106
131
  });
@@ -271,39 +296,52 @@ export default (state = {}, { payload = {}, type }) => {
271
296
  return state;
272
297
  };
273
298
 
274
- //returns an array like so: [{start: 0, end: 4, isMatch: false}, {start,end,isMatch} ... etc]
299
+ //returns an array like so: [{start: 0, end: 4, isMatch: false, differenceType: "mismatch"}, ...]
300
+ // differenceType is one of: "mismatch" | "insertion" | "deletion" | null (for match ranges)
275
301
  function getRangeMatchesBetweenTemplateAndNonTemplate(tempSeq, nonTempSeq) {
276
302
  //assume all sequences are the same length (with gap characters "-" in some places)
277
303
  //loop through all non template sequences and compare them with the template
278
304
 
279
305
  const seqLength = nonTempSeq.length;
280
306
  const ranges = [];
281
- // const startIndex = "".match/[-]/ Math.max(0, .indexOf("-"));
282
307
  const nonTempSeqWithoutLeadingDashes = nonTempSeq.replace(/^-+/g, "");
283
308
  const nonTempSeqWithoutTrailingDashes = nonTempSeq.replace(/-+$/g, "");
284
309
 
285
310
  const startIndex = seqLength - nonTempSeqWithoutLeadingDashes.length;
286
311
  const endIndex =
287
312
  seqLength - (seqLength - nonTempSeqWithoutTrailingDashes.length);
313
+
288
314
  for (let index = startIndex; index < endIndex; index++) {
289
- const isMatch =
290
- tempSeq[index].toLowerCase() === nonTempSeq[index].toLowerCase();
291
- const previousRange = ranges[ranges.length - 1];
292
- if (previousRange) {
293
- if (previousRange.isMatch === isMatch) {
294
- previousRange.end++;
315
+ const tempBase = tempSeq[index].toLowerCase();
316
+ const nonTempBase = nonTempSeq[index].toLowerCase();
317
+ const isMatch = tempBase === nonTempBase;
318
+
319
+ let differenceType = null;
320
+ if (!isMatch) {
321
+ if (tempBase === "-") {
322
+ differenceType = "insertion";
323
+ } else if (nonTempBase === "-") {
324
+ differenceType = "deletion";
295
325
  } else {
296
- ranges.push({
297
- start: index,
298
- end: index,
299
- isMatch
300
- });
326
+ differenceType = "mismatch";
301
327
  }
328
+ }
329
+
330
+ const previousRange = ranges[ranges.length - 1];
331
+ if (
332
+ previousRange &&
333
+ previousRange.isMatch === isMatch &&
334
+ previousRange.differenceType === differenceType
335
+ ) {
336
+ previousRange.end++;
337
+ } else if (previousRange) {
338
+ ranges.push({ start: index, end: index, isMatch, differenceType });
302
339
  } else {
303
340
  ranges.push({
304
341
  start: startIndex,
305
342
  end: startIndex,
306
- isMatch
343
+ isMatch,
344
+ differenceType
307
345
  });
308
346
  }
309
347
  }