@teselagen/range-utils 0.3.14-beta.3 → 0.3.14

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.

Potentially problematic release.


This version of @teselagen/range-utils might be problematic. Click here for more details.

Files changed (128) hide show
  1. package/adjustRangeToDeletionOfAnotherRange.d.ts +1 -2
  2. package/adjustRangeToInsert.d.ts +1 -2
  3. package/adjustRangeToRotation.d.ts +1 -5
  4. package/bundle.js +2 -0
  5. package/checkIfNonCircularRangesOverlap.d.ts +1 -2
  6. package/checkIfPotentiallyCircularRangesOverlap.d.ts +1 -2
  7. package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.d.ts +1 -2
  8. package/convertRangeIndices.d.ts +1 -10
  9. package/convertRangeTo0Based.d.ts +1 -5
  10. package/convertRangeTo1Based.d.ts +1 -5
  11. package/doesRangeSpanEntireSequence.d.ts +1 -2
  12. package/doesRangeSpanOrigin.d.ts +1 -2
  13. package/expandOrContractCircularRangeToPosition.d.ts +2 -3
  14. package/expandOrContractNonCircularRangeToPosition.d.ts +2 -3
  15. package/expandOrContractRangeByLength.d.ts +1 -5
  16. package/expandOrContractRangeToPosition.d.ts +2 -3
  17. package/flipContainedRange.d.ts +1 -5
  18. package/generateRandomRange.d.ts +3 -3
  19. package/getAnnotationRangeType.d.ts +1 -2
  20. package/getEachPositionInRangeAsArray.d.ts +1 -2
  21. package/getLengthOfOverlappingRegionsBetweenTwoRanges.d.ts +1 -2
  22. package/getMiddleOfRange.d.ts +1 -2
  23. package/getOverlapOfNonCircularRanges.d.ts +4 -5
  24. package/getOverlapsOfPotentiallyCircularRanges.d.ts +1 -2
  25. package/getPositionFromAngle.d.ts +1 -1
  26. package/getRangeAngles.d.ts +7 -3
  27. package/getRangeLength.d.ts +1 -5
  28. package/getRangesBetweenTwoRanges.d.ts +1 -2
  29. package/getSequenceWithinRange.d.ts +1 -2
  30. package/getShortestDistanceBetweenTwoPositions.d.ts +1 -1
  31. package/getYOffsetForPotentiallyCircularRange.d.ts +1 -2
  32. package/getYOffsetsForPotentiallyCircularRanges.d.ts +2 -3
  33. package/getZeroedRangeOverlaps.d.ts +1 -2
  34. package/index.cjs +88 -87
  35. package/index.d.ts +0 -1
  36. package/index.js +88 -87
  37. package/index.umd.cjs +88 -87
  38. package/invertRange.d.ts +1 -5
  39. package/isPositionCloserToRangeStartThanRangeEnd.d.ts +1 -2
  40. package/isPositionWithinRange.d.ts +2 -3
  41. package/isRangeOrPositionWithinRange.d.ts +1 -2
  42. package/isRangeWithinRange.d.ts +1 -2
  43. package/loopEachPositionInRange.d.ts +1 -2
  44. package/modulatePositionByRange.d.ts +1 -2
  45. package/modulateRangeBySequenceLength.d.ts +1 -8
  46. package/normalizePositionByRangeLength.d.ts +1 -1
  47. package/normalizePositionByRangeLength1Based.d.ts +1 -1
  48. package/normalizeRange.d.ts +1 -5
  49. package/package.json +5 -10
  50. package/provideInclusiveOptions.d.ts +1 -6
  51. package/reversePositionInRange.d.ts +1 -1
  52. package/splitRangeIntoTwoPartsIfItIsCircular.d.ts +3 -4
  53. package/src/adjustRangeToDeletionOfAnotherRange.js +30 -33
  54. package/src/convertRangeIndices.test.js +1 -1
  55. package/src/expandOrContractRangeByLength.test.js +1 -1
  56. package/src/flipContainedRange.test.js +1 -1
  57. package/src/generateRandomRange.test.js +1 -1
  58. package/src/getAnnotationRangeType.test.js +1 -1
  59. package/src/invertRange.test.js +1 -1
  60. package/translateRange.d.ts +1 -5
  61. package/trimAnnStartEndToFitSeqLength.d.ts +1 -1
  62. package/trimNonCicularRangeByAnotherNonCircularRange.d.ts +4 -2
  63. package/trimNumberToFitWithin0ToAnotherNumber.d.ts +1 -1
  64. package/trimRangeByAnotherRange.d.ts +1 -2
  65. package/zeroSubrangeByContainerRange.d.ts +1 -2
  66. package/RangeAngles.d.ts +0 -7
  67. package/src/RangeAngles.ts +0 -9
  68. package/src/adjustRangeToDeletionOfAnotherRange.ts +0 -57
  69. package/src/adjustRangeToInsert.ts +0 -32
  70. package/src/adjustRangeToRotation.ts +0 -23
  71. package/src/checkIfNonCircularRangesOverlap.ts +0 -35
  72. package/src/checkIfPotentiallyCircularRangesOverlap.ts +0 -28
  73. package/src/collapseOverlapsGeneratedFromRangeComparisonIfPossible.ts +0 -81
  74. package/src/convertRangeIndices.ts +0 -34
  75. package/src/convertRangeTo0Based.ts +0 -9
  76. package/src/convertRangeTo1Based.ts +0 -10
  77. package/src/doesRangeSpanEntireSequence.ts +0 -12
  78. package/src/doesRangeSpanOrigin.ts +0 -5
  79. package/src/expandOrContractCircularRangeToPosition.ts +0 -50
  80. package/src/expandOrContractNonCircularRangeToPosition.ts +0 -30
  81. package/src/expandOrContractRangeByLength.ts +0 -18
  82. package/src/expandOrContractRangeToPosition.ts +0 -16
  83. package/src/flipContainedRange.ts +0 -156
  84. package/src/generateRandomRange.ts +0 -26
  85. package/src/getAnnotationRangeType.ts +0 -30
  86. package/src/getEachPositionInRangeAsArray.ts +0 -19
  87. package/src/getLengthOfOverlappingRegionsBetweenTwoRanges.ts +0 -18
  88. package/src/getMiddleOfRange.ts +0 -11
  89. package/src/getOverlapOfNonCircularRanges.ts +0 -41
  90. package/src/getOverlapsOfPotentiallyCircularRanges.ts +0 -60
  91. package/src/getPositionFromAngle.ts +0 -12
  92. package/src/getRangeAngles.ts +0 -38
  93. package/src/getRangeLength.test.ts +0 -30
  94. package/src/getRangeLength.ts +0 -17
  95. package/src/getRangesBetweenTwoRanges.ts +0 -42
  96. package/src/getSequenceWithinRange.test.ts +0 -47
  97. package/src/getSequenceWithinRange.ts +0 -24
  98. package/src/getShortestDistanceBetweenTwoPositions.test.ts +0 -12
  99. package/src/getShortestDistanceBetweenTwoPositions.ts +0 -16
  100. package/src/getYOffsetForPotentiallyCircularRange.ts +0 -37
  101. package/src/getYOffsetsForPotentiallyCircularRanges.test.ts +0 -17
  102. package/src/getYOffsetsForPotentiallyCircularRanges.ts +0 -28
  103. package/src/getZeroedRangeOverlaps.test.ts +0 -65
  104. package/src/getZeroedRangeOverlaps.ts +0 -33
  105. package/src/index.test.ts +0 -39
  106. package/src/index.ts +0 -53
  107. package/src/invertRange.ts +0 -25
  108. package/src/isPositionCloserToRangeStartThanRangeEnd.ts +0 -22
  109. package/src/isPositionWithinRange.ts +0 -40
  110. package/src/isRangeOrPositionWithinRange.ts +0 -40
  111. package/src/isRangeWithinRange.ts +0 -18
  112. package/src/loopEachPositionInRange.ts +0 -11
  113. package/src/modulatePositionByRange.ts +0 -15
  114. package/src/modulateRangeBySequenceLength.ts +0 -13
  115. package/src/normalizePositionByRangeLength.ts +0 -24
  116. package/src/normalizePositionByRangeLength1Based.ts +0 -9
  117. package/src/normalizeRange.ts +0 -12
  118. package/src/provideInclusiveOptions.ts +0 -79
  119. package/src/reversePositionInRange.ts +0 -17
  120. package/src/splitRangeIntoTwoPartsIfItIsCircular.ts +0 -36
  121. package/src/translateRange.ts +0 -21
  122. package/src/trimAnnStartEndToFitSeqLength.ts +0 -9
  123. package/src/trimNonCicularRangeByAnotherNonCircularRange.ts +0 -63
  124. package/src/trimNumberToFitWithin0ToAnotherNumber.ts +0 -15
  125. package/src/trimRangeByAnotherRange.ts +0 -103
  126. package/src/types.ts +0 -12
  127. package/src/zeroSubrangeByContainerRange.ts +0 -49
  128. package/types.d.ts +0 -12
