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

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
package/src/index.test.ts DELETED
@@ -1,39 +0,0 @@
1
- import * as src from "./index";
2
- import fs from "fs";
3
-
4
- describe("index.js", () => {
5
- it(`should export all functions defined`, () => {
6
- return new Promise<void>(resolve => {
7
- fs.readdir(__dirname, (err, files) => {
8
- let passes = true;
9
- files.forEach(file => {
10
- if (
11
- file.indexOf(".test.js") > -1 ||
12
- file.indexOf(".test.ts") > -1 ||
13
- file.indexOf("index.js") > -1 ||
14
- file.indexOf("types.ts") > -1 ||
15
- file.indexOf("RangeAngles.ts") > -1 ||
16
- file.indexOf("index.ts") > -1
17
- ) {
18
- return;
19
- }
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- const funcOrObj = (src as any)[file.replace(/\.(ts|js)$/, "")];
22
- if (!funcOrObj) {
23
- console.info(
24
- `Uh oh, it looks like you forgot to export (or explicitly ignore) this file:`,
25
- file
26
- );
27
- passes = false;
28
- }
29
- });
30
- if (!passes) {
31
- throw new Error(
32
- "Please make sure to export (or ignore) each file! Update index.js to export the file"
33
- );
34
- }
35
- resolve();
36
- });
37
- });
38
- });
39
- });
package/src/index.ts DELETED
@@ -1,53 +0,0 @@
1
- export { default as adjustRangeToDeletionOfAnotherRange } from "./adjustRangeToDeletionOfAnotherRange";
2
- export { default as adjustRangeToInsert } from "./adjustRangeToInsert";
3
- export { default as checkIfNonCircularRangesOverlap } from "./checkIfNonCircularRangesOverlap";
4
- export { default as checkIfPotentiallyCircularRangesOverlap } from "./checkIfPotentiallyCircularRangesOverlap";
5
- export { default as collapseOverlapsGeneratedFromRangeComparisonIfPossible } from "./collapseOverlapsGeneratedFromRangeComparisonIfPossible";
6
- export { default as convertRangeIndices } from "./convertRangeIndices";
7
- export { default as convertRangeTo0Based } from "./convertRangeTo0Based";
8
- export { default as convertRangeTo1Based } from "./convertRangeTo1Based";
9
- export { default as doesRangeSpanEntireSequence } from "./doesRangeSpanEntireSequence";
10
- export { default as isRangeOrPositionWithinRange } from "./isRangeOrPositionWithinRange";
11
- export { default as doesRangeSpanOrigin } from "./doesRangeSpanOrigin";
12
- export { default as expandOrContractCircularRangeToPosition } from "./expandOrContractCircularRangeToPosition";
13
- export { default as expandOrContractNonCircularRangeToPosition } from "./expandOrContractNonCircularRangeToPosition";
14
- export { default as expandOrContractRangeByLength } from "./expandOrContractRangeByLength";
15
- export { default as expandOrContractRangeToPosition } from "./expandOrContractRangeToPosition";
16
- export { default as flipContainedRange } from "./flipContainedRange";
17
- export { default as generateRandomRange } from "./generateRandomRange";
18
- export { default as getAnnotationRangeType } from "./getAnnotationRangeType";
19
- export { default as getEachPositionInRangeAsArray } from "./getEachPositionInRangeAsArray";
20
- export { default as getLengthOfOverlappingRegionsBetweenTwoRanges } from "./getLengthOfOverlappingRegionsBetweenTwoRanges";
21
- export { default as getOverlapOfNonCircularRanges } from "./getOverlapOfNonCircularRanges";
22
- export { default as getOverlapsOfPotentiallyCircularRanges } from "./getOverlapsOfPotentiallyCircularRanges";
23
- export { default as getPositionFromAngle } from "./getPositionFromAngle";
24
- export { default as getRangeAngles } from "./getRangeAngles";
25
- export { default as getRangeLength } from "./getRangeLength";
26
- export { default as getMiddleOfRange } from "./getMiddleOfRange";
27
- export { default as getRangesBetweenTwoRanges } from "./getRangesBetweenTwoRanges";
28
- export { default as getSequenceWithinRange } from "./getSequenceWithinRange";
29
- export { default as getShortestDistanceBetweenTwoPositions } from "./getShortestDistanceBetweenTwoPositions";
30
- export { default as getYOffsetForPotentiallyCircularRange } from "./getYOffsetForPotentiallyCircularRange";
31
- export { default as getYOffsetsForPotentiallyCircularRanges } from "./getYOffsetsForPotentiallyCircularRanges";
32
- export { default as invertRange } from "./invertRange";
33
- export { default as isPositionCloserToRangeStartThanRangeEnd } from "./isPositionCloserToRangeStartThanRangeEnd";
34
- export { default as isPositionWithinRange } from "./isPositionWithinRange";
35
- export { default as isRangeWithinRange } from "./isRangeWithinRange";
36
- export { default as loopEachPositionInRange } from "./loopEachPositionInRange";
37
- export { default as modulatePositionByRange } from "./modulatePositionByRange";
38
- export { default as modulateRangeBySequenceLength } from "./modulateRangeBySequenceLength";
39
- export { default as normalizePositionByRangeLength } from "./normalizePositionByRangeLength";
40
- export { default as normalizePositionByRangeLength1Based } from "./normalizePositionByRangeLength1Based";
41
- export { default as normalizeRange } from "./normalizeRange";
42
- export { default as provideInclusiveOptions } from "./provideInclusiveOptions";
43
- export { default as reversePositionInRange } from "./reversePositionInRange";
44
- export { default as splitRangeIntoTwoPartsIfItIsCircular } from "./splitRangeIntoTwoPartsIfItIsCircular";
45
- export { default as translateRange } from "./translateRange";
46
- export { default as trimNonCicularRangeByAnotherNonCircularRange } from "./trimNonCicularRangeByAnotherNonCircularRange";
47
- export { default as trimNumberToFitWithin0ToAnotherNumber } from "./trimNumberToFitWithin0ToAnotherNumber";
48
- export { default as trimRangeByAnotherRange } from "./trimRangeByAnotherRange";
49
- export { default as zeroSubrangeByContainerRange } from "./zeroSubrangeByContainerRange";
50
- export { default as adjustRangeToRotation } from "./adjustRangeToRotation";
51
- export { default as getZeroedRangeOverlaps } from "./getZeroedRangeOverlaps";
52
- export { default as trimAnnStartEndToFitSeqLength } from "./trimAnnStartEndToFitSeqLength";
53
- export * from "./types";
@@ -1,25 +0,0 @@
1
- import { Range } from "./types";
2
-
3
- import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
4
- import provideInclusiveOptions from "./provideInclusiveOptions";
5
- export default provideInclusiveOptions(invertRange);
6
-
7
- function invertRange(
8
- rangeOrCaret: Range | number,
9
- rangeMax: number
10
- ): Range | undefined {
11
- if (typeof rangeOrCaret !== "number" && rangeOrCaret.start > -1) {
12
- const start = rangeOrCaret.end + 1;
13
- const end = rangeOrCaret.start - 1;
14
- return {
15
- start: normalizePositionByRangeLength(start, rangeMax, false),
16
- end: normalizePositionByRangeLength(end, rangeMax, false)
17
- };
18
- } else if (typeof rangeOrCaret === "number" && rangeOrCaret > -1) {
19
- return {
20
- start: normalizePositionByRangeLength(rangeOrCaret, rangeMax, false),
21
- end: normalizePositionByRangeLength(rangeOrCaret - 1, rangeMax, false)
22
- };
23
- }
24
- return undefined;
25
- }
@@ -1,22 +0,0 @@
1
- //function to calculate whether a position is closer to the range start than the range end
2
- import getShortestDistanceBetweenTwoPositions from "./getShortestDistanceBetweenTwoPositions";
3
-
4
- import { Range } from "./types";
5
-
6
- export default function isPositionCloserToRangeStartThanRangeEnd(
7
- position: number,
8
- range: Range,
9
- maxLength: number
10
- ) {
11
- const distanceFromStart = getShortestDistanceBetweenTwoPositions(
12
- range.start,
13
- position,
14
- maxLength
15
- );
16
- const distanceFromEnd = getShortestDistanceBetweenTwoPositions(
17
- range.end,
18
- position,
19
- maxLength
20
- );
21
- return distanceFromStart <= distanceFromEnd;
22
- }
@@ -1,40 +0,0 @@
1
- import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIsCircular";
2
- /**
3
- *
4
- * @param {*} position //assumed to be a 0 based "caretPosition"
5
- * @param {*} range //0 based inclusive range
6
- * @param {*} sequenceLength
7
- * @param {*} includeEdges - (default false) whether or not to say
8
- */
9
- import { Range } from "./types";
10
-
11
- /**
12
- *
13
- * @param {*} position //assumed to be a 0 based "caretPosition"
14
- * @param {*} range //0 based inclusive range
15
- * @param {*} sequenceLength
16
- * @param {*} includeEdges - (default false) whether or not to say
17
- */
18
- function isPositionWithinRange(
19
- position: number,
20
- range: Range,
21
- sequenceLength: number,
22
- includeStartEdge?: boolean,
23
- includeEndEdge?: boolean
24
- ) {
25
- const ranges = splitRangeIntoTwoPartsIfItIsCircular(range, sequenceLength);
26
- const positionFits = ranges.some(function (range) {
27
- if (includeStartEdge ? position < range.start : position <= range.start) {
28
- return false;
29
- } else {
30
- if (includeEndEdge ? position <= range.end + 1 : position <= range.end) {
31
- return true;
32
- } else {
33
- return false;
34
- }
35
- }
36
- });
37
- return positionFits;
38
- }
39
-
40
- export default isPositionWithinRange;
@@ -1,40 +0,0 @@
1
- import { isObject } from "lodash-es";
2
- import isRangeWithinRange from "./isRangeWithinRange";
3
- import isPositionWithinRange from "./isPositionWithinRange";
4
-
5
- import { Range } from "./types";
6
-
7
- export default function isRangeOrPositionWithinRange(
8
- rangeOrPositionToCheck: Range | number,
9
- containingRange: Range,
10
- maxLength: number,
11
- includeStartEdge?: boolean,
12
- includeEndEdge?: boolean
13
- ) {
14
- if (
15
- rangeOrPositionToCheck === undefined ||
16
- rangeOrPositionToCheck === null ||
17
- containingRange === undefined ||
18
- containingRange === null
19
- ) {
20
- return false;
21
- }
22
- if (isObject(rangeOrPositionToCheck)) {
23
- if (typeof (rangeOrPositionToCheck as Range).start !== "number") {
24
- return false;
25
- }
26
- return isRangeWithinRange(
27
- rangeOrPositionToCheck as Range,
28
- containingRange,
29
- maxLength
30
- );
31
- } else {
32
- return isPositionWithinRange(
33
- rangeOrPositionToCheck,
34
- containingRange,
35
- maxLength,
36
- includeStartEdge,
37
- includeEndEdge
38
- );
39
- }
40
- }
@@ -1,18 +0,0 @@
1
- //TNR: THIS METHOD ONLY WORKS FOR COMPARING 0-BASED RANGES!!!!!!
2
- import trimRangeByAnotherRange from "./trimRangeByAnotherRange";
3
-
4
- import { Range } from "./types";
5
-
6
- export default function isRangeWithinRange(
7
- rangeToCheck: Range,
8
- containingRange: Range,
9
- maxLength: number
10
- ) {
11
- const ranges = trimRangeByAnotherRange(
12
- rangeToCheck,
13
- containingRange,
14
- maxLength
15
- );
16
- if (ranges === null) return false;
17
- return !ranges;
18
- }
@@ -1,11 +0,0 @@
1
- import { Range } from "./types";
2
-
3
- import getEachPositionInRangeAsArray from "./getEachPositionInRangeAsArray";
4
-
5
- export default function loopEachPositionInRange(
6
- range: Range,
7
- rangeMax: number,
8
- func: (pos: number) => void
9
- ) {
10
- getEachPositionInRangeAsArray(range, rangeMax).map(func);
11
- }
@@ -1,15 +0,0 @@
1
- import { Range } from "./types";
2
-
3
- //this function takes a position that might not fit in a given range and puts it into that range
4
- export default function modulatePositionByRange(
5
- position: number,
6
- range: Range
7
- ) {
8
- let returnVal = position;
9
- if (position < range.start) {
10
- returnVal = range.end - (range.start - (position + 1));
11
- } else if (position > range.end) {
12
- returnVal = range.start + (position - range.end - 1);
13
- }
14
- return returnVal;
15
- }
@@ -1,13 +0,0 @@
1
- import { Range } from "./types";
2
-
3
- import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
4
- import provideInclusiveOptions from "./provideInclusiveOptions";
5
- import { assign } from "lodash-es";
6
- export default provideInclusiveOptions(modulateRangeBySequenceLength);
7
-
8
- function modulateRangeBySequenceLength(range: Range, seqLen: number) {
9
- return assign(range, {
10
- start: normalizePositionByRangeLength(range.start, seqLen),
11
- end: normalizePositionByRangeLength(range.end, seqLen)
12
- });
13
- }
@@ -1,24 +0,0 @@
1
- //
2
- // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
3
- export default function normalizePositionByRangeLength(
4
- pPosition: number,
5
- sequenceLength: number,
6
- isInBetweenPositions = false
7
- ) {
8
- //isInBetweenPositions refers to:
9
- // A T G C
10
- // 0 1 2 3 <-- isInBetweenPositions = false is counting the positions themselves
11
- //0 1 2 3 4 <-- isInBetweenPositions = true is counting the spaces between positions
12
- // ac.throw([ac.number, ac.posInt, ac.bool], arguments);
13
- let position = pPosition;
14
- if (position < 0) {
15
- position += sequenceLength;
16
- } else if (position + (isInBetweenPositions ? 0 : 1) > sequenceLength) {
17
- position -= sequenceLength;
18
- }
19
- return position < 0
20
- ? 0
21
- : position > sequenceLength - (isInBetweenPositions ? 0 : 1)
22
- ? sequenceLength - (isInBetweenPositions ? 0 : 1)
23
- : position;
24
- }
@@ -1,9 +0,0 @@
1
- //
2
- import modulatePositionByRange from "./modulatePositionByRange";
3
-
4
- export default function normalizePositionByRangeLength1Based(
5
- position: number,
6
- sequenceLength: number
7
- ) {
8
- return modulatePositionByRange(position, { start: 1, end: sequenceLength });
9
- }
@@ -1,12 +0,0 @@
1
- //normalize range takes in a range that might be slightly outside of the rangeMax and wraps the start/end as necessary to fit
2
- import { assign } from "lodash-es";
3
-
4
- import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
5
- import { Range } from "./types";
6
-
7
- export default function normalizeRange(range: Range, sequenceLength: number) {
8
- return assign({}, range, {
9
- start: normalizePositionByRangeLength(range.start, sequenceLength),
10
- end: normalizePositionByRangeLength(range.end, sequenceLength)
11
- });
12
- }
@@ -1,79 +0,0 @@
1
- import { assign } from "lodash-es";
2
-
3
- type Options = {
4
- inclusive1BasedEnd?: boolean;
5
- inclusive1BasedStart?: boolean;
6
- };
7
-
8
- export default function provideInclusiveOptions<
9
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
- T extends (...args: any[]) => any
11
- >(
12
- funToWrap: T
13
- ): (
14
- ...args: [...Parameters<T>, options?: Options]
15
- ) => ReturnType<T> {
16
- return function (
17
- this: unknown,
18
- ...args: [...Parameters<T>, options?: Options]
19
- ): ReturnType<T> {
20
- const options = args[args.length - 1] as Options | undefined;
21
- if (
22
- options &&
23
- (options.inclusive1BasedEnd || options.inclusive1BasedStart)
24
- ) {
25
- args.forEach(function (arg, index) {
26
- // cast arg to check for start/end
27
- const potentialRange = arg as { start?: number; end?: number } | null;
28
- if (
29
- potentialRange &&
30
- typeof potentialRange.start === "number" &&
31
- potentialRange.start > -1 &&
32
- options.inclusive1BasedStart
33
- ) {
34
- args[index] = assign(potentialRange, {
35
- start: potentialRange.start - 1
36
- });
37
- }
38
- if (
39
- potentialRange &&
40
- typeof potentialRange.end === "number" &&
41
- potentialRange.end > -1 &&
42
- options.inclusive1BasedEnd
43
- ) {
44
- args[index] = assign(potentialRange, {
45
- end: potentialRange.end - 1
46
- });
47
- }
48
- });
49
- }
50
- // eslint-disable-next-line @typescript-eslint/ban-types
51
- let returnVal = (funToWrap as Function).apply(this, args);
52
- const potentialReturn = returnVal as {
53
- start?: number;
54
- end?: number;
55
- } | null;
56
-
57
- if (
58
- potentialReturn &&
59
- typeof potentialReturn.start === "number" &&
60
- potentialReturn.start > -1 &&
61
- options &&
62
- options.inclusive1BasedStart
63
- ) {
64
- returnVal = assign(potentialReturn, {
65
- start: potentialReturn.start + 1
66
- });
67
- }
68
- if (
69
- potentialReturn &&
70
- typeof potentialReturn.end === "number" &&
71
- potentialReturn.end > -1 &&
72
- options &&
73
- options.inclusive1BasedEnd
74
- ) {
75
- returnVal = assign(potentialReturn, { end: potentialReturn.end + 1 });
76
- }
77
- return returnVal as ReturnType<T>;
78
- };
79
- }
@@ -1,17 +0,0 @@
1
- //
2
- export default function reversePositionInRange(
3
- position: number,
4
- rangeLength: number,
5
- isInBetweenPositions: boolean
6
- ) {
7
- //isInBetweenPositions refers to:
8
- // A T G C
9
- // 0 1 2 3 <-- isInBetweenPositions = false is counting the positions themselves
10
- //0 1 2 3 4 <-- isInBetweenPositions = true is counting the spaces between positions
11
- // ac.throw([
12
- // ac.posInt,
13
- // ac.posInt,
14
- // ac.bool
15
- // ], arguments);
16
- return rangeLength - position - (isInBetweenPositions ? 0 : 1);
17
- }
@@ -1,36 +0,0 @@
1
- import { Range } from "./types";
2
-
3
- //
4
- // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
5
- //takes a potentially circular range and returns an array containing the range split on the origin
6
- export default function splitRangeIntoTwoPartsIfItIsCircular(
7
- range: Range,
8
- sequenceLength: number
9
- ) {
10
- // ac.throw([ac.range, ac.number], arguments);
11
- if (sequenceLength !== 0) {
12
- sequenceLength = sequenceLength || Infinity;
13
- }
14
- const ranges = [];
15
- if (range.start > range.end) {
16
- //the range is cicular, so we return an array of two ranges
17
- ranges.push({
18
- start: 0,
19
- end: range.end,
20
- type: "end"
21
- });
22
- ranges.push({
23
- start: range.start,
24
- end: sequenceLength - 1,
25
- type: "beginning"
26
- });
27
- } else {
28
- //the range isn't circular, so we just return the range
29
- ranges.push({
30
- start: range.start,
31
- end: range.end,
32
- type: "beginningAndEnd"
33
- });
34
- }
35
- return ranges;
36
- }
@@ -1,21 +0,0 @@
1
- import { Range } from "./types";
2
-
3
- import { assign } from "lodash-es";
4
- import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
5
-
6
- export default function translateRange(
7
- rangeToBeAdjusted: Range,
8
- translateBy: number,
9
- rangeLength: number
10
- ) {
11
- return assign({}, rangeToBeAdjusted, {
12
- start: normalizePositionByRangeLength(
13
- rangeToBeAdjusted.start + translateBy,
14
- rangeLength
15
- ),
16
- end: normalizePositionByRangeLength(
17
- rangeToBeAdjusted.end + translateBy,
18
- rangeLength
19
- )
20
- });
21
- }
@@ -1,9 +0,0 @@
1
- export default function trimAnnStartEndToFitSeqLength(
2
- annStartOrEnd: number,
3
- sequenceLength: number
4
- ) {
5
- return Math.max(
6
- 0,
7
- Math.min(annStartOrEnd || 0, Math.max(sequenceLength - 1, 0))
8
- );
9
- }
@@ -1,63 +0,0 @@
1
- //
2
- import { Range } from "./types";
3
-
4
- //
5
- export default function trimNonCicularRangeByAnotherNonCircularRange(
6
- rangeToBeTrimmed: Range,
7
- trimmingRange: Range
8
- ): Range | undefined {
9
- // ac.throw([ac.range, ac.range], arguments);
10
- let outputTrimmedRange;
11
- if (!rangeToBeTrimmed) {
12
- return outputTrimmedRange;
13
- }
14
- if (rangeToBeTrimmed.start < trimmingRange.start) {
15
- if (rangeToBeTrimmed.end < trimmingRange.start) {
16
- // rrr <range to be trimmed
17
- // ttt <trimming range
18
- outputTrimmedRange = {
19
- start: rangeToBeTrimmed.start,
20
- end: rangeToBeTrimmed.end
21
- };
22
- } else {
23
- if (rangeToBeTrimmed.end > trimmingRange.end) {
24
- // rrrrrr <range to be trimmed
25
- // ttt <trimming range
26
- outputTrimmedRange = {
27
- start: rangeToBeTrimmed.start,
28
- end: rangeToBeTrimmed.end
29
- };
30
- } else {
31
- // rrrrrr <range to be trimmed
32
- // ttt <trimming range
33
- outputTrimmedRange = {
34
- start: rangeToBeTrimmed.start,
35
- end: trimmingRange.start - 1
36
- };
37
- }
38
- }
39
- } else {
40
- if (rangeToBeTrimmed.end <= trimmingRange.end) {
41
- // rrr <range to be trimmed
42
- // ttttt <trimming range
43
- //fully deleting the range, so do nothing
44
- } else {
45
- if (rangeToBeTrimmed.start > trimmingRange.end) {
46
- // rrrrrr <range to be trimmed
47
- // ttt <trimming range
48
- outputTrimmedRange = {
49
- end: rangeToBeTrimmed.end,
50
- start: rangeToBeTrimmed.start
51
- };
52
- } else {
53
- // rrrrrr <range to be trimmed
54
- // ttt <trimming range
55
- outputTrimmedRange = {
56
- end: rangeToBeTrimmed.end,
57
- start: trimmingRange.end + 1
58
- };
59
- }
60
- }
61
- }
62
- return outputTrimmedRange;
63
- }
@@ -1,15 +0,0 @@
1
- //
2
- // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
3
- export default function trimNumberToFitWithin0ToAnotherNumber(
4
- numberToBeTrimmed: number,
5
- max: number
6
- ) {
7
- // ac.throw([ac.number, ac.number], arguments);
8
- if (numberToBeTrimmed < 0) {
9
- numberToBeTrimmed = 0;
10
- }
11
- if (numberToBeTrimmed > max) {
12
- numberToBeTrimmed = max;
13
- }
14
- return numberToBeTrimmed;
15
- }