@teselagen/range-utils 0.3.7 → 0.3.9

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 (96) hide show
  1. package/README.md +94 -0
  2. package/flipContainedRange.d.ts +1 -1
  3. package/index.cjs +2619 -0
  4. package/index.d.ts +52 -51
  5. package/index.js +1791 -6100
  6. package/index.umd.cjs +2623 -0
  7. package/package.json +2 -3
  8. package/src/adjustRangeToDeletionOfAnotherRange.test.js +166 -105
  9. package/src/adjustRangeToInsert.js +29 -26
  10. package/src/adjustRangeToInsert.test.js +197 -109
  11. package/src/adjustRangeToRotation.js +4 -5
  12. package/src/adjustRangeToRotation.test.js +203 -119
  13. package/src/checkIfNonCircularRangesOverlap.js +18 -15
  14. package/src/checkIfNonCircularRangesOverlap.test.js +67 -42
  15. package/src/checkIfPotentiallyCircularRangesOverlap.js +22 -12
  16. package/src/checkIfPotentiallyCircularRangesOverlap.test.js +115 -70
  17. package/src/collapseOverlapsGeneratedFromRangeComparisonIfPossible.js +72 -41
  18. package/src/collapseOverlapsGeneratedFromRangeComparisonIfPossible.test.js +183 -84
  19. package/src/convertRangeIndices.js +24 -20
  20. package/src/convertRangeIndices.test.js +40 -21
  21. package/src/convertRangeTo0Based.js +7 -4
  22. package/src/convertRangeTo1Based.js +8 -4
  23. package/src/doesRangeSpanEntireSequence.js +4 -4
  24. package/src/doesRangeSpanOrigin.js +3 -3
  25. package/src/expandOrContractCircularRangeToPosition.js +45 -38
  26. package/src/expandOrContractNonCircularRangeToPosition.js +24 -21
  27. package/src/expandOrContractRangeByLength.js +16 -11
  28. package/src/expandOrContractRangeByLength.test.js +109 -71
  29. package/src/expandOrContractRangeToPosition.js +17 -9
  30. package/src/flipContainedRange.js +133 -72
  31. package/src/flipContainedRange.test.js +143 -117
  32. package/src/generateRandomRange.js +17 -15
  33. package/src/generateRandomRange.test.js +21 -21
  34. package/src/getAnnotationRangeType.js +25 -21
  35. package/src/getAnnotationRangeType.test.js +56 -57
  36. package/src/getEachPositionInRangeAsArray.js +13 -13
  37. package/src/getEachPositionInRangeAsArray.test.js +12 -8
  38. package/src/getLengthOfOverlappingRegionsBetweenTwoRanges.js +16 -8
  39. package/src/getLengthOfOverlappingRegionsBetweenTwoRanges.test.js +32 -24
  40. package/src/getMiddleOfRange.js +1 -1
  41. package/src/getMiddleOfRange.test.js +5 -13
  42. package/src/getOverlapOfNonCircularRanges.js +30 -30
  43. package/src/getOverlapsOfPotentiallyCircularRanges.js +5 -5
  44. package/src/getOverlapsOfPotentiallyCircularRanges.test.js +3 -23
  45. package/src/getPositionFromAngle.js +12 -7
  46. package/src/getRangeAngles.js +1 -1
  47. package/src/getRangeAngles.test.js +10 -11
  48. package/src/getRangeLength.test.js +5 -5
  49. package/src/getRangesBetweenTwoRanges.js +31 -22
  50. package/src/getSequenceWithinRange.js +13 -13
  51. package/src/getSequenceWithinRange.test.js +43 -45
  52. package/src/getShortestDistanceBetweenTwoPositions.js +10 -6
  53. package/src/getShortestDistanceBetweenTwoPositions.test.js +11 -13
  54. package/src/getYOffsetForPotentiallyCircularRange.js +33 -21
  55. package/src/getYOffsetsForPotentiallyCircularRanges.js +26 -19
  56. package/src/getYOffsetsForPotentiallyCircularRanges.test.js +42 -29
  57. package/src/getZeroedRangeOverlaps.js +30 -15
  58. package/src/getZeroedRangeOverlaps.test.js +75 -36
  59. package/src/index.js +52 -51
  60. package/src/index.test.js +6 -8
  61. package/src/invertRange.test.js +103 -93
  62. package/src/isPositionCloserToRangeStartThanRangeEnd.js +18 -6
  63. package/src/isPositionCloserToRangeStartThanRangeEnd.test.js +36 -16
  64. package/src/isPositionWithinRange.js +4 -4
  65. package/src/isRangeOrPositionWithinRange.js +18 -12
  66. package/src/isRangeOrPositionWithinRange.test.js +6 -6
  67. package/src/isRangeWithinRange.js +2 -3
  68. package/src/loopEachPositionInRange.js +3 -3
  69. package/src/modulatePositionByRange.js +8 -8
  70. package/src/modulatePositionByRange.test.js +10 -11
  71. package/src/modulateRangeBySequenceLength.js +7 -7
  72. package/src/modulateRangeBySequenceLength.test.js +39 -16
  73. package/src/normalizePositionByRangeLength.js +22 -18
  74. package/src/normalizePositionByRangeLength.test.js +23 -23
  75. package/src/normalizePositionByRangeLength1Based.js +7 -4
  76. package/src/normalizePositionByRangeLength1Based.test.js +9 -9
  77. package/src/normalizeRange.js +7 -7
  78. package/src/normalizeRange.test.js +9 -9
  79. package/src/provideInclusiveOptions.js +36 -23
  80. package/src/reversePositionInRange.js +16 -12
  81. package/src/splitRangeIntoTwoPartsIfItIsCircular.js +31 -28
  82. package/src/splitRangeIntoTwoPartsIfItIsCircular.test.js +22 -11
  83. package/src/translateRange.js +18 -8
  84. package/src/translateRange.test.js +18 -19
  85. package/src/trimAnnStartEndToFitSeqLength.js +9 -0
  86. package/src/trimAnnStartEndToFitSeqLength.test.js +35 -0
  87. package/src/trimNonCicularRangeByAnotherNonCircularRange.js +45 -42
  88. package/src/trimNumberToFitWithin0ToAnotherNumber.js +13 -10
  89. package/src/trimRangeByAnotherRange.js +20 -19
  90. package/src/trimRangeByAnotherRange.test.js +6 -6
  91. package/src/zeroSubrangeByContainerRange.js +29 -19
  92. package/src/zeroSubrangeByContainerRange.test.js +57 -47
  93. package/trimAnnStartEndToFitSeqLength.d.ts +1 -0
  94. package/trimAnnStartEndToFitSeqLength.test.d.ts +1 -0
  95. package/index.mjs +0 -6928
  96. package/index.umd.js +0 -6932
