@teselagen/range-utils 0.3.20-beta.1 → 0.3.20

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 (163) hide show
  1. package/adjustRangeToDeletionOfAnotherRange.d.ts +1 -2
  2. package/adjustRangeToDeletionOfAnotherRange.test.d.ts +1 -0
  3. package/adjustRangeToInsert.d.ts +1 -2
  4. package/adjustRangeToInsert.test.d.ts +1 -0
  5. package/adjustRangeToRotation.d.ts +1 -2
  6. package/adjustRangeToRotation.test.d.ts +1 -0
  7. package/checkIfNonCircularRangesOverlap.d.ts +1 -2
  8. package/checkIfNonCircularRangesOverlap.test.d.ts +1 -0
  9. package/checkIfPotentiallyCircularRangesOverlap.d.ts +1 -2
  10. package/checkIfPotentiallyCircularRangesOverlap.test.d.ts +1 -0
  11. package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.d.ts +1 -2
  12. package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.test.d.ts +1 -0
  13. package/convertRangeIndices.d.ts +1 -10
  14. package/convertRangeIndices.test.d.ts +1 -0
  15. package/convertRangeTo0Based.d.ts +1 -5
  16. package/convertRangeTo1Based.d.ts +1 -5
  17. package/doesRangeSpanEntireSequence.d.ts +1 -2
  18. package/doesRangeSpanOrigin.d.ts +1 -2
  19. package/expandOrContractCircularRangeToPosition.d.ts +2 -3
  20. package/expandOrContractNonCircularRangeToPosition.d.ts +2 -3
  21. package/expandOrContractRangeByLength.d.ts +1 -5
  22. package/expandOrContractRangeByLength.test.d.ts +1 -0
  23. package/expandOrContractRangeToPosition.d.ts +2 -3
  24. package/flipContainedRange.d.ts +1 -5
  25. package/flipContainedRange.test.d.ts +1 -0
  26. package/generateRandomRange.d.ts +3 -3
  27. package/generateRandomRange.test.d.ts +1 -0
  28. package/getAnnotationRangeType.d.ts +1 -2
  29. package/getAnnotationRangeType.test.d.ts +1 -0
  30. package/getEachPositionInRangeAsArray.d.ts +1 -2
  31. package/getEachPositionInRangeAsArray.test.d.ts +1 -0
  32. package/getLengthOfOverlappingRegionsBetweenTwoRanges.d.ts +1 -2
  33. package/getLengthOfOverlappingRegionsBetweenTwoRanges.test.d.ts +1 -0
  34. package/getMiddleOfRange.d.ts +1 -2
  35. package/getMiddleOfRange.test.d.ts +1 -0
  36. package/getOverlapOfNonCircularRanges.d.ts +4 -5
  37. package/getOverlapsOfPotentiallyCircularRanges.d.ts +1 -2
  38. package/getOverlapsOfPotentiallyCircularRanges.test.d.ts +1 -0
  39. package/getPositionFromAngle.d.ts +1 -1
  40. package/getRangeAngles.d.ts +7 -3
  41. package/getRangeAngles.test.d.ts +1 -0
  42. package/getRangeLength.d.ts +1 -5
  43. package/getRangeLength.test.d.ts +1 -0
  44. package/getRangesBetweenTwoRanges.d.ts +1 -2
  45. package/getSequenceWithinRange.d.ts +1 -3
  46. package/getSequenceWithinRange.test.d.ts +1 -0
  47. package/getShortestDistanceBetweenTwoPositions.d.ts +1 -1
  48. package/getShortestDistanceBetweenTwoPositions.test.d.ts +1 -0
  49. package/getYOffsetForPotentiallyCircularRange.d.ts +1 -2
  50. package/getYOffsetsForPotentiallyCircularRanges.d.ts +2 -3
  51. package/getYOffsetsForPotentiallyCircularRanges.test.d.ts +1 -0
  52. package/getZeroedRangeOverlaps.d.ts +1 -2
  53. package/getZeroedRangeOverlaps.test.d.ts +1 -0
  54. package/index.cjs +45 -58
  55. package/index.d.ts +0 -1
  56. package/index.js +45 -58
  57. package/index.test.d.ts +1 -0
  58. package/index.umd.cjs +45 -58
  59. package/invertRange.d.ts +1 -5
  60. package/invertRange.test.d.ts +1 -0
  61. package/isPositionCloserToRangeStartThanRangeEnd.d.ts +1 -2
  62. package/isPositionCloserToRangeStartThanRangeEnd.test.d.ts +1 -0
  63. package/isPositionWithinRange.d.ts +2 -3
  64. package/isRangeOrPositionWithinRange.d.ts +1 -2
  65. package/isRangeOrPositionWithinRange.test.d.ts +1 -0
  66. package/isRangeWithinRange.d.ts +1 -2
  67. package/loopEachPositionInRange.d.ts +1 -2
  68. package/modulatePositionByRange.d.ts +1 -2
  69. package/modulatePositionByRange.test.d.ts +1 -0
  70. package/modulateRangeBySequenceLength.d.ts +1 -8
  71. package/modulateRangeBySequenceLength.test.d.ts +1 -0
  72. package/normalizePositionByRangeLength.d.ts +1 -1
  73. package/normalizePositionByRangeLength.test.d.ts +1 -0
  74. package/normalizePositionByRangeLength1Based.d.ts +1 -1
  75. package/normalizePositionByRangeLength1Based.test.d.ts +1 -0
  76. package/normalizeRange.d.ts +1 -5
  77. package/normalizeRange.test.d.ts +1 -0
  78. package/package.json +2 -10
  79. package/provideInclusiveOptions.d.ts +1 -6
  80. package/reversePositionInRange.d.ts +1 -1
  81. package/splitRangeIntoTwoPartsIfItIsCircular.d.ts +3 -4
  82. package/splitRangeIntoTwoPartsIfItIsCircular.test.d.ts +1 -0
  83. package/src/{adjustRangeToDeletionOfAnotherRange.ts → adjustRangeToDeletionOfAnotherRange.js} +7 -4
  84. package/src/{adjustRangeToInsert.ts → adjustRangeToInsert.js} +4 -4
  85. package/src/adjustRangeToRotation.js +23 -0
  86. package/src/{checkIfNonCircularRangesOverlap.ts → checkIfNonCircularRangesOverlap.js} +4 -5
  87. package/src/{checkIfPotentiallyCircularRangesOverlap.ts → checkIfPotentiallyCircularRangesOverlap.js} +4 -4
  88. package/src/{collapseOverlapsGeneratedFromRangeComparisonIfPossible.ts → collapseOverlapsGeneratedFromRangeComparisonIfPossible.js} +4 -7
  89. package/src/{convertRangeIndices.ts → convertRangeIndices.js} +3 -11
  90. package/src/{convertRangeTo0Based.ts → convertRangeTo0Based.js} +1 -2
  91. package/src/{convertRangeTo1Based.ts → convertRangeTo1Based.js} +1 -2
  92. package/src/doesRangeSpanEntireSequence.js +7 -0
  93. package/src/doesRangeSpanOrigin.js +3 -0
  94. package/src/{expandOrContractCircularRangeToPosition.ts → expandOrContractCircularRangeToPosition.js} +3 -5
  95. package/src/{expandOrContractNonCircularRangeToPosition.ts → expandOrContractNonCircularRangeToPosition.js} +2 -4
  96. package/src/{expandOrContractRangeByLength.ts → expandOrContractRangeByLength.js} +4 -5
  97. package/src/{expandOrContractRangeToPosition.ts → expandOrContractRangeToPosition.js} +8 -6
  98. package/src/{flipContainedRange.ts → flipContainedRange.js} +8 -18
  99. package/src/{generateRandomRange.ts → generateRandomRange.js} +2 -6
  100. package/src/{getAnnotationRangeType.ts → getAnnotationRangeType.js} +3 -5
  101. package/src/{getEachPositionInRangeAsArray.ts → getEachPositionInRangeAsArray.js} +2 -6
  102. package/src/{getLengthOfOverlappingRegionsBetweenTwoRanges.ts → getLengthOfOverlappingRegionsBetweenTwoRanges.js} +3 -4
  103. package/src/{getMiddleOfRange.ts → getMiddleOfRange.js} +1 -2
  104. package/src/{getOverlapOfNonCircularRanges.ts → getOverlapOfNonCircularRanges.js} +1 -7
  105. package/src/{getOverlapsOfPotentiallyCircularRanges.ts → getOverlapsOfPotentiallyCircularRanges.js} +7 -13
  106. package/src/{getPositionFromAngle.ts → getPositionFromAngle.js} +3 -3
  107. package/src/{getRangeAngles.ts → getRangeAngles.js} +3 -8
  108. package/src/{getRangeLength.ts → getRangeLength.js} +1 -4
  109. package/src/{getRangesBetweenTwoRanges.ts → getRangesBetweenTwoRanges.js} +2 -7
  110. package/src/getSequenceWithinRange.js +17 -0
  111. package/src/{getShortestDistanceBetweenTwoPositions.ts → getShortestDistanceBetweenTwoPositions.js} +3 -3
  112. package/src/{getYOffsetForPotentiallyCircularRange.ts → getYOffsetForPotentiallyCircularRange.js} +4 -5
  113. package/src/{getYOffsetsForPotentiallyCircularRanges.ts → getYOffsetsForPotentiallyCircularRanges.js} +4 -5
  114. package/src/getYOffsetsForPotentiallyCircularRanges.test.js +42 -0
  115. package/src/{getZeroedRangeOverlaps.ts → getZeroedRangeOverlaps.js} +3 -4
  116. package/src/{getZeroedRangeOverlaps.test.ts → getZeroedRangeOverlaps.test.js} +15 -5
  117. package/src/{index.ts → index.js} +0 -1
  118. package/src/{index.test.ts → index.test.js} +3 -11
  119. package/src/invertRange.js +21 -0
  120. package/src/{isPositionCloserToRangeStartThanRangeEnd.ts → isPositionCloserToRangeStartThanRangeEnd.js} +3 -5
  121. package/src/{isPositionWithinRange.ts → isPositionWithinRange.js} +5 -14
  122. package/src/{isRangeOrPositionWithinRange.ts → isRangeOrPositionWithinRange.js} +6 -11
  123. package/src/{isRangeWithinRange.ts → isRangeWithinRange.js} +3 -5
  124. package/src/loopEachPositionInRange.js +5 -0
  125. package/src/{modulatePositionByRange.ts → modulatePositionByRange.js} +1 -6
  126. package/src/{modulateRangeBySequenceLength.ts → modulateRangeBySequenceLength.js} +1 -3
  127. package/src/{normalizePositionByRangeLength.ts → normalizePositionByRangeLength.js} +7 -7
  128. package/src/{normalizePositionByRangeLength1Based.ts → normalizePositionByRangeLength1Based.js} +2 -3
  129. package/src/{normalizeRange.ts → normalizeRange.js} +1 -2
  130. package/src/provideInclusiveOptions.js +39 -0
  131. package/src/{reversePositionInRange.ts → reversePositionInRange.js} +4 -4
  132. package/src/{splitRangeIntoTwoPartsIfItIsCircular.ts → splitRangeIntoTwoPartsIfItIsCircular.js} +4 -5
  133. package/src/{translateRange.ts → translateRange.js} +3 -5
  134. package/src/{trimAnnStartEndToFitSeqLength.ts → trimAnnStartEndToFitSeqLength.js} +2 -2
  135. package/src/{trimNonCicularRangeByAnotherNonCircularRange.ts → trimNonCicularRangeByAnotherNonCircularRange.js} +4 -6
  136. package/src/{trimNumberToFitWithin0ToAnotherNumber.ts → trimNumberToFitWithin0ToAnotherNumber.js} +4 -3
  137. package/src/{trimRangeByAnotherRange.ts → trimRangeByAnotherRange.js} +9 -9
  138. package/src/{zeroSubrangeByContainerRange.ts → zeroSubrangeByContainerRange.js} +8 -10
  139. package/translateRange.d.ts +1 -5
  140. package/translateRange.test.d.ts +1 -0
  141. package/trimAnnStartEndToFitSeqLength.d.ts +1 -1
  142. package/trimAnnStartEndToFitSeqLength.test.d.ts +1 -0
  143. package/trimNonCicularRangeByAnotherNonCircularRange.d.ts +4 -2
  144. package/trimNumberToFitWithin0ToAnotherNumber.d.ts +1 -1
  145. package/trimRangeByAnotherRange.d.ts +1 -2
  146. package/trimRangeByAnotherRange.test.d.ts +1 -0
  147. package/zeroSubrangeByContainerRange.d.ts +1 -2
  148. package/zeroSubrangeByContainerRange.test.d.ts +1 -0
  149. package/RangeAngles.d.ts +0 -7
  150. package/src/RangeAngles.ts +0 -9
  151. package/src/adjustRangeToRotation.ts +0 -22
  152. package/src/doesRangeSpanEntireSequence.ts +0 -12
  153. package/src/doesRangeSpanOrigin.ts +0 -5
  154. package/src/getSequenceWithinRange.ts +0 -33
  155. package/src/getYOffsetsForPotentiallyCircularRanges.test.ts +0 -17
  156. package/src/invertRange.ts +0 -25
  157. package/src/loopEachPositionInRange.ts +0 -11
  158. package/src/provideInclusiveOptions.ts +0 -79
  159. package/src/types.ts +0 -12
  160. package/types.d.ts +0 -12
  161. /package/src/{getRangeLength.test.ts → getRangeLength.test.js} +0 -0
  162. /package/src/{getSequenceWithinRange.test.ts → getSequenceWithinRange.test.js} +0 -0
  163. /package/src/{getShortestDistanceBetweenTwoPositions.test.ts → getShortestDistanceBetweenTwoPositions.test.js} +0 -0