@@ -1,26 +0,0 @@
1
- import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
2
-
3
- export default function generateRandomRange(
4
- minStart: number,
5
- maxEnd: number,
6
- maxLength: number
7
- ) {
8
- const start = getRandomInt(minStart, maxEnd);
9
- let end;
10
- if (maxLength) {
11
- end = normalizePositionByRangeLength(
12
- getRandomInt(start, start + maxLength),
13
- maxEnd
14
- );
15
- } else {
16
- end = getRandomInt(minStart, maxEnd);
17
- }
18
- return {
19
- start: start,
20
- end: end
21
- };
22
- }
23
-
24
- function getRandomInt(min: number, max: number) {
25
- return Math.floor(Math.random() * (max - min)) + min;
26
- }
@@ -1,30 +0,0 @@
1
- import { Range } from "./types";
2
-
3
- //function that returns the annotation range type
4
- export default function getAnnotationRangeType(
5
- annotationRange: Range,
6
- enclosingRangeType: Range,
7
- forward: boolean
8
- ) {
9
- if (annotationRange.start === enclosingRangeType.start) {
10
- if (annotationRange.end === enclosingRangeType.end) {
11
- return "beginningAndEnd";
12
- } else {
13
- if (forward) {
14
- return "start";
15
- } else {
16
- return "end";
17
- }
18
- }
19
- } else {
20
- if (annotationRange.end === enclosingRangeType.end) {
21
- if (forward) {
22
- return "end";
23
- } else {
24
- return "start";
25
- }
26
- } else {
27
- return "middle";
28
- }
29
- }
30
- }
@@ -1,19 +0,0 @@
1
- import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
2
- import getRangeLength from "./getRangeLength";
3
- import { Range } from "./types";
4
-
5
- export default function getEachPositionInRangeAsArray(
6
- range: Range,
7
- rangeMax: number
8
- ) {
9
- const output: number[] = [];
10
- const length = getRangeLength(range, rangeMax);
11
- if (!(length > 0)) {
12
- return output;
13
- }
14
- for (let i = range.start; i < length + range.start; i++) {
15
- const position = normalizePositionByRangeLength(i, rangeMax);
16
- output.push(position);
17
- }
18
- return output;
19
- }
@@ -1,18 +0,0 @@
1
- import getRangeLength from "./getRangeLength";
2
- import getOverlapsOfPotentiallyCircularRanges from "./getOverlapsOfPotentiallyCircularRanges";
3
- import { Range } from "./types";
4
-
5
- export default function getLengthOfOverlappingRegionsBetweenTwoRanges(
6
- rangeA: Range,
7
- rangeB: Range,
8
- maxLength: number
9
- ) {
10
- const overlaps = getOverlapsOfPotentiallyCircularRanges(
11
- rangeA,
12
- rangeB,
13
- maxLength
14
- );
15
- return overlaps.reduce(function (counter, overlap) {
16
- return counter + getRangeLength(overlap, maxLength);
17
- }, 0);
18
- }
@@ -1,11 +0,0 @@
1
- import getRangeLength from "./getRangeLength";
2
- import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
3
- import { Range } from "./types";
4
-
5
- export default function getMiddleOfRange(range: Range, rangeMax: number) {
6
- const len = getRangeLength({ start: range.start, end: range.end }, rangeMax);
7
- return normalizePositionByRangeLength(
8
- range.start + Math.floor(len / 2),
9
- rangeMax
10
- );
11
- }
@@ -1,41 +0,0 @@
1
- import { Range } from "./types";
2
-
3
- export default function getOverlapOfNonCircularRanges(
4
- rangeA: Range,
5
- rangeB: Range
6
- ) {
7
- if (rangeA.start < rangeB.start) {
8
- if (rangeA.end < rangeB.start) {
9
- //no overlap
10
- } else {
11
- if (rangeA.end < rangeB.end) {
12
- return {
13
- start: rangeB.start,
14
- end: rangeA.end
15
- };
16
- } else {
17
- return {
18
- start: rangeB.start,
19
- end: rangeB.end
20
- };
21
- }
22
- }
23
- } else {
24
- if (rangeA.start > rangeB.end) {
25
- //no overlap
26
- } else {
27
- if (rangeA.end < rangeB.end) {
28
- return {
29
- start: rangeA.start,
30
- end: rangeA.end
31
- };
32
- } else {
33
- return {
34
- start: rangeA.start,
35
- end: rangeB.end
36
- };
37
- }
38
- }
39
- }
40
- return null;
41
- }
@@ -1,60 +0,0 @@
1
- import { flatMap } from "lodash-es";
2
- import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIsCircular";
3
- import getOverlapOfNonCircularRanges from "./getOverlapOfNonCircularRanges";
4
-
5
- //returns an array of the overlaps between two potentially circular ranges
6
- import { Range } from "./types";
7
-
8
- //returns an array of the overlaps between two potentially circular ranges
9
- export default function getOverlapsOfPotentiallyCircularRanges(
10
- rangeA: Range,
11
- rangeB: Range,
12
- maxRangeLength: number,
13
- joinIfPossible = false //by default this fn only returns **non-circular** overlaps, if true it will try to join overlaps split on the origin
14
- ) {
15
- const normalizedRangeA = splitRangeIntoTwoPartsIfItIsCircular(
16
- rangeA,
17
- maxRangeLength
18
- );
19
- const normalizedRangeB = splitRangeIntoTwoPartsIfItIsCircular(
20
- rangeB,
21
- maxRangeLength
22
- );
23
-
24
- let overlaps: Range[] = [];
25
-
26
- normalizedRangeA.forEach(function (nonCircularRangeA) {
27
- normalizedRangeB.forEach(function (nonCircularRangeB) {
28
- const overlap = getOverlapOfNonCircularRanges(
29
- nonCircularRangeA,
30
- nonCircularRangeB
31
- );
32
- if (overlap) {
33
- overlaps.push(overlap);
34
- }
35
- });
36
- });
37
- if (
38
- joinIfPossible &&
39
- normalizedRangeA.length === 2 &&
40
- normalizedRangeB.length === 2 &&
41
- maxRangeLength
42
- ) {
43
- //we have 2 circular ranges that will have gotten split on the origin, so we'll manually mend those pieces back together
44
- const joinedOverlap: Partial<Range> = {};
45
- overlaps = flatMap(overlaps, o => {
46
- if (o.start === 0) {
47
- joinedOverlap.end = o.end;
48
- return [];
49
- } else if (o.end === maxRangeLength - 1) {
50
- joinedOverlap.start = o.start;
51
- return [];
52
- }
53
- return [o];
54
- });
55
- if (Object.keys(joinedOverlap).length > 0) {
56
- overlaps.push(joinedOverlap as Range);
57
- }
58
- }
59
- return overlaps;
60
- }
@@ -1,12 +0,0 @@
1
- export default function getPositionFromAngle(
2
- angle: number,
3
- rangeMax: number,
4
- isInBetweenPositions?: boolean
5
- ) {
6
- //percent through sequence * rangeMax
7
- const unroundedPostion = (angle / Math.PI / 2) * rangeMax;
8
- //return either the nearest position, or the nearest "inBetween" postion
9
- return isInBetweenPositions
10
- ? Math.round(unroundedPostion)
11
- : Math.floor(unroundedPostion);
12
- }
@@ -1,38 +0,0 @@
1
- import getRangeLength from "./getRangeLength";
2
- import { Range } from "./types";
3
- import { RangeAngles } from "./RangeAngles";
4
-
5
- export default function getRangeAngles(
6
- range: Range,
7
- rangeMax: number
8
- ): RangeAngles {
9
- const { startAngle, totalAngle, endAngle } = getStartEndAndTotalAngle(
10
- range,
11
- rangeMax
12
- );
13
-
14
- return {
15
- startAngle,
16
- totalAngle,
17
- endAngle,
18
- centerAngle: startAngle + totalAngle / 2,
19
- locationAngles:
20
- range.locations &&
21
- range.locations.map((location: Range) => {
22
- return getRangeAngles(location, rangeMax);
23
- })
24
- };
25
- }
26
-
27
- function getStartEndAndTotalAngle(range: Range, rangeMax: number) {
28
- const rangeLength = getRangeLength(
29
- { start: range.start, end: range.end },
30
- rangeMax
31
- );
32
-
33
- return {
34
- startAngle: 2 * Math.PI * (range.start / rangeMax),
35
- totalAngle: (rangeLength / rangeMax) * Math.PI * 2,
36
- endAngle: (2 * Math.PI * (range.end + 1)) / rangeMax //use a +1 here because the angle must encompass the end of the annotation
37
- };
38
- }
@@ -1,30 +0,0 @@
1
- //0123456789
2
- //r--------r
3
- //
4
- //0123
5
- //r--r
6
- // 0
7
- // 3 1
8
- // 2
9
-
10
- import assert from "assert";
11
-
12
- import getRangeLength from "./getRangeLength";
13
- describe("getRangeLength", function () {
14
- it("should return the correct length for ranges that cross the origin", function () {
15
- const length = getRangeLength({ start: 9, end: 0 }, 10);
16
- assert(length === 2);
17
- });
18
- it("should return the correct length for ranges that do not cross the origin", function () {
19
- const length = getRangeLength({ start: 4, end: 6 }, 10);
20
- assert(length === 3);
21
- });
22
- it("should return the correct length for ranges that overlapSelf", function () {
23
- const length = getRangeLength({ start: 4, end: 6, overlapsSelf: true }, 10);
24
- assert(length === 13);
25
- });
26
- it("should return the correct length for ranges that overlapSelf and origin", function () {
27
- const length = getRangeLength({ start: 9, end: 1, overlapsSelf: true }, 10);
28
- assert(length === 13);
29
- });
30
- });
@@ -1,17 +0,0 @@
1
- import provideInclusiveOptions from "./provideInclusiveOptions";
2
- import { Range } from "./types";
3
-
4
- export default provideInclusiveOptions(getRangeLength);
5
-
6
- function getRangeLength(range: Range, rangeMax: number) {
7
- let toRet;
8
- if (range.end < range.start) {
9
- toRet = rangeMax - range.start + range.end + 1;
10
- } else {
11
- toRet = range.end - range.start + 1;
12
- }
13
- if (range.overlapsSelf && rangeMax) {
14
- toRet += rangeMax;
15
- }
16
- return toRet;
17
- }
@@ -1,42 +0,0 @@
1
- import { Range } from "./types";
2
-
3
- export default function getRangesBetweenTwoRanges(
4
- range1: Range,
5
- range2: Range
6
- ) {
7
- // {
8
- // start: 85,
9
- // end: 92
10
- // }
11
-
12
- // {
13
- // start: 130,
14
- // end: 189
15
- // }
16
-
17
- // start1 - end2
18
-
19
- // start2 - end1
20
-
21
- const newRanges: Range[] = [];
22
- if (
23
- !(
24
- range1.start > -1 &&
25
- range1.end > -1 &&
26
- range2.start > -1 &&
27
- range2.end > -1
28
- )
29
- ) {
30
- return newRanges;
31
- }
32
- return [
33
- {
34
- start: range1.start,
35
- end: range2.end
36
- },
37
- {
38
- start: range2.start,
39
- end: range1.end
40
- }
41
- ];
42
- }
@@ -1,47 +0,0 @@
1
- import getSequenceWithinRange from "./getSequenceWithinRange.js";
2
-
3
- import assert from "assert";
4
- let subseq;
5
-
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
- });
47
- });
@@ -1,24 +0,0 @@
1
- import { Range } from "./types";
2
-
3
- //
4
- export default function getSequenceWithinRange<T>(
5
- range: Range,
6
- sequence: string | T[]
7
- ) {
8
- // ac.throw([ac.range, ac.oneOfType([ac.array, ac.string])], arguments);
9
- if (range.start < 0 || range.end < 0) return "";
10
- if (range.start > range.end) {
11
- //circular range
12
- let subSequence = sequence.slice(range.start, sequence.length);
13
- if (typeof subSequence === "string") {
14
- subSequence += sequence.slice(0, range.end + 1);
15
- } else {
16
- subSequence = (subSequence as T[]).concat(
17
- sequence.slice(0, range.end + 1) as T[]
18
- );
19
- }
20
- return subSequence;
21
- } else {
22
- return sequence.slice(range.start, range.end + 1);
23
- }
24
- }
@@ -1,12 +0,0 @@
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
- });
12
- });
@@ -1,16 +0,0 @@
1
- export default function getShortestDistanceBetweenTwoPositions(
2
- position1: number,
3
- position2: number,
4
- sequenceLength: number
5
- ) {
6
- if (position1 < position2) {
7
- const position1Holder = position1;
8
- position1 = position2;
9
- position2 = position1Holder;
10
- }
11
- //position 1 is now always >= position 2
12
-
13
- const d1 = position1 - position2;
14
- const d2 = sequenceLength - position1 + position2;
15
- return Math.min(d1, d2);
16
- }
@@ -1,37 +0,0 @@
1
- import checkIfPotentiallyCircularRangesOverlap from "./checkIfPotentiallyCircularRangesOverlap";
2
- import { Range } from "./types";
3
-
4
- export default function getYOffsetForPotentiallyCircularRange(
5
- range: Range,
6
- YOffsetLevelsWithRanges: Range[][],
7
- assignYOffsetToRange: boolean
8
- ) {
9
- //adjust the yOffset of the range being pushed in by checking its range against other range already in the row
10
- let yOffset = 0;
11
- //YOffsetLevelsWithRanges is an array of arrays (array of yOffset levels holding arrays of 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 openYOffsetFound = YOffsetLevelsWithRanges.some(
14
- function (rangesAlreadyAddedToYOffset, index) {
15
- const rangeBlocked = rangesAlreadyAddedToYOffset.some(
16
- function (comparisonRange) {
17
- return checkIfPotentiallyCircularRangesOverlap(
18
- range,
19
- comparisonRange
20
- );
21
- }
22
- );
23
- if (!rangeBlocked) {
24
- yOffset = index;
25
- if (assignYOffsetToRange) range.yOffset = index;
26
- rangesAlreadyAddedToYOffset.push(range);
27
- return true;
28
- }
29
- return false;
30
- }
31
- );
32
- if (!openYOffsetFound) {
33
- yOffset = YOffsetLevelsWithRanges.length;
34
- if (assignYOffsetToRange) range.yOffset = YOffsetLevelsWithRanges.length;
35
- }
36
- return yOffset;
37
- }
@@ -1,17 +0,0 @@
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
- const ranges = [
6
- { start: 0, end: 10, id: "1" },
7
- { start: 5, end: 20, id: "2" },
8
- { start: 15, end: 25, id: "3" }
9
- ];
10
- getYOffsetsForPotentiallyCircularRanges(ranges, false);
11
- expect(ranges).to.deep.equal([
12
- { start: 0, end: 10, id: "1", yOffset: 0 },
13
- { start: 5, end: 20, id: "2", yOffset: 1 },
14
- { start: 15, end: 25, id: "3", yOffset: 0 }
15
- ]);
16
- });
17
- });
@@ -1,28 +0,0 @@
1
- import getYOffsetForPotentiallyCircularRange from "./getYOffsetForPotentiallyCircularRange";
2
- import { Range } from "./types";
3
-
4
- export default function getYOffsetsForPotentiallyCircularRanges(
5
- ranges: Range[],
6
- assignYOffsetToRange: boolean
7
- ) {
8
- //adjust the yOffset of the range being pushed in by checking its range against other ranges already in the row
9
- const yOffsets: number[] = [];
10
- let maxYOffset = 0;
11
- const yOffsetLevels: Range[][] = []; //yOffsetLevels is an array of arrays (array of yOffset levels holding arrays of ranges)
12
- ranges.forEach(function (range) {
13
- //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.
14
- const yOffset = getYOffsetForPotentiallyCircularRange(
15
- range,
16
- yOffsetLevels,
17
- assignYOffsetToRange
18
- );
19
- yOffsets.push(yOffset);
20
- if (yOffset > maxYOffset) {
21
- maxYOffset = yOffset;
22
- }
23
- range.yOffset = yOffset;
24
- if (!yOffsetLevels[yOffset]) yOffsetLevels[yOffset] = [];
25
- yOffsetLevels[yOffset].push(range);
26
- });
27
- return { yOffsets: yOffsets, maxYOffset: maxYOffset };
28
- }
@@ -1,65 +0,0 @@
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
- );
10
- assert.deepEqual(res, [{ start: 0, end: 1 }]);
11
- });
12
- it("annotation non circular, selection circular", function () {
13
- //01234
14
- //aaaa
15
- //s sss
16
- const res = getZeroedRangeOverlaps(
17
- { start: 0, end: 3 },
18
- { start: 2, end: 0 },
19
- 5
20
- );
21
- assert.deepEqual(res, [
22
- { start: 3, end: 3 },
23
- { start: 0, end: 1 }
24
- ]);
25
- });
26
- it("annotation non circular, selection circular 2", function () {
27
- //0123
28
- //aaaa
29
- //ssss
30
- const res = getZeroedRangeOverlaps(
31
- { start: 0, end: 3 },
32
- { start: 2, end: 1 },
33
- 4
34
- );
35
- assert.deepEqual(res, [
36
- { start: 2, end: 3 },
37
- { start: 0, end: 1 }
38
- ]);
39
- });
40
- it("annotation circular, selection fully containing", function () {
41
- //01234
42
- //aa aa
43
- //sssss
44
- const res = getZeroedRangeOverlaps(
45
- { start: 3, end: 1 },
46
- { start: 0, end: 4 },
47
- 5
48
- );
49
- assert.deepEqual(res, [{ start: 3, end: 1 }]);
50
- });
51
- it("annotation circular, selection fully containing 2", function () {
52
- //01234
53
- //aa aa
54
- //sssss
55
- const res = getZeroedRangeOverlaps(
56
- { start: 3, end: 1 },
57
- { start: 1, end: 0 },
58
- 5
59
- );
60
- assert.deepEqual(res, [
61
- { start: 2, end: 4 },
62
- { start: 0, end: 0 }
63
- ]);
64
- });
65
- });
@@ -1,33 +0,0 @@
1
- import { Range } from "./types";
2
- import getOverlapsOfPotentiallyCircularRanges from "./getOverlapsOfPotentiallyCircularRanges";
3
- import collapseOverlapsGeneratedFromRangeComparisonIfPossible from "./collapseOverlapsGeneratedFromRangeComparisonIfPossible";
4
- import zeroSubrangeByContainerRange from "./zeroSubrangeByContainerRange";
5
- import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
6
-
7
- //gets the overlapping sections of two ranges and zeroes them to their first point of intersection!
8
- export default function getZeroedRangeOverlaps(
9
- annotation: Range,
10
- selection: Range,
11
- sequenceLength: number
12
- ) {
13
- const overlaps = collapseOverlapsGeneratedFromRangeComparisonIfPossible(
14
- getOverlapsOfPotentiallyCircularRanges(
15
- annotation,
16
- selection,
17
- sequenceLength
18
- ),
19
- sequenceLength,
20
- annotation
21
- );
22
- const zeroedOverlaps = overlaps.map(overlap => {
23
- return zeroSubrangeByContainerRange(
24
- overlap,
25
- {
26
- start: selection.start,
27
- end: normalizePositionByRangeLength(selection.start - 1, sequenceLength)
28
- },
29
- sequenceLength
30
- );
31
- });
32
- return zeroedOverlaps;
33
- }