@@ -1,17 +1,17 @@
1
1
  //
2
2
  export default function getSequenceWithinRange(range, sequence) {
3
- // ac.throw([ac.range, ac.oneOfType([ac.array, ac.string])], arguments);
4
- if (range.start < 0 || range.end < 0) return ''
5
- if (range.start > range.end) {
6
- //circular range
7
- let subSequence = sequence.slice(range.start, sequence.length);
8
- if (typeof subSequence === 'string') {
9
- subSequence += sequence.slice(0, range.end + 1);
10
- } else {
11
- subSequence = subSequence.concat(sequence.slice(0, range.end + 1));
12
- }
13
- return subSequence;
3
+ // ac.throw([ac.range, ac.oneOfType([ac.array, ac.string])], arguments);
4
+ if (range.start < 0 || range.end < 0) return "";
5
+ if (range.start > range.end) {
6
+ //circular range
7
+ let subSequence = sequence.slice(range.start, sequence.length);
8
+ if (typeof subSequence === "string") {
9
+ subSequence += sequence.slice(0, range.end + 1);
14
10
  } else {
15
- return sequence.slice(range.start, range.end + 1);
11
+ subSequence = subSequence.concat(sequence.slice(0, range.end + 1));
16
12
  }
17
- };
13
+ return subSequence;
14
+ } else {
15
+ return sequence.slice(range.start, range.end + 1);
16
+ }
17
+ }
@@ -1,49 +1,47 @@
1
+ import getSequenceWithinRange from "./getSequenceWithinRange.js";
1
2
 