@@ -5,7 +5,9 @@ describe("getZeroedRangeOverlaps", function () {
5
5
  const res = getZeroedRangeOverlaps(
6
6
  { start: 0, end: 3 },
7
7
  { start: 2, end: 3 },
8
- 4
8
+ 4,
9
+ true,
10
+ true
9
11
  );
10
12
  assert.deepEqual(res, [{ start: 0, end: 1 }]);
11
13
  });
@@ -16,7 +18,9 @@ describe("getZeroedRangeOverlaps", function () {
16
18
  const res = getZeroedRangeOverlaps(
17
19
  { start: 0, end: 3 },
18
20
  { start: 2, end: 0 },
19
- 5
21
+ 5,
22
+ true,
23
+ true
20
24
  );
21
25
  assert.deepEqual(res, [
22
26
  { start: 3, end: 3 },
@@ -30,7 +34,9 @@ describe("getZeroedRangeOverlaps", function () {
30
34
  const res = getZeroedRangeOverlaps(
31
35
  { start: 0, end: 3 },
32
36
  { start: 2, end: 1 },
33
- 4
37
+ 4,
38
+ true,
39
+ true
34
40
  );
35
41
  assert.deepEqual(res, [
36
42
  { start: 2, end: 3 },
@@ -44,7 +50,9 @@ describe("getZeroedRangeOverlaps", function () {
44
50
  const res = getZeroedRangeOverlaps(
45
51
  { start: 3, end: 1 },
46
52
  { start: 0, end: 4 },
47
- 5
53
+ 5,
54
+ true,
55
+ true
48
56
  );
49
57
  assert.deepEqual(res, [{ start: 3, end: 1 }]);
50
58
  });
@@ -55,7 +63,9 @@ describe("getZeroedRangeOverlaps", function () {
55
63
  const res = getZeroedRangeOverlaps(
56
64
  { start: 3, end: 1 },
57
65
  { start: 1, end: 0 },
58
- 5
66
+ 5,
67
+ true,
68
+ true
59
69
  );
60
70
  assert.deepEqual(res, [
61
71
  { start: 2, end: 4 },
@@ -50,4 +50,3 @@ export { default as zeroSubrangeByContainerRange } from "./zeroSubrangeByContain
50
50
  export { default as adjustRangeToRotation } from "./adjustRangeToRotation";
51
51
  export { default as getZeroedRangeOverlaps } from "./getZeroedRangeOverlaps";
52
52
  export { default as trimAnnStartEndToFitSeqLength } from "./trimAnnStartEndToFitSeqLength";
53
- export * from "./types";
@@ -3,22 +3,14 @@ import fs from "fs";
3
3
 
4
4
  describe("index.js", () => {
5
5
  it(`should export all functions defined`, () => {
6
- return new Promise<void>(resolve => {
6
+ return new Promise(resolve => {
7
7
  fs.readdir(__dirname, (err, files) => {
8
8
  let passes = true;
9
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
- ) {
10
+ if (file.indexOf(".test.js") > -1 || file.indexOf("index.js") > -1) {
18
11
  return;
19
12
  }
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- const funcOrObj = (src as any)[file.replace(/\.(ts|js)$/, "")];
13
+ const funcOrObj = src[file.replace(".js", "")];
22
14
  if (!funcOrObj) {
23
15
  console.info(
24
16
  `Uh oh, it looks like you forgot to export (or explicitly ignore) this file:`,
@@ -0,0 +1,21 @@
1
+ import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
2
+ import provideInclusiveOptions from "./provideInclusiveOptions";
3
+ export default provideInclusiveOptions(invertRange);
4
+
5
+ function invertRange(rangeOrCaret, rangeMax) {
6
+ if (rangeOrCaret.start > -1) {
7
+ const start = rangeOrCaret.end + 1;
8
+ const end = rangeOrCaret.start - 1;
9
+ return {
10
+ start: normalizePositionByRangeLength(start, rangeMax, false),
11
+ end: normalizePositionByRangeLength(end, rangeMax, false)
12
+ };
13
+ } else {
14
+ if (rangeOrCaret > -1) {
15
+ return {
16
+ start: normalizePositionByRangeLength(rangeOrCaret, rangeMax, false),
17
+ end: normalizePositionByRangeLength(rangeOrCaret - 1, rangeMax, false)
18
+ };
19
+ }
20
+ }
21
+ }
@@ -1,12 +1,10 @@
1
1
  //function to calculate whether a position is closer to the range start than the range end
2
2
  import getShortestDistanceBetweenTwoPositions from "./getShortestDistanceBetweenTwoPositions";
3
3
 
4
- import { Range } from "./types";
5
-
6
4
  export default function isPositionCloserToRangeStartThanRangeEnd(
7
- position: number,
8
- range: Range,
9
- maxLength: number
5
+ position,
6
+ range,
7
+ maxLength
10
8
  ) {
11
9
  const distanceFromStart = getShortestDistanceBetweenTwoPositions(
12
10
  range.start,
@@ -1,13 +1,4 @@
1
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
2
  /**
12
3
  *
13
4
  * @param {*} position //assumed to be a 0 based "caretPosition"
@@ -16,11 +7,11 @@ import { Range } from "./types";
16
7
  * @param {*} includeEdges - (default false) whether or not to say
17
8
  */
18
9
  function isPositionWithinRange(
19
- position: number,
20
- range: Range,
21
- sequenceLength: number,
22
- includeStartEdge?: boolean,
23
- includeEndEdge?: boolean
10
+ position,
11
+ range,
12
+ sequenceLength,
13
+ includeStartEdge,
14
+ includeEndEdge
24
15
  ) {
25
16
  const ranges = splitRangeIntoTwoPartsIfItIsCircular(range, sequenceLength);
26
17
  const positionFits = ranges.some(function (range) {
@@ -2,14 +2,12 @@ import { isObject } from "lodash-es";
2
2
  import isRangeWithinRange from "./isRangeWithinRange";
3
3
  import isPositionWithinRange from "./isPositionWithinRange";
4
4
 
5
- import { Range } from "./types";
6
-
7
5
  export default function isRangeOrPositionWithinRange(
8
- rangeOrPositionToCheck: Range | number,
9
- containingRange: Range,
10
- maxLength: number,
11
- includeStartEdge?: boolean,
12
- includeEndEdge?: boolean
6
+ rangeOrPositionToCheck,
7
+ containingRange,
8
+ maxLength,
9
+ includeStartEdge,
10
+ includeEndEdge
13
11
  ) {
14
12
  if (
15
13
  rangeOrPositionToCheck === undefined ||
@@ -20,11 +18,8 @@ export default function isRangeOrPositionWithinRange(
20
18
  return false;
21
19
  }
22
20
  if (isObject(rangeOrPositionToCheck)) {
23
- if (typeof (rangeOrPositionToCheck as Range).start !== "number") {
24
- return false;
25
- }
26
21
  return isRangeWithinRange(
27
- rangeOrPositionToCheck as Range,
22
+ rangeOrPositionToCheck,
28
23
  containingRange,
29
24
  maxLength
30
25
  );
@@ -1,12 +1,10 @@
1
1
  //TNR: THIS METHOD ONLY WORKS FOR COMPARING 0-BASED RANGES!!!!!!
2
2
  import trimRangeByAnotherRange from "./trimRangeByAnotherRange";
3
3
 
4
- import { Range } from "./types";
5
-
6
4
  export default function isRangeWithinRange(
7
- rangeToCheck: Range,
8
- containingRange: Range,
9
- maxLength: number
5
+ rangeToCheck,
6
+ containingRange,
7
+ maxLength
10
8
  ) {
11
9
  const ranges = trimRangeByAnotherRange(
12
10
  rangeToCheck,
@@ -0,0 +1,5 @@
1
+ import getEachPositionInRangeAsArray from "./getEachPositionInRangeAsArray";
2
+
3
+ export default function loopEachPositionInRange(range, rangeMax, func) {
4
+ getEachPositionInRangeAsArray(range, rangeMax).map(func);
5
+ }
@@ -1,10 +1,5 @@
1
- import { Range } from "./types";
2
-
3
1
  //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
- ) {
2
+ export default function modulatePositionByRange(position, range) {
8
3
  let returnVal = position;
9
4
  if (position < range.start) {
10
5
  returnVal = range.end - (range.start - (position + 1));
@@ -1,11 +1,9 @@
1
- import { Range } from "./types";
2
-
3
1
  import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
4
2
  import provideInclusiveOptions from "./provideInclusiveOptions";
5
3
  import { assign } from "lodash-es";
6
4
  export default provideInclusiveOptions(modulateRangeBySequenceLength);
7
5
 
8
- function modulateRangeBySequenceLength(range: Range, seqLen: number) {
6
+ function modulateRangeBySequenceLength(range, seqLen) {
9
7
  return assign(range, {
10
8
  start: normalizePositionByRangeLength(range.start, seqLen),
11
9
  end: normalizePositionByRangeLength(range.end, seqLen)
@@ -1,15 +1,15 @@
1
1
  //
2
-
2
+ // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
3
3
  export default function normalizePositionByRangeLength(
4
- pPosition: number,
5
- sequenceLength: number,
6
- isInBetweenPositions = false
4
+ pPosition,
5
+ sequenceLength,
6
+ isInBetweenPositions
7
7
  ) {
8
8
  //isInBetweenPositions refers to:
9
9
  // A T G C
10
10
  // 0 1 2 3 <-- isInBetweenPositions = false is counting the positions themselves
11
11
  //0 1 2 3 4 <-- isInBetweenPositions = true is counting the spaces between positions
12
-
12
+ // ac.throw([ac.number, ac.posInt, ac.bool], arguments);
13
13
  let position = pPosition;
14
14
  if (position < 0) {
15
15
  position += sequenceLength;
@@ -19,6 +19,6 @@ export default function normalizePositionByRangeLength(
19
19
  return position < 0
20
20
  ? 0
21
21
  : position > sequenceLength - (isInBetweenPositions ? 0 : 1)
22
- ? sequenceLength - (isInBetweenPositions ? 0 : 1)
23
- : position;
22
+ ? sequenceLength - (isInBetweenPositions ? 0 : 1)
23
+ : position;
24
24
  }
@@ -1,9 +1,8 @@
1
- //
2
1
  import modulatePositionByRange from "./modulatePositionByRange";
3
2
 
4
3
  export default function normalizePositionByRangeLength1Based(
5
- position: number,
6
- sequenceLength: number
4
+ position,
5
+ sequenceLength
7
6
  ) {
8
7
  return modulatePositionByRange(position, { start: 1, end: sequenceLength });
9
8
  }
@@ -2,9 +2,8 @@
2
2
  import { assign } from "lodash-es";
3
3
 
4
4
  import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
5
- import { Range } from "./types";
6
5
 
7
- export default function normalizeRange(range: Range, sequenceLength: number) {
6
+ export default function normalizeRange(range, sequenceLength) {
8
7
  return assign({}, range, {
9
8
  start: normalizePositionByRangeLength(range.start, sequenceLength),
10
9
  end: normalizePositionByRangeLength(range.end, sequenceLength)
@@ -0,0 +1,39 @@
1
+ import { assign } from "lodash-es";
2
+
3
+ export default function provideInclusiveOptions(funToWrap) {
4
+ return function () {
5
+ const args = Array.prototype.slice.call(arguments);
6
+ const options = args[args.length - 1];
7
+ if (
8
+ options &&
9
+ (options.inclusive1BasedEnd || options.inclusive1BasedStart)
10
+ ) {
11
+ args.forEach(function (arg, index) {
12
+ if (arg && arg.start > -1 && options.inclusive1BasedStart) {
13
+ args[index] = assign(arg, { start: arg.start - 1 });
14
+ }
15
+ if (arg && arg.end > -1 && options.inclusive1BasedEnd) {
16
+ args[index] = assign(arg, { end: arg.end - 1 });
17
+ }
18
+ });
19
+ }
20
+ let returnVal = funToWrap.apply(this, args);
21
+ if (
22
+ returnVal &&
23
+ returnVal.start > -1 &&
24
+ options &&
25
+ options.inclusive1BasedStart
26
+ ) {
27
+ returnVal = assign(returnVal, { start: returnVal.start + 1 });
28
+ }
29
+ if (
30
+ returnVal &&
31
+ returnVal.end > -1 &&
32
+ options &&
33
+ options.inclusive1BasedEnd
34
+ ) {
35
+ returnVal = assign(returnVal, { end: returnVal.end + 1 });
36
+ }
37
+ return returnVal;
38
+ };
39
+ }
@@ -1,14 +1,14 @@
1
1
  //
2
2
  export default function reversePositionInRange(
3
- position: number,
4
- rangeLength: number,
5
- isInBetweenPositions: boolean
3
+ position,
4
+ rangeLength,
5
+ isInBetweenPositions
6
6
  ) {
7
7
  //isInBetweenPositions refers to:
8
8
  // A T G C
9
9
  // 0 1 2 3 <-- isInBetweenPositions = false is counting the positions themselves
10
10
  //0 1 2 3 4 <-- isInBetweenPositions = true is counting the spaces between positions
11
-
11
+ // ac.throw([
12
12
  // ac.posInt,
13
13
  // ac.posInt,
14
14
  // ac.bool
@@ -1,12 +1,11 @@
1
- import { Range } from "./types";
2
-
3
1
  //
4
-
2
+ // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
5
3
  //takes a potentially circular range and returns an array containing the range split on the origin
6
4
  export default function splitRangeIntoTwoPartsIfItIsCircular(
7
- range: Range,
8
- sequenceLength: number
5
+ range,
6
+ sequenceLength
9
7
  ) {
8
+ // ac.throw([ac.range, ac.number], arguments);
10
9
  if (sequenceLength !== 0) {
11
10
  sequenceLength = sequenceLength || Infinity;
12
11
  }
@@ -1,12 +1,10 @@
1
- import { Range } from "./types";
2
-
3
1
  import { assign } from "lodash-es";
4
2
  import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
5
3
 
6
4
  export default function translateRange(
7
- rangeToBeAdjusted: Range,
8
- translateBy: number,
9
- rangeLength: number
5
+ rangeToBeAdjusted,
6
+ translateBy,
7
+ rangeLength
10
8
  ) {
11
9
  return assign({}, rangeToBeAdjusted, {
12
10
  start: normalizePositionByRangeLength(
@@ -1,6 +1,6 @@
1
1
  export default function trimAnnStartEndToFitSeqLength(
2
- annStartOrEnd: number,
3
- sequenceLength: number
2
+ annStartOrEnd,
3
+ sequenceLength
4
4
  ) {
5
5
  return Math.max(
6
6
  0,
@@ -1,11 +1,9 @@
1
- //
2
- import { Range } from "./types";
3
-
4
1
  //
5
2
  export default function trimNonCicularRangeByAnotherNonCircularRange(
6
- rangeToBeTrimmed: Range,
7
- trimmingRange: Range
8
- ): Range | undefined {
3
+ rangeToBeTrimmed,
4
+ trimmingRange
5
+ ) {
6
+ // ac.throw([ac.range, ac.range], arguments);
9
7
  let outputTrimmedRange;
10
8
  if (!rangeToBeTrimmed) {
11
9
  return outputTrimmedRange;
@@ -1,9 +1,10 @@
1
1
  //
2
-
2
+ // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
3
3
  export default function trimNumberToFitWithin0ToAnotherNumber(
4
- numberToBeTrimmed: number,
5
- max: number
4
+ numberToBeTrimmed,
5
+ max
6
6
  ) {
7
+ // ac.throw([ac.number, ac.number], arguments);
7
8
  if (numberToBeTrimmed < 0) {
8
9
  numberToBeTrimmed = 0;
9
10
  }
@@ -2,7 +2,6 @@ import getOverlapsOfPotentiallyCircularRanges from "./getOverlapsOfPotentiallyCi
2
2
  import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIsCircular";
3
3
  import trimNonCicularRangeByAnotherNonCircularRange from "./trimNonCicularRangeByAnotherNonCircularRange";
4
4
  import { extend } from "lodash-es";
5
- import { Range } from "./types";
6
5
 
7
6
  /**
8
7
  * trims range, but does *not* adjust it
@@ -19,10 +18,10 @@ import { Range } from "./types";
19
18
  * }
20
19
  */
21
20
  export default function trimRangeByAnotherRange(
22
- rangeToBeTrimmed: Range,
23
- trimmingRange: Range,
24
- sequenceLength: number
25
- ): Range | undefined | null {
21
+ rangeToBeTrimmed,
22
+ trimmingRange,
23
+ sequenceLength
24
+ ) {
26
25
  if (!rangeToBeTrimmed || !trimmingRange) {
27
26
  console.warn("invalid range input");
28
27
  return null; //a null return val means something went wrong with this function
@@ -51,8 +50,10 @@ export default function trimRangeByAnotherRange(
51
50
  return rangeToBeTrimmed;
52
51
  }
53
52
  //and trim both pieces by the already calculated overlaps
54
- const splitRangesToBeTrimmed: (Range | undefined | null)[] =
55
- splitRangeIntoTwoPartsIfItIsCircular(rangeToBeTrimmed, sequenceLength);
53
+ const splitRangesToBeTrimmed = splitRangeIntoTwoPartsIfItIsCircular(
54
+ rangeToBeTrimmed,
55
+ sequenceLength
56
+ );
56
57
  splitRangesToBeTrimmed.forEach(function (nonCircularRangeToBeTrimmed, index) {
57
58
  overlaps.forEach(function (overlap) {
58
59
  if (nonCircularRangeToBeTrimmed) {
@@ -67,7 +68,7 @@ export default function trimRangeByAnotherRange(
67
68
  });
68
69
  //filter out any of the split ranges that have been fully deleted!
69
70
  const outputSplitRanges = splitRangesToBeTrimmed.filter(
70
- function (trimmedRange): trimmedRange is Range {
71
+ function (trimmedRange) {
71
72
  if (trimmedRange) {
72
73
  return true;
73
74
  }
@@ -99,5 +100,4 @@ export default function trimRangeByAnotherRange(
99
100
  end: outputTrimmedRange.end
100
101
  });
101
102
  }
102
- return undefined;
103
103
  }
@@ -1,9 +1,7 @@
1
1
  //
2
-
2
+ // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
3
3
  import trimRangeByAnotherRange from "./trimRangeByAnotherRange";
4
4
 
5
- import { Range } from "./types";
6
-
7
5
  /**
8
6
  * "zeroes" a subrange of a container range by
9
7
  * adjusting subRange start and end such that it is as if the container range start = 0.
@@ -19,10 +17,11 @@ import { Range } from "./types";
19
17
  * }
20
18
  */
21
19
  export default function zeroSubrangeByContainerRange(
22
- subRange: Range,
23
- containerRange: Range,
24
- sequenceLength: number
20
+ subRange,
21
+ containerRange,
22
+ sequenceLength
25
23
  ) {
24
+ // ac.throw([ac.range, ac.range, ac.posInt], arguments);
26
25
  //first check to make sure the container range fully contains the subRange
27
26
  const trimmedSubRange = trimRangeByAnotherRange(
28
27
  subRange,
@@ -34,10 +33,9 @@ export default function zeroSubrangeByContainerRange(
34
33
  "subRange must be fully contained by containerRange! Otherwise this function does not make sense"
35
34
  );
36
35
  }
37
- const newSubrange: Range = {
38
- start: subRange.start - containerRange.start,
39
- end: subRange.end - containerRange.start
40
- };
36
+ const newSubrange = {};
37
+ newSubrange.start = subRange.start - containerRange.start;
38
+ newSubrange.end = subRange.end - containerRange.start;
41
39
  if (newSubrange.start < 0) {
42
40
  newSubrange.start += sequenceLength;
43
41
  }
@@ -1,5 +1 @@
1
- import { Range } from './types';
2
- export default function translateRange(rangeToBeAdjusted: Range, translateBy: number, rangeLength: number): Range & {
3
- start: number;
4
- end: number;
5
- };
1
+ export default function translateRange(rangeToBeAdjusted: any, translateBy: any, rangeLength: any): any;
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- export default function trimAnnStartEndToFitSeqLength(annStartOrEnd: number, sequenceLength: number): number;
1
+ export default function trimAnnStartEndToFitSeqLength(annStartOrEnd: any, sequenceLength: any): number;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,4 @@
1
- import { Range } from './types';
2
- export default function trimNonCicularRangeByAnotherNonCircularRange(rangeToBeTrimmed: Range, trimmingRange: Range): Range | undefined;
1
+ export default function trimNonCicularRangeByAnotherNonCircularRange(rangeToBeTrimmed: any, trimmingRange: any): {
2
+ start: any;
3
+ end: any;
4
+ } | undefined;
@@ -1 +1 @@
1
- export default function trimNumberToFitWithin0ToAnotherNumber(numberToBeTrimmed: number, max: number): number;
1
+ export default function trimNumberToFitWithin0ToAnotherNumber(numberToBeTrimmed: any, max: any): any;
@@ -1,4 +1,3 @@
1
- import { Range } from './types';
2
1
  /**
3
2
  * trims range, but does *not* adjust it
4
3
  * returns a new range if there is one, or null, if it is trimmed completely
@@ -13,4 +12,4 @@ import { Range } from './types';
13
12
  * end:
14
13
  * }
15
14
  */
16
- export default function trimRangeByAnotherRange(rangeToBeTrimmed: Range, trimmingRange: Range, sequenceLength: number): Range | undefined | null;
15
+ export default function trimRangeByAnotherRange(rangeToBeTrimmed: any, trimmingRange: any, sequenceLength: int): object;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,3 @@
1
- import { Range } from './types';
2
1
  /**
3
2
  * "zeroes" a subrange of a container range by
4
3
  * adjusting subRange start and end such that it is as if the container range start = 0.
@@ -13,4 +12,4 @@ import { Range } from './types';
13
12
  * end:
14
13
  * }
15
14
  */
16
- export default function zeroSubrangeByContainerRange(subRange: Range, containerRange: Range, sequenceLength: number): Range;
15
+ export default function zeroSubrangeByContainerRange(subRange: object, containerRange: object, sequenceLength: int): object;
@@ -0,0 +1 @@
1
+ export {};
package/RangeAngles.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export interface RangeAngles {
2
- startAngle: number;
3
- totalAngle: number;
4
- endAngle: number;
5
- centerAngle: number;
6
- locationAngles?: RangeAngles[];
7
- }
@@ -1,9 +0,0 @@
1
- //
2
-
3
- export interface RangeAngles {
4
- startAngle: number;
5
- totalAngle: number;
6
- endAngle: number;
7
- centerAngle: number;
8
- locationAngles?: RangeAngles[];
9
- }
@@ -1,22 +0,0 @@
1
- import { assign } from "lodash-es";
2
-
3
- import { Range } from "./types";
4
-
5
- export default function adjustRangeToRotation<T extends Range>(
6
- rangeToBeAdjusted: T,
7
- rotateTo = 0,
8
- rangeLength?: number
9
- ): T {
10
- const mod = (n: number) => (rangeLength ? modulo(n, rangeLength) : n);
11
-
12
- const newRange = assign({}, rangeToBeAdjusted, {
13
- start: mod(rangeToBeAdjusted.start - (rotateTo || 0)),
14
- end: mod(rangeToBeAdjusted.end - (rotateTo || 0))
15
- });
16
-
17
- return newRange as T;
18
- }
19
-
20
- function modulo(n: number, m: number) {
21
- return ((n % m) + m) % m;
22
- }
@@ -1,12 +0,0 @@
1
- import getRangeLength from "./getRangeLength";
2
- import { Range } from "./types";
3
-
4
- export default function doesRangeSpanEntireSequence(
5
- range: Range,
6
- sequenceLength: number
7
- ) {
8
- if (getRangeLength(range, sequenceLength) === sequenceLength) {
9
- return true;
10
- }
11
- return false;
12
- }
@@ -1,5 +0,0 @@
1
- import { Range } from "./types";
2
-
3
- export default function doesRangeSpanOrigin(range: Range) {
4
- return range.start > range.end;
5
- }