@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.
- package/adjustRangeToDeletionOfAnotherRange.d.ts +1 -2
- package/adjustRangeToDeletionOfAnotherRange.test.d.ts +1 -0
- package/adjustRangeToInsert.d.ts +1 -2
- package/adjustRangeToInsert.test.d.ts +1 -0
- package/adjustRangeToRotation.d.ts +1 -2
- package/adjustRangeToRotation.test.d.ts +1 -0
- package/checkIfNonCircularRangesOverlap.d.ts +1 -2
- package/checkIfNonCircularRangesOverlap.test.d.ts +1 -0
- package/checkIfPotentiallyCircularRangesOverlap.d.ts +1 -2
- package/checkIfPotentiallyCircularRangesOverlap.test.d.ts +1 -0
- package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.d.ts +1 -2
- package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.test.d.ts +1 -0
- package/convertRangeIndices.d.ts +1 -10
- package/convertRangeIndices.test.d.ts +1 -0
- package/convertRangeTo0Based.d.ts +1 -5
- package/convertRangeTo1Based.d.ts +1 -5
- package/doesRangeSpanEntireSequence.d.ts +1 -2
- package/doesRangeSpanOrigin.d.ts +1 -2
- package/expandOrContractCircularRangeToPosition.d.ts +2 -3
- package/expandOrContractNonCircularRangeToPosition.d.ts +2 -3
- package/expandOrContractRangeByLength.d.ts +1 -5
- package/expandOrContractRangeByLength.test.d.ts +1 -0
- package/expandOrContractRangeToPosition.d.ts +2 -3
- package/flipContainedRange.d.ts +1 -5
- package/flipContainedRange.test.d.ts +1 -0
- package/generateRandomRange.d.ts +3 -3
- package/generateRandomRange.test.d.ts +1 -0
- package/getAnnotationRangeType.d.ts +1 -2
- package/getAnnotationRangeType.test.d.ts +1 -0
- package/getEachPositionInRangeAsArray.d.ts +1 -2
- package/getEachPositionInRangeAsArray.test.d.ts +1 -0
- package/getLengthOfOverlappingRegionsBetweenTwoRanges.d.ts +1 -2
- package/getLengthOfOverlappingRegionsBetweenTwoRanges.test.d.ts +1 -0
- package/getMiddleOfRange.d.ts +1 -2
- package/getMiddleOfRange.test.d.ts +1 -0
- package/getOverlapOfNonCircularRanges.d.ts +4 -5
- package/getOverlapsOfPotentiallyCircularRanges.d.ts +1 -2
- package/getOverlapsOfPotentiallyCircularRanges.test.d.ts +1 -0
- package/getPositionFromAngle.d.ts +1 -1
- package/getRangeAngles.d.ts +7 -3
- package/getRangeAngles.test.d.ts +1 -0
- package/getRangeLength.d.ts +1 -5
- package/getRangeLength.test.d.ts +1 -0
- package/getRangesBetweenTwoRanges.d.ts +1 -2
- package/getSequenceWithinRange.d.ts +1 -3
- package/getSequenceWithinRange.test.d.ts +1 -0
- package/getShortestDistanceBetweenTwoPositions.d.ts +1 -1
- package/getShortestDistanceBetweenTwoPositions.test.d.ts +1 -0
- package/getYOffsetForPotentiallyCircularRange.d.ts +1 -2
- package/getYOffsetsForPotentiallyCircularRanges.d.ts +2 -3
- package/getYOffsetsForPotentiallyCircularRanges.test.d.ts +1 -0
- package/getZeroedRangeOverlaps.d.ts +1 -2
- package/getZeroedRangeOverlaps.test.d.ts +1 -0
- package/index.cjs +45 -58
- package/index.d.ts +0 -1
- package/index.js +45 -58
- package/index.test.d.ts +1 -0
- package/index.umd.cjs +45 -58
- package/invertRange.d.ts +1 -5
- package/invertRange.test.d.ts +1 -0
- package/isPositionCloserToRangeStartThanRangeEnd.d.ts +1 -2
- package/isPositionCloserToRangeStartThanRangeEnd.test.d.ts +1 -0
- package/isPositionWithinRange.d.ts +2 -3
- package/isRangeOrPositionWithinRange.d.ts +1 -2
- package/isRangeOrPositionWithinRange.test.d.ts +1 -0
- package/isRangeWithinRange.d.ts +1 -2
- package/loopEachPositionInRange.d.ts +1 -2
- package/modulatePositionByRange.d.ts +1 -2
- package/modulatePositionByRange.test.d.ts +1 -0
- package/modulateRangeBySequenceLength.d.ts +1 -8
- package/modulateRangeBySequenceLength.test.d.ts +1 -0
- package/normalizePositionByRangeLength.d.ts +1 -1
- package/normalizePositionByRangeLength.test.d.ts +1 -0
- package/normalizePositionByRangeLength1Based.d.ts +1 -1
- package/normalizePositionByRangeLength1Based.test.d.ts +1 -0
- package/normalizeRange.d.ts +1 -5
- package/normalizeRange.test.d.ts +1 -0
- package/package.json +2 -10
- package/provideInclusiveOptions.d.ts +1 -6
- package/reversePositionInRange.d.ts +1 -1
- package/splitRangeIntoTwoPartsIfItIsCircular.d.ts +3 -4
- package/splitRangeIntoTwoPartsIfItIsCircular.test.d.ts +1 -0
- package/src/{adjustRangeToDeletionOfAnotherRange.ts → adjustRangeToDeletionOfAnotherRange.js} +7 -4
- package/src/{adjustRangeToInsert.ts → adjustRangeToInsert.js} +4 -4
- package/src/adjustRangeToRotation.js +23 -0
- package/src/{checkIfNonCircularRangesOverlap.ts → checkIfNonCircularRangesOverlap.js} +4 -5
- package/src/{checkIfPotentiallyCircularRangesOverlap.ts → checkIfPotentiallyCircularRangesOverlap.js} +4 -4
- package/src/{collapseOverlapsGeneratedFromRangeComparisonIfPossible.ts → collapseOverlapsGeneratedFromRangeComparisonIfPossible.js} +4 -7
- package/src/{convertRangeIndices.ts → convertRangeIndices.js} +3 -11
- package/src/{convertRangeTo0Based.ts → convertRangeTo0Based.js} +1 -2
- package/src/{convertRangeTo1Based.ts → convertRangeTo1Based.js} +1 -2
- package/src/doesRangeSpanEntireSequence.js +7 -0
- package/src/doesRangeSpanOrigin.js +3 -0
- package/src/{expandOrContractCircularRangeToPosition.ts → expandOrContractCircularRangeToPosition.js} +3 -5
- package/src/{expandOrContractNonCircularRangeToPosition.ts → expandOrContractNonCircularRangeToPosition.js} +2 -4
- package/src/{expandOrContractRangeByLength.ts → expandOrContractRangeByLength.js} +4 -5
- package/src/{expandOrContractRangeToPosition.ts → expandOrContractRangeToPosition.js} +8 -6
- package/src/{flipContainedRange.ts → flipContainedRange.js} +8 -18
- package/src/{generateRandomRange.ts → generateRandomRange.js} +2 -6
- package/src/{getAnnotationRangeType.ts → getAnnotationRangeType.js} +3 -5
- package/src/{getEachPositionInRangeAsArray.ts → getEachPositionInRangeAsArray.js} +2 -6
- package/src/{getLengthOfOverlappingRegionsBetweenTwoRanges.ts → getLengthOfOverlappingRegionsBetweenTwoRanges.js} +3 -4
- package/src/{getMiddleOfRange.ts → getMiddleOfRange.js} +1 -2
- package/src/{getOverlapOfNonCircularRanges.ts → getOverlapOfNonCircularRanges.js} +1 -7
- package/src/{getOverlapsOfPotentiallyCircularRanges.ts → getOverlapsOfPotentiallyCircularRanges.js} +7 -13
- package/src/{getPositionFromAngle.ts → getPositionFromAngle.js} +3 -3
- package/src/{getRangeAngles.ts → getRangeAngles.js} +3 -8
- package/src/{getRangeLength.ts → getRangeLength.js} +1 -4
- package/src/{getRangesBetweenTwoRanges.ts → getRangesBetweenTwoRanges.js} +2 -7
- package/src/getSequenceWithinRange.js +17 -0
- package/src/{getShortestDistanceBetweenTwoPositions.ts → getShortestDistanceBetweenTwoPositions.js} +3 -3
- package/src/{getYOffsetForPotentiallyCircularRange.ts → getYOffsetForPotentiallyCircularRange.js} +4 -5
- package/src/{getYOffsetsForPotentiallyCircularRanges.ts → getYOffsetsForPotentiallyCircularRanges.js} +4 -5
- package/src/getYOffsetsForPotentiallyCircularRanges.test.js +42 -0
- package/src/{getZeroedRangeOverlaps.ts → getZeroedRangeOverlaps.js} +3 -4
- package/src/{getZeroedRangeOverlaps.test.ts → getZeroedRangeOverlaps.test.js} +15 -5
- package/src/{index.ts → index.js} +0 -1
- package/src/{index.test.ts → index.test.js} +3 -11
- package/src/invertRange.js +21 -0
- package/src/{isPositionCloserToRangeStartThanRangeEnd.ts → isPositionCloserToRangeStartThanRangeEnd.js} +3 -5
- package/src/{isPositionWithinRange.ts → isPositionWithinRange.js} +5 -14
- package/src/{isRangeOrPositionWithinRange.ts → isRangeOrPositionWithinRange.js} +6 -11
- package/src/{isRangeWithinRange.ts → isRangeWithinRange.js} +3 -5
- package/src/loopEachPositionInRange.js +5 -0
- package/src/{modulatePositionByRange.ts → modulatePositionByRange.js} +1 -6
- package/src/{modulateRangeBySequenceLength.ts → modulateRangeBySequenceLength.js} +1 -3
- package/src/{normalizePositionByRangeLength.ts → normalizePositionByRangeLength.js} +7 -7
- package/src/{normalizePositionByRangeLength1Based.ts → normalizePositionByRangeLength1Based.js} +2 -3
- package/src/{normalizeRange.ts → normalizeRange.js} +1 -2
- package/src/provideInclusiveOptions.js +39 -0
- package/src/{reversePositionInRange.ts → reversePositionInRange.js} +4 -4
- package/src/{splitRangeIntoTwoPartsIfItIsCircular.ts → splitRangeIntoTwoPartsIfItIsCircular.js} +4 -5
- package/src/{translateRange.ts → translateRange.js} +3 -5
- package/src/{trimAnnStartEndToFitSeqLength.ts → trimAnnStartEndToFitSeqLength.js} +2 -2
- package/src/{trimNonCicularRangeByAnotherNonCircularRange.ts → trimNonCicularRangeByAnotherNonCircularRange.js} +4 -6
- package/src/{trimNumberToFitWithin0ToAnotherNumber.ts → trimNumberToFitWithin0ToAnotherNumber.js} +4 -3
- package/src/{trimRangeByAnotherRange.ts → trimRangeByAnotherRange.js} +9 -9
- package/src/{zeroSubrangeByContainerRange.ts → zeroSubrangeByContainerRange.js} +8 -10
- package/translateRange.d.ts +1 -5
- package/translateRange.test.d.ts +1 -0
- package/trimAnnStartEndToFitSeqLength.d.ts +1 -1
- package/trimAnnStartEndToFitSeqLength.test.d.ts +1 -0
- package/trimNonCicularRangeByAnotherNonCircularRange.d.ts +4 -2
- package/trimNumberToFitWithin0ToAnotherNumber.d.ts +1 -1
- package/trimRangeByAnotherRange.d.ts +1 -2
- package/trimRangeByAnotherRange.test.d.ts +1 -0
- package/zeroSubrangeByContainerRange.d.ts +1 -2
- package/zeroSubrangeByContainerRange.test.d.ts +1 -0
- package/RangeAngles.d.ts +0 -7
- package/src/RangeAngles.ts +0 -9
- package/src/adjustRangeToRotation.ts +0 -22
- package/src/doesRangeSpanEntireSequence.ts +0 -12
- package/src/doesRangeSpanOrigin.ts +0 -5
- package/src/getSequenceWithinRange.ts +0 -33
- package/src/getYOffsetsForPotentiallyCircularRanges.test.ts +0 -17
- package/src/invertRange.ts +0 -25
- package/src/loopEachPositionInRange.ts +0 -11
- package/src/provideInclusiveOptions.ts +0 -79
- package/src/types.ts +0 -12
- package/types.d.ts +0 -12
- /package/src/{getRangeLength.test.ts → getRangeLength.test.js} +0 -0
- /package/src/{getSequenceWithinRange.test.ts → getSequenceWithinRange.test.js} +0 -0
- /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
|
|
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
|
-
|
|
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
|
|
8
|
-
range
|
|
9
|
-
maxLength
|
|
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
|
|
20
|
-
range
|
|
21
|
-
sequenceLength
|
|
22
|
-
includeStartEdge
|
|
23
|
-
includeEndEdge
|
|
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
|
|
9
|
-
containingRange
|
|
10
|
-
maxLength
|
|
11
|
-
includeStartEdge
|
|
12
|
-
includeEndEdge
|
|
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
|
|
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
|
|
8
|
-
containingRange
|
|
9
|
-
maxLength
|
|
5
|
+
rangeToCheck,
|
|
6
|
+
containingRange,
|
|
7
|
+
maxLength
|
|
10
8
|
) {
|
|
11
9
|
const ranges = trimRangeByAnotherRange(
|
|
12
10
|
rangeToCheck,
|
|
@@ -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
|
|
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
|
|
5
|
-
sequenceLength
|
|
6
|
-
isInBetweenPositions
|
|
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
|
-
|
|
23
|
-
|
|
22
|
+
? sequenceLength - (isInBetweenPositions ? 0 : 1)
|
|
23
|
+
: position;
|
|
24
24
|
}
|
package/src/{normalizePositionByRangeLength1Based.ts → normalizePositionByRangeLength1Based.js}
RENAMED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
//
|
|
2
1
|
import modulatePositionByRange from "./modulatePositionByRange";
|
|
3
2
|
|
|
4
3
|
export default function normalizePositionByRangeLength1Based(
|
|
5
|
-
position
|
|
6
|
-
sequenceLength
|
|
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
|
|
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
|
|
4
|
-
rangeLength
|
|
5
|
-
isInBetweenPositions
|
|
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
|
package/src/{splitRangeIntoTwoPartsIfItIsCircular.ts → splitRangeIntoTwoPartsIfItIsCircular.js}
RENAMED
|
@@ -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
|
|
8
|
-
sequenceLength
|
|
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
|
|
8
|
-
translateBy
|
|
9
|
-
rangeLength
|
|
5
|
+
rangeToBeAdjusted,
|
|
6
|
+
translateBy,
|
|
7
|
+
rangeLength
|
|
10
8
|
) {
|
|
11
9
|
return assign({}, rangeToBeAdjusted, {
|
|
12
10
|
start: normalizePositionByRangeLength(
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { Range } from "./types";
|
|
3
|
-
|
|
4
1
|
//
|
|
5
2
|
export default function trimNonCicularRangeByAnotherNonCircularRange(
|
|
6
|
-
rangeToBeTrimmed
|
|
7
|
-
trimmingRange
|
|
8
|
-
)
|
|
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;
|
package/src/{trimNumberToFitWithin0ToAnotherNumber.ts → trimNumberToFitWithin0ToAnotherNumber.js}
RENAMED
|
@@ -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
|
|
5
|
-
max
|
|
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
|
|
23
|
-
trimmingRange
|
|
24
|
-
sequenceLength
|
|
25
|
-
)
|
|
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
|
|
55
|
-
|
|
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)
|
|
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
|
|
23
|
-
containerRange
|
|
24
|
-
sequenceLength
|
|
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
|
|
38
|
-
|
|
39
|
-
|
|
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
|
}
|
package/translateRange.d.ts
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
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:
|
|
1
|
+
export default function trimAnnStartEndToFitSeqLength(annStartOrEnd: any, sequenceLength: any): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
15
|
+
export default function zeroSubrangeByContainerRange(subRange: object, containerRange: object, sequenceLength: int): object;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/RangeAngles.d.ts
DELETED
package/src/RangeAngles.ts
DELETED
|
@@ -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
|
-
}
|