2
-
3
- import getSequenceWithinRange from './getSequenceWithinRange.js';
4
-
5
- import assert from 'assert';
3
+ import assert from "assert";
6
4
  let subseq;
7
5
 
8
- describe('getSequenceWithinRange', function() {
9
- it('works with an array (translation amino acids for example) as well', function() {
10
- subseq = getSequenceWithinRange({start: 0,end:0},['a','t','g','c']);
11
- assert.deepEqual(subseq, ['a']);
12
- subseq = getSequenceWithinRange({start: 1,end:1},['a','t','g','c']);
13
- assert.deepEqual(subseq, ['t']);
14
- subseq = getSequenceWithinRange({start: 1,end:0},['a','t','g','c']);
15
- assert.deepEqual(subseq, ['t','g','c','a']);
16
- });
17
- it('gets a non circular range', function() {
18
- subseq = getSequenceWithinRange({start: 0,end:0},'atgc');
19
- assert.equal(subseq, 'a');
20
- subseq = getSequenceWithinRange({start: 1,end:1},'atgc');
21
- assert.equal(subseq, 't');
22
- subseq = getSequenceWithinRange({start: 0,end:3},'atgc');
23
- assert.equal(subseq, 'atgc');
24
- });
25
- it('gets a circular range', function() {
26
- subseq = getSequenceWithinRange({start: 1,end:0},'atgc');
27
- assert.deepEqual(subseq, 'tgca');
28
- subseq = getSequenceWithinRange({start: 2,end:1},'atgc');
29
- assert.deepEqual(subseq, 'gcat');
30
- subseq = getSequenceWithinRange({start: 3,end:0},'atgc');
31
- assert.deepEqual(subseq, 'ca');
32
- });
33
- it('gets a circular range', function() {
34
- subseq = getSequenceWithinRange({start: 1,end:0},'atgc');
35
- assert.deepEqual(subseq, 'tgca');
36
- subseq = getSequenceWithinRange({start: 2,end:1},'atgc');
37
- assert.deepEqual(subseq, 'gcat');
38
- subseq = getSequenceWithinRange({start: 3,end:0},'atgc');
39
- assert.deepEqual(subseq, 'ca');
40
- });
41
- it('returns an empty string if the range is invalid', function() {
42
- subseq = getSequenceWithinRange({start: -1,end:0},'atgc');
43
- assert.deepEqual(subseq, '');
44
- subseq = getSequenceWithinRange({start: -1,end:-1},'atgc');
45
- assert.deepEqual(subseq, '');
46
- subseq = getSequenceWithinRange({start: 3,end:-1},'atgc');
47
- assert.deepEqual(subseq, '');
48
- });
6
+ describe("getSequenceWithinRange", function () {
7
+ it("works with an array (translation amino acids for example) as well", function () {
8
+ subseq = getSequenceWithinRange({ start: 0, end: 0 }, ["a", "t", "g", "c"]);
9
+ assert.deepEqual(subseq, ["a"]);
10
+ subseq = getSequenceWithinRange({ start: 1, end: 1 }, ["a", "t", "g", "c"]);
11
+ assert.deepEqual(subseq, ["t"]);
12
+ subseq = getSequenceWithinRange({ start: 1, end: 0 }, ["a", "t", "g", "c"]);
13
+ assert.deepEqual(subseq, ["t", "g", "c", "a"]);
14
+ });
15
+ it("gets a non circular range", function () {
16
+ subseq = getSequenceWithinRange({ start: 0, end: 0 }, "atgc");
17
+ assert.equal(subseq, "a");
18
+ subseq = getSequenceWithinRange({ start: 1, end: 1 }, "atgc");
19
+ assert.equal(subseq, "t");
20
+ subseq = getSequenceWithinRange({ start: 0, end: 3 }, "atgc");
21
+ assert.equal(subseq, "atgc");
22
+ });
23
+ it("gets a circular range", function () {
24
+ subseq = getSequenceWithinRange({ start: 1, end: 0 }, "atgc");
25
+ assert.deepEqual(subseq, "tgca");
26
+ subseq = getSequenceWithinRange({ start: 2, end: 1 }, "atgc");
27
+ assert.deepEqual(subseq, "gcat");
28
+ subseq = getSequenceWithinRange({ start: 3, end: 0 }, "atgc");
29
+ assert.deepEqual(subseq, "ca");
30
+ });
31
+ it("gets a circular range", function () {
32
+ subseq = getSequenceWithinRange({ start: 1, end: 0 }, "atgc");
33
+ assert.deepEqual(subseq, "tgca");
34
+ subseq = getSequenceWithinRange({ start: 2, end: 1 }, "atgc");
35
+ assert.deepEqual(subseq, "gcat");
36
+ subseq = getSequenceWithinRange({ start: 3, end: 0 }, "atgc");
37
+ assert.deepEqual(subseq, "ca");
38
+ });
39
+ it("returns an empty string if the range is invalid", function () {
40
+ subseq = getSequenceWithinRange({ start: -1, end: 0 }, "atgc");
41
+ assert.deepEqual(subseq, "");
42
+ subseq = getSequenceWithinRange({ start: -1, end: -1 }, "atgc");
43
+ assert.deepEqual(subseq, "");
44
+ subseq = getSequenceWithinRange({ start: 3, end: -1 }, "atgc");
45
+ assert.deepEqual(subseq, "");
46
+ });
49
47
  });
@@ -1,12 +1,16 @@
1
- export default function getShortestDistanceBetweenTwoPositions(position1, position2, sequenceLength) {
1
+ export default function getShortestDistanceBetweenTwoPositions(
2
+ position1,
3
+ position2,
4
+ sequenceLength
5
+ ) {
2
6
  if (position1 < position2) {
3
- const position1Holder = position1;
4
- position1 = position2
5
- position2 = position1Holder
7
+ const position1Holder = position1;
8
+ position1 = position2;
9
+ position2 = position1Holder;
6
10
  }
7
11
  //position 1 is now always >= position 2
8
12
 
9
13
  const d1 = position1 - position2;
10
14
  const d2 = sequenceLength - position1 + position2;
11
- return Math.min(d1,d2)
12
- };
15
+ return Math.min(d1, d2);
16
+ }
@@ -1,14 +1,12 @@
1
- import assert from 'assert';
2
- import getShortestDistanceBetweenTwoPositions from './getShortestDistanceBetweenTwoPositions';
3
- describe('getShortestDistanceBetweenTwoPositions', function () {
4
- it('should return the correct length for positions that cross the origin', function () {
5
- const length = getShortestDistanceBetweenTwoPositions(9,0,10);
6
- assert(length === 1)
7
-
8
- });
9
- it('should return the correct length for ranges that do not cross the origin', function () {
10
- const length = getShortestDistanceBetweenTwoPositions(4,6,10);
11
- assert(length === 2)
12
-
13
- });
1
+ import assert from "assert";
2
+ import getShortestDistanceBetweenTwoPositions from "./getShortestDistanceBetweenTwoPositions";
3
+ describe("getShortestDistanceBetweenTwoPositions", function () {
4
+ it("should return the correct length for positions that cross the origin", function () {
5
+ const length = getShortestDistanceBetweenTwoPositions(9, 0, 10);
6
+ assert(length === 1);
7
+ });
8
+ it("should return the correct length for ranges that do not cross the origin", function () {
9
+ const length = getShortestDistanceBetweenTwoPositions(4, 6, 10);
10
+ assert(length === 2);
11
+ });
14
12
  });
@@ -1,24 +1,36 @@
1
- import checkIfPotentiallyCircularRangesOverlap from './checkIfPotentiallyCircularRangesOverlap';
1
+ import checkIfPotentiallyCircularRangesOverlap from "./checkIfPotentiallyCircularRangesOverlap";
2
2
 
3
- export default function getYOffsetForPotentiallyCircularRange(range, YOffsetLevelsWithRanges, assignYOffsetToRange) {
4
- //adjust the yOffset of the range being pushed in by checking its range against other range already in the row
5
- let yOffset = [];
6
- //YOffsetLevelsWithRanges is an array of arrays (array of yOffset levels holding arrays of range)
7
- //loop through y offset levels starting with the 0 level until an empty one is found and push the range into it. If none are found, add another level.
8
- const openYOffsetFound = YOffsetLevelsWithRanges.some(function(rangesAlreadyAddedToYOffset, index) {
9
- const rangeBlocked = rangesAlreadyAddedToYOffset.some(function(comparisonRange) {
10
- return checkIfPotentiallyCircularRangesOverlap(range, comparisonRange)
11
- })
12
- if (!rangeBlocked) {
13
- yOffset = index
14
- if (assignYOffsetToRange) range.yOffset = index
15
- rangesAlreadyAddedToYOffset.push(range)
16
- return true
3
+ export default function getYOffsetForPotentiallyCircularRange(
4
+ range,
5
+ YOffsetLevelsWithRanges,
6
+ assignYOffsetToRange
7
+ ) {
8
+ //adjust the yOffset of the range being pushed in by checking its range against other range already in the row
9
+ let yOffset = [];
10
+ //YOffsetLevelsWithRanges is an array of arrays (array of yOffset levels holding arrays of range)
11
+ //loop through y offset levels starting with the 0 level until an empty one is found and push the range into it. If none are found, add another level.
12
+ const openYOffsetFound = YOffsetLevelsWithRanges.some(
13
+ function (rangesAlreadyAddedToYOffset, index) {
14
+ const rangeBlocked = rangesAlreadyAddedToYOffset.some(
15
+ function (comparisonRange) {
16
+ return checkIfPotentiallyCircularRangesOverlap(
17
+ range,
18
+ comparisonRange
19
+ );
17
20
  }
18
- });
19
- if (!openYOffsetFound) {
20
- yOffset = YOffsetLevelsWithRanges.length
21
- if (assignYOffsetToRange) range.yOffset = YOffsetLevelsWithRanges.length
21
+ );
22
+ if (!rangeBlocked) {
23
+ yOffset = index;
24
+ if (assignYOffsetToRange) range.yOffset = index;
25
+ rangesAlreadyAddedToYOffset.push(range);
26
+ return true;
27
+ }
28
+ return false;
22
29
  }
23
- return yOffset
24
- };
30
+ );
31
+ if (!openYOffsetFound) {
32
+ yOffset = YOffsetLevelsWithRanges.length;
33
+ if (assignYOffsetToRange) range.yOffset = YOffsetLevelsWithRanges.length;
34
+ }
35
+ return yOffset;
36
+ }
@@ -1,20 +1,27 @@
1
- import getYOffsetForPotentiallyCircularRange from './getYOffsetForPotentiallyCircularRange';
1
+ import getYOffsetForPotentiallyCircularRange from "./getYOffsetForPotentiallyCircularRange";
2
2
 
3
- export default function getYOffsetsForPotentiallyCircularRanges(ranges, assignYOffsetToRange) {
4
- //adjust the yOffset of the range being pushed in by checking its range against other ranges already in the row
5
- const yOffsets = [];
6
- let maxYOffset = 0;
7
- const yOffsetLevels = [] //yOffsetLevels is an array of arrays (array of yOffset levels holding arrays of ranges)
8
- ranges.forEach(function(range){
9
- //loop through y offset levels starting with the 0 level until an empty one is found and push the range into it. If none are found, add another level.
10
- const yOffset = getYOffsetForPotentiallyCircularRange(range, yOffsetLevels, assignYOffsetToRange)
11
- yOffsets.push(yOffset)
12
- if (yOffset>maxYOffset) {
13
- maxYOffset = yOffset;
14
- }
15
- range.yOffset = yOffset;
16
- if (!yOffsetLevels[yOffset]) yOffsetLevels[yOffset] = [];
17
- yOffsetLevels[yOffset].push(range);
18
- });
19
- return {yOffsets:yOffsets, maxYOffset: maxYOffset};
20
- };
3
+ export default function getYOffsetsForPotentiallyCircularRanges(
4
+ ranges,
5
+ assignYOffsetToRange
6
+ ) {
7
+ //adjust the yOffset of the range being pushed in by checking its range against other ranges already in the row
8
+ const yOffsets = [];
9
+ let maxYOffset = 0;
10
+ const yOffsetLevels = []; //yOffsetLevels is an array of arrays (array of yOffset levels holding arrays of ranges)
11
+ ranges.forEach(function (range) {
12
+ //loop through y offset levels starting with the 0 level until an empty one is found and push the range into it. If none are found, add another level.
13
+ const yOffset = getYOffsetForPotentiallyCircularRange(
14
+ range,
15
+ yOffsetLevels,
16
+ assignYOffsetToRange
17
+ );
18
+ yOffsets.push(yOffset);
19
+ if (yOffset > maxYOffset) {
20
+ maxYOffset = yOffset;
21
+ }
22
+ range.yOffset = yOffset;
23
+ if (!yOffsetLevels[yOffset]) yOffsetLevels[yOffset] = [];
24
+ yOffsetLevels[yOffset].push(range);
25
+ });
26
+ return { yOffsets: yOffsets, maxYOffset: maxYOffset };
27
+ }
@@ -1,29 +1,42 @@
1
- import {expect} from 'chai';
2
- import getYOffsetsForPotentiallyCircularRanges from './getYOffsetsForPotentiallyCircularRanges.js';
3
- describe('getYOffsetsForPotentiallyCircularRanges', function() {
4
- it('returns correct yOffset for overlapping ranges', function() {
5
- expect(getYOffsetsForPotentiallyCircularRanges([{
6
- start: 5,
7
- end: 100
8
- }, {
9
- start: 50,
10
- end: 50
11
- }])).to.deep.equal({yOffsets: [0,1], maxYOffset: 1});
12
- expect(getYOffsetsForPotentiallyCircularRanges([{
13
- start: 5,
14
- end: 100
15
- }, {
16
- start: 50,
17
- end: 50
18
- },{
19
- start: 50,
20
- end: 50
21
- },{
22
- start: 150,
23
- end: 4
24
- },{
25
- start: 150,
26
- end: 150
27
- }])).to.deep.equal({yOffsets: [0,1,2,0,1], maxYOffset: 2});
28
- });
29
- });
1
+ import { expect } from "chai";
2
+ import getYOffsetsForPotentiallyCircularRanges from "./getYOffsetsForPotentiallyCircularRanges.js";
3
+ describe("getYOffsetsForPotentiallyCircularRanges", function () {
4
+ it("returns correct yOffset for overlapping ranges", function () {
5
+ expect(
6
+ getYOffsetsForPotentiallyCircularRanges([
7
+ {
8
+ start: 5,
9
+ end: 100
10
+ },
11
+ {
12
+ start: 50,
13
+ end: 50
14
+ }
15
+ ])
16
+ ).to.deep.equal({ yOffsets: [0, 1], maxYOffset: 1 });
17
+ expect(
18
+ getYOffsetsForPotentiallyCircularRanges([
19
+ {
20
+ start: 5,
21
+ end: 100
22
+ },
23
+ {
24
+ start: 50,
25
+ end: 50
26
+ },
27
+ {
28
+ start: 50,
29
+ end: 50
30
+ },
31
+ {
32
+ start: 150,
33
+ end: 4
34
+ },
35
+ {
36
+ start: 150,
37
+ end: 150
38
+ }
39
+ ])
40
+ ).to.deep.equal({ yOffsets: [0, 1, 2, 0, 1], maxYOffset: 2 });
41
+ });
42
+ });
@@ -1,17 +1,32 @@
1
-
2
- import getOverlapsOfPotentiallyCircularRanges from './getOverlapsOfPotentiallyCircularRanges';
3
- import collapseOverlapsGeneratedFromRangeComparisonIfPossible from './collapseOverlapsGeneratedFromRangeComparisonIfPossible';
4
- import zeroSubrangeByContainerRange from './zeroSubrangeByContainerRange';
5
- import normalizePositionByRangeLength from './normalizePositionByRangeLength';
1
+ import getOverlapsOfPotentiallyCircularRanges from "./getOverlapsOfPotentiallyCircularRanges";
2
+ import collapseOverlapsGeneratedFromRangeComparisonIfPossible from "./collapseOverlapsGeneratedFromRangeComparisonIfPossible";
3
+ import zeroSubrangeByContainerRange from "./zeroSubrangeByContainerRange";
4
+ import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
6
5
 
7
6
  //gets the overlapping sections of two ranges and zeroes them to their first point of intersection!
8
- export default function getZeroedRangeOverlaps (annotation, selection, sequenceLength) {
9
- const overlaps = collapseOverlapsGeneratedFromRangeComparisonIfPossible(getOverlapsOfPotentiallyCircularRanges(annotation, selection, sequenceLength), sequenceLength, annotation)
10
- const zeroedOverlaps = overlaps.map((overlap) => {
11
- return zeroSubrangeByContainerRange(overlap, {
12
- start: selection.start,
13
- end: normalizePositionByRangeLength(selection.start - 1, sequenceLength)
14
- }, sequenceLength)
15
- })
16
- return zeroedOverlaps
17
- };
7
+ export default function getZeroedRangeOverlaps(
8
+ annotation,
9
+ selection,
10
+ sequenceLength
11
+ ) {
12
+ const overlaps = collapseOverlapsGeneratedFromRangeComparisonIfPossible(
13
+ getOverlapsOfPotentiallyCircularRanges(
14
+ annotation,
15
+ selection,
16
+ sequenceLength
17
+ ),
18
+ sequenceLength,
19
+ annotation
20
+ );
21
+ const zeroedOverlaps = overlaps.map(overlap => {
22
+ return zeroSubrangeByContainerRange(
23
+ overlap,
24
+ {
25
+ start: selection.start,
26
+ end: normalizePositionByRangeLength(selection.start - 1, sequenceLength)
27
+ },
28
+ sequenceLength
29
+ );
30
+ });
31
+ return zeroedOverlaps;
32
+ }
@@ -1,36 +1,75 @@
1
- import assert from 'assert';
2
- import getZeroedRangeOverlaps from './getZeroedRangeOverlaps';
3
- describe('getZeroedRangeOverlaps', function() {
4
- it('annotation non-circular, selection non circular ', function() {
5
- const res = getZeroedRangeOverlaps({start: 0, end: 3}, {start: 2, end: 3}, 4, true, true)
6
- assert.deepEqual(res, [{start: 0, end:1}])
7
- })
8
- it('annotation non circular, selection circular', function() {
9
- //01234
10
- //aaaa
11
- //s sss
12
- const res = getZeroedRangeOverlaps({start: 0, end: 3}, {start: 2, end: 0}, 5, true, true)
13
- assert.deepEqual(res, [ {start: 3,end: 3}, {start: 0, end:1}])
14
- })
15
- it('annotation non circular, selection circular 2', function() {
16
- //0123
17
- //aaaa
18
- //ssss
19
- const res = getZeroedRangeOverlaps({start: 0, end: 3}, {start: 2, end: 1}, 4, true, true)
20
- assert.deepEqual(res, [ {start: 2,end: 3}, {start: 0, end:1},])
21
- })
22
- it('annotation circular, selection fully containing', function() {
23
- //01234
24
- //aa aa
25
- //sssss
26
- const res = getZeroedRangeOverlaps({start: 3, end: 1}, {start: 0, end: 4}, 5, true, true)
27
- assert.deepEqual(res, [{start: 3, end: 1}])
28
- })
29
- it('annotation circular, selection fully containing 2', function() {
30
- //01234
31
- //aa aa
32
- //sssss
33
- const res = getZeroedRangeOverlaps({start: 3, end: 1}, {start: 1, end: 0}, 5, true, true)
34
- assert.deepEqual(res, [{start: 2, end: 4}, {start: 0, end: 0}])
35
- })
36
- })
1
+ import assert from "assert";
2
+ import getZeroedRangeOverlaps from "./getZeroedRangeOverlaps";
3
+ describe("getZeroedRangeOverlaps", function () {
4
+ it("annotation non-circular, selection non circular ", function () {
5
+ const res = getZeroedRangeOverlaps(
6
+ { start: 0, end: 3 },
7
+ { start: 2, end: 3 },
8
+ 4,
9
+ true,
10
+ true
11
+ );
12
+ assert.deepEqual(res, [{ start: 0, end: 1 }]);
13
+ });
14
+ it("annotation non circular, selection circular", function () {
15
+ //01234
16
+ //aaaa
17
+ //s sss
18
+ const res = getZeroedRangeOverlaps(
19
+ { start: 0, end: 3 },
20
+ { start: 2, end: 0 },
21
+ 5,
22
+ true,
23
+ true
24
+ );
25
+ assert.deepEqual(res, [
26
+ { start: 3, end: 3 },
27
+ { start: 0, end: 1 }
28
+ ]);
29
+ });
30
+ it("annotation non circular, selection circular 2", function () {
31
+ //0123
32
+ //aaaa
33
+ //ssss
34
+ const res = getZeroedRangeOverlaps(
35
+ { start: 0, end: 3 },
36
+ { start: 2, end: 1 },
37
+ 4,
38
+ true,
39
+ true
40
+ );
41
+ assert.deepEqual(res, [
42
+ { start: 2, end: 3 },
43
+ { start: 0, end: 1 }
44
+ ]);
45
+ });
46
+ it("annotation circular, selection fully containing", function () {
47
+ //01234
48
+ //aa aa
49
+ //sssss
50
+ const res = getZeroedRangeOverlaps(
51
+ { start: 3, end: 1 },
52
+ { start: 0, end: 4 },
53
+ 5,
54
+ true,
55
+ true
56
+ );
57
+ assert.deepEqual(res, [{ start: 3, end: 1 }]);
58
+ });
59
+ it("annotation circular, selection fully containing 2", function () {
60
+ //01234
61
+ //aa aa
62
+ //sssss
63
+ const res = getZeroedRangeOverlaps(
64
+ { start: 3, end: 1 },
65
+ { start: 1, end: 0 },
66
+ 5,
67
+ true,
68
+ true
69
+ );
70
+ assert.deepEqual(res, [
71
+ { start: 2, end: 4 },
72
+ { start: 0, end: 0 }
73
+ ]);
74
+ });
75
+ });