@teselagen/range-utils 0.3.18 → 0.3.20-beta.1
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/README.md +0 -10
- package/RangeAngles.d.ts +7 -0
- package/adjustRangeToDeletionOfAnotherRange.d.ts +2 -1
- package/adjustRangeToInsert.d.ts +2 -1
- package/adjustRangeToRotation.d.ts +2 -1
- package/checkIfNonCircularRangesOverlap.d.ts +2 -1
- package/checkIfPotentiallyCircularRangesOverlap.d.ts +2 -1
- package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.d.ts +2 -1
- package/convertRangeIndices.d.ts +10 -1
- package/convertRangeTo0Based.d.ts +5 -1
- package/convertRangeTo1Based.d.ts +5 -1
- package/doesRangeSpanEntireSequence.d.ts +2 -1
- package/doesRangeSpanOrigin.d.ts +2 -1
- package/expandOrContractCircularRangeToPosition.d.ts +3 -2
- package/expandOrContractNonCircularRangeToPosition.d.ts +3 -2
- package/expandOrContractRangeByLength.d.ts +5 -1
- package/expandOrContractRangeToPosition.d.ts +3 -2
- package/flipContainedRange.d.ts +5 -1
- package/generateRandomRange.d.ts +3 -3
- package/getAnnotationRangeType.d.ts +2 -1
- package/getEachPositionInRangeAsArray.d.ts +2 -1
- package/getLengthOfOverlappingRegionsBetweenTwoRanges.d.ts +2 -1
- package/getMiddleOfRange.d.ts +2 -1
- package/getOverlapOfNonCircularRanges.d.ts +5 -4
- package/getOverlapsOfPotentiallyCircularRanges.d.ts +2 -1
- package/getPositionFromAngle.d.ts +1 -1
- package/getRangeAngles.d.ts +3 -7
- package/getRangeLength.d.ts +5 -1
- package/getRangesBetweenTwoRanges.d.ts +2 -1
- package/getSequenceWithinRange.d.ts +3 -1
- package/getShortestDistanceBetweenTwoPositions.d.ts +1 -1
- package/getYOffsetForPotentiallyCircularRange.d.ts +2 -1
- package/getYOffsetsForPotentiallyCircularRanges.d.ts +3 -2
- package/getZeroedRangeOverlaps.d.ts +2 -1
- package/index.cjs +58 -45
- package/index.d.ts +1 -0
- package/index.js +58 -45
- package/index.umd.cjs +58 -45
- package/invertRange.d.ts +5 -1
- package/isPositionCloserToRangeStartThanRangeEnd.d.ts +2 -1
- package/isPositionWithinRange.d.ts +3 -2
- package/isRangeOrPositionWithinRange.d.ts +2 -1
- package/isRangeWithinRange.d.ts +2 -1
- package/loopEachPositionInRange.d.ts +2 -1
- package/modulatePositionByRange.d.ts +2 -1
- package/modulateRangeBySequenceLength.d.ts +8 -1
- package/normalizePositionByRangeLength.d.ts +1 -1
- package/normalizePositionByRangeLength1Based.d.ts +1 -1
- package/normalizeRange.d.ts +5 -1
- package/package.json +10 -2
- package/provideInclusiveOptions.d.ts +6 -1
- package/reversePositionInRange.d.ts +1 -1
- package/splitRangeIntoTwoPartsIfItIsCircular.d.ts +4 -3
- package/src/RangeAngles.ts +9 -0
- package/src/{adjustRangeToDeletionOfAnotherRange.js → adjustRangeToDeletionOfAnotherRange.ts} +4 -7
- package/src/{adjustRangeToInsert.js → adjustRangeToInsert.ts} +4 -4
- package/src/adjustRangeToRotation.ts +22 -0
- package/src/{checkIfNonCircularRangesOverlap.js → checkIfNonCircularRangesOverlap.ts} +5 -4
- package/src/{checkIfPotentiallyCircularRangesOverlap.js → checkIfPotentiallyCircularRangesOverlap.ts} +4 -4
- package/src/{collapseOverlapsGeneratedFromRangeComparisonIfPossible.js → collapseOverlapsGeneratedFromRangeComparisonIfPossible.ts} +7 -4
- package/src/{convertRangeIndices.js → convertRangeIndices.ts} +11 -3
- package/src/{convertRangeTo0Based.js → convertRangeTo0Based.ts} +2 -1
- package/src/{convertRangeTo1Based.js → convertRangeTo1Based.ts} +2 -1
- package/src/doesRangeSpanEntireSequence.ts +12 -0
- package/src/doesRangeSpanOrigin.ts +5 -0
- package/src/{expandOrContractCircularRangeToPosition.js → expandOrContractCircularRangeToPosition.ts} +5 -3
- package/src/{expandOrContractNonCircularRangeToPosition.js → expandOrContractNonCircularRangeToPosition.ts} +4 -2
- package/src/{expandOrContractRangeByLength.js → expandOrContractRangeByLength.ts} +5 -4
- package/src/{expandOrContractRangeToPosition.js → expandOrContractRangeToPosition.ts} +6 -8
- package/src/{flipContainedRange.js → flipContainedRange.ts} +18 -8
- package/src/{generateRandomRange.js → generateRandomRange.ts} +6 -2
- package/src/{getAnnotationRangeType.js → getAnnotationRangeType.ts} +5 -3
- package/src/{getEachPositionInRangeAsArray.js → getEachPositionInRangeAsArray.ts} +6 -2
- package/src/{getLengthOfOverlappingRegionsBetweenTwoRanges.js → getLengthOfOverlappingRegionsBetweenTwoRanges.ts} +4 -3
- package/src/{getMiddleOfRange.js → getMiddleOfRange.ts} +2 -1
- package/src/{getOverlapOfNonCircularRanges.js → getOverlapOfNonCircularRanges.ts} +7 -1
- package/src/{getOverlapsOfPotentiallyCircularRanges.js → getOverlapsOfPotentiallyCircularRanges.ts} +13 -7
- package/src/{getPositionFromAngle.js → getPositionFromAngle.ts} +3 -3
- package/src/{getRangeAngles.js → getRangeAngles.ts} +8 -3
- package/src/{getRangeLength.js → getRangeLength.ts} +4 -1
- package/src/{getRangesBetweenTwoRanges.js → getRangesBetweenTwoRanges.ts} +7 -2
- package/src/getSequenceWithinRange.ts +33 -0
- package/src/{getShortestDistanceBetweenTwoPositions.js → getShortestDistanceBetweenTwoPositions.ts} +3 -3
- package/src/{getYOffsetForPotentiallyCircularRange.js → getYOffsetForPotentiallyCircularRange.ts} +5 -4
- package/src/getYOffsetsForPotentiallyCircularRanges.test.ts +17 -0
- package/src/{getYOffsetsForPotentiallyCircularRanges.js → getYOffsetsForPotentiallyCircularRanges.ts} +5 -4
- package/src/{getZeroedRangeOverlaps.test.js → getZeroedRangeOverlaps.test.ts} +5 -15
- package/src/{getZeroedRangeOverlaps.js → getZeroedRangeOverlaps.ts} +4 -3
- package/src/{index.test.js → index.test.ts} +11 -3
- package/src/{index.js → index.ts} +1 -0
- package/src/invertRange.ts +25 -0
- package/src/{isPositionCloserToRangeStartThanRangeEnd.js → isPositionCloserToRangeStartThanRangeEnd.ts} +5 -3
- package/src/{isPositionWithinRange.js → isPositionWithinRange.ts} +14 -5
- package/src/{isRangeOrPositionWithinRange.js → isRangeOrPositionWithinRange.ts} +11 -6
- package/src/{isRangeWithinRange.js → isRangeWithinRange.ts} +5 -3
- package/src/loopEachPositionInRange.ts +11 -0
- package/src/{modulatePositionByRange.js → modulatePositionByRange.ts} +6 -1
- package/src/{modulateRangeBySequenceLength.js → modulateRangeBySequenceLength.ts} +3 -1
- package/src/{normalizePositionByRangeLength.js → normalizePositionByRangeLength.ts} +7 -7
- package/src/{normalizePositionByRangeLength1Based.js → normalizePositionByRangeLength1Based.ts} +3 -2
- package/src/{normalizeRange.js → normalizeRange.ts} +2 -1
- package/src/provideInclusiveOptions.ts +79 -0
- package/src/{reversePositionInRange.js → reversePositionInRange.ts} +4 -4
- package/src/{splitRangeIntoTwoPartsIfItIsCircular.js → splitRangeIntoTwoPartsIfItIsCircular.ts} +5 -4
- package/src/{translateRange.js → translateRange.ts} +5 -3
- package/src/{trimAnnStartEndToFitSeqLength.js → trimAnnStartEndToFitSeqLength.ts} +2 -2
- package/src/{trimNonCicularRangeByAnotherNonCircularRange.js → trimNonCicularRangeByAnotherNonCircularRange.ts} +6 -4
- package/src/{trimNumberToFitWithin0ToAnotherNumber.js → trimNumberToFitWithin0ToAnotherNumber.ts} +3 -4
- package/src/{trimRangeByAnotherRange.js → trimRangeByAnotherRange.ts} +9 -9
- package/src/types.ts +12 -0
- package/src/{zeroSubrangeByContainerRange.js → zeroSubrangeByContainerRange.ts} +10 -8
- package/translateRange.d.ts +5 -1
- package/trimAnnStartEndToFitSeqLength.d.ts +1 -1
- package/trimNonCicularRangeByAnotherNonCircularRange.d.ts +2 -4
- package/trimNumberToFitWithin0ToAnotherNumber.d.ts +1 -1
- package/trimRangeByAnotherRange.d.ts +2 -1
- package/types.d.ts +12 -0
- package/zeroSubrangeByContainerRange.d.ts +2 -1
- package/adjustRangeToDeletionOfAnotherRange.test.d.ts +0 -1
- package/adjustRangeToInsert.test.d.ts +0 -1
- package/adjustRangeToRotation.test.d.ts +0 -1
- package/checkIfNonCircularRangesOverlap.test.d.ts +0 -1
- package/checkIfPotentiallyCircularRangesOverlap.test.d.ts +0 -1
- package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.test.d.ts +0 -1
- package/convertRangeIndices.test.d.ts +0 -1
- package/expandOrContractRangeByLength.test.d.ts +0 -1
- package/flipContainedRange.test.d.ts +0 -1
- package/generateRandomRange.test.d.ts +0 -1
- package/getAnnotationRangeType.test.d.ts +0 -1
- package/getEachPositionInRangeAsArray.test.d.ts +0 -1
- package/getLengthOfOverlappingRegionsBetweenTwoRanges.test.d.ts +0 -1
- package/getMiddleOfRange.test.d.ts +0 -1
- package/getOverlapsOfPotentiallyCircularRanges.test.d.ts +0 -1
- package/getRangeAngles.test.d.ts +0 -1
- package/getRangeLength.test.d.ts +0 -1
- package/getSequenceWithinRange.test.d.ts +0 -1
- package/getShortestDistanceBetweenTwoPositions.test.d.ts +0 -1
- package/getYOffsetsForPotentiallyCircularRanges.test.d.ts +0 -1
- package/getZeroedRangeOverlaps.test.d.ts +0 -1
- package/index.test.d.ts +0 -1
- package/invertRange.test.d.ts +0 -1
- package/isPositionCloserToRangeStartThanRangeEnd.test.d.ts +0 -1
- package/isRangeOrPositionWithinRange.test.d.ts +0 -1
- package/modulatePositionByRange.test.d.ts +0 -1
- package/modulateRangeBySequenceLength.test.d.ts +0 -1
- package/normalizePositionByRangeLength.test.d.ts +0 -1
- package/normalizePositionByRangeLength1Based.test.d.ts +0 -1
- package/normalizeRange.test.d.ts +0 -1
- package/splitRangeIntoTwoPartsIfItIsCircular.test.d.ts +0 -1
- package/src/adjustRangeToRotation.js +0 -23
- package/src/doesRangeSpanEntireSequence.js +0 -7
- package/src/doesRangeSpanOrigin.js +0 -3
- package/src/getSequenceWithinRange.js +0 -17
- package/src/getYOffsetsForPotentiallyCircularRanges.test.js +0 -42
- package/src/invertRange.js +0 -21
- package/src/loopEachPositionInRange.js +0 -5
- package/src/provideInclusiveOptions.js +0 -39
- package/translateRange.test.d.ts +0 -1
- package/trimAnnStartEndToFitSeqLength.test.d.ts +0 -1
- package/trimRangeByAnotherRange.test.d.ts +0 -1
- package/zeroSubrangeByContainerRange.test.d.ts +0 -1
- /package/src/{getRangeLength.test.js → getRangeLength.test.ts} +0 -0
- /package/src/{getSequenceWithinRange.test.js → getSequenceWithinRange.test.ts} +0 -0
- /package/src/{getShortestDistanceBetweenTwoPositions.test.js → getShortestDistanceBetweenTwoPositions.test.ts} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Range } from "./types";
|
|
1
2
|
import getOverlapsOfPotentiallyCircularRanges from "./getOverlapsOfPotentiallyCircularRanges";
|
|
2
3
|
import collapseOverlapsGeneratedFromRangeComparisonIfPossible from "./collapseOverlapsGeneratedFromRangeComparisonIfPossible";
|
|
3
4
|
import zeroSubrangeByContainerRange from "./zeroSubrangeByContainerRange";
|
|
@@ -5,9 +6,9 @@ import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
|
|
5
6
|
|
|
6
7
|
//gets the overlapping sections of two ranges and zeroes them to their first point of intersection!
|
|
7
8
|
export default function getZeroedRangeOverlaps(
|
|
8
|
-
annotation,
|
|
9
|
-
selection,
|
|
10
|
-
sequenceLength
|
|
9
|
+
annotation: Range,
|
|
10
|
+
selection: Range,
|
|
11
|
+
sequenceLength: number
|
|
11
12
|
) {
|
|
12
13
|
const overlaps = collapseOverlapsGeneratedFromRangeComparisonIfPossible(
|
|
13
14
|
getOverlapsOfPotentiallyCircularRanges(
|
|
@@ -3,14 +3,22 @@ import fs from "fs";
|
|
|
3
3
|
|
|
4
4
|
describe("index.js", () => {
|
|
5
5
|
it(`should export all functions defined`, () => {
|
|
6
|
-
return new Promise(resolve => {
|
|
6
|
+
return new Promise<void>(resolve => {
|
|
7
7
|
fs.readdir(__dirname, (err, files) => {
|
|
8
8
|
let passes = true;
|
|
9
9
|
files.forEach(file => {
|
|
10
|
-
if (
|
|
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
|
+
) {
|
|
11
18
|
return;
|
|
12
19
|
}
|
|
13
|
-
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
const funcOrObj = (src as any)[file.replace(/\.(ts|js)$/, "")];
|
|
14
22
|
if (!funcOrObj) {
|
|
15
23
|
console.info(
|
|
16
24
|
`Uh oh, it looks like you forgot to export (or explicitly ignore) this file:`,
|
|
@@ -50,3 +50,4 @@ 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";
|
|
@@ -0,0 +1,25 @@
|
|
|
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,10 +1,12 @@
|
|
|
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
|
+
|
|
4
6
|
export default function isPositionCloserToRangeStartThanRangeEnd(
|
|
5
|
-
position,
|
|
6
|
-
range,
|
|
7
|
-
maxLength
|
|
7
|
+
position: number,
|
|
8
|
+
range: Range,
|
|
9
|
+
maxLength: number
|
|
8
10
|
) {
|
|
9
11
|
const distanceFromStart = getShortestDistanceBetweenTwoPositions(
|
|
10
12
|
range.start,
|
|
@@ -1,4 +1,13 @@
|
|
|
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
|
+
|
|
2
11
|
/**
|
|
3
12
|
*
|
|
4
13
|
* @param {*} position //assumed to be a 0 based "caretPosition"
|
|
@@ -7,11 +16,11 @@ import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIs
|
|
|
7
16
|
* @param {*} includeEdges - (default false) whether or not to say
|
|
8
17
|
*/
|
|
9
18
|
function isPositionWithinRange(
|
|
10
|
-
position,
|
|
11
|
-
range,
|
|
12
|
-
sequenceLength,
|
|
13
|
-
includeStartEdge,
|
|
14
|
-
includeEndEdge
|
|
19
|
+
position: number,
|
|
20
|
+
range: Range,
|
|
21
|
+
sequenceLength: number,
|
|
22
|
+
includeStartEdge?: boolean,
|
|
23
|
+
includeEndEdge?: boolean
|
|
15
24
|
) {
|
|
16
25
|
const ranges = splitRangeIntoTwoPartsIfItIsCircular(range, sequenceLength);
|
|
17
26
|
const positionFits = ranges.some(function (range) {
|
|
@@ -2,12 +2,14 @@ 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
|
+
|
|
5
7
|
export default function isRangeOrPositionWithinRange(
|
|
6
|
-
rangeOrPositionToCheck,
|
|
7
|
-
containingRange,
|
|
8
|
-
maxLength,
|
|
9
|
-
includeStartEdge,
|
|
10
|
-
includeEndEdge
|
|
8
|
+
rangeOrPositionToCheck: Range | number,
|
|
9
|
+
containingRange: Range,
|
|
10
|
+
maxLength: number,
|
|
11
|
+
includeStartEdge?: boolean,
|
|
12
|
+
includeEndEdge?: boolean
|
|
11
13
|
) {
|
|
12
14
|
if (
|
|
13
15
|
rangeOrPositionToCheck === undefined ||
|
|
@@ -18,8 +20,11 @@ export default function isRangeOrPositionWithinRange(
|
|
|
18
20
|
return false;
|
|
19
21
|
}
|
|
20
22
|
if (isObject(rangeOrPositionToCheck)) {
|
|
23
|
+
if (typeof (rangeOrPositionToCheck as Range).start !== "number") {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
21
26
|
return isRangeWithinRange(
|
|
22
|
-
rangeOrPositionToCheck,
|
|
27
|
+
rangeOrPositionToCheck as Range,
|
|
23
28
|
containingRange,
|
|
24
29
|
maxLength
|
|
25
30
|
);
|
|
@@ -1,10 +1,12 @@
|
|
|
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
|
+
|
|
4
6
|
export default function isRangeWithinRange(
|
|
5
|
-
rangeToCheck,
|
|
6
|
-
containingRange,
|
|
7
|
-
maxLength
|
|
7
|
+
rangeToCheck: Range,
|
|
8
|
+
containingRange: Range,
|
|
9
|
+
maxLength: number
|
|
8
10
|
) {
|
|
9
11
|
const ranges = trimRangeByAnotherRange(
|
|
10
12
|
rangeToCheck,
|
|
@@ -0,0 +1,11 @@
|
|
|
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,5 +1,10 @@
|
|
|
1
|
+
import { Range } from "./types";
|
|
2
|
+
|
|
1
3
|
//this function takes a position that might not fit in a given range and puts it into that range
|
|
2
|
-
export default function modulatePositionByRange(
|
|
4
|
+
export default function modulatePositionByRange(
|
|
5
|
+
position: number,
|
|
6
|
+
range: Range
|
|
7
|
+
) {
|
|
3
8
|
let returnVal = position;
|
|
4
9
|
if (position < range.start) {
|
|
5
10
|
returnVal = range.end - (range.start - (position + 1));
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { Range } from "./types";
|
|
2
|
+
|
|
1
3
|
import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
|
2
4
|
import provideInclusiveOptions from "./provideInclusiveOptions";
|
|
3
5
|
import { assign } from "lodash-es";
|
|
4
6
|
export default provideInclusiveOptions(modulateRangeBySequenceLength);
|
|
5
7
|
|
|
6
|
-
function modulateRangeBySequenceLength(range, seqLen) {
|
|
8
|
+
function modulateRangeBySequenceLength(range: Range, seqLen: number) {
|
|
7
9
|
return assign(range, {
|
|
8
10
|
start: normalizePositionByRangeLength(range.start, seqLen),
|
|
9
11
|
end: normalizePositionByRangeLength(range.end, seqLen)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
//
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
export default function normalizePositionByRangeLength(
|
|
4
|
-
pPosition,
|
|
5
|
-
sequenceLength,
|
|
6
|
-
isInBetweenPositions
|
|
4
|
+
pPosition: number,
|
|
5
|
+
sequenceLength: number,
|
|
6
|
+
isInBetweenPositions = false
|
|
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
|
+
|
|
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.js → normalizePositionByRangeLength1Based.ts}
RENAMED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
//
|
|
1
2
|
import modulatePositionByRange from "./modulatePositionByRange";
|
|
2
3
|
|
|
3
4
|
export default function normalizePositionByRangeLength1Based(
|
|
4
|
-
position,
|
|
5
|
-
sequenceLength
|
|
5
|
+
position: number,
|
|
6
|
+
sequenceLength: number
|
|
6
7
|
) {
|
|
7
8
|
return modulatePositionByRange(position, { start: 1, end: sequenceLength });
|
|
8
9
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import { assign } from "lodash-es";
|
|
3
3
|
|
|
4
4
|
import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
|
5
|
+
import { Range } from "./types";
|
|
5
6
|
|
|
6
|
-
export default function normalizeRange(range, sequenceLength) {
|
|
7
|
+
export default function normalizeRange(range: Range, sequenceLength: number) {
|
|
7
8
|
return assign({}, range, {
|
|
8
9
|
start: normalizePositionByRangeLength(range.start, sequenceLength),
|
|
9
10
|
end: normalizePositionByRangeLength(range.end, sequenceLength)
|
|
@@ -0,0 +1,79 @@
|
|
|
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,14 +1,14 @@
|
|
|
1
1
|
//
|
|
2
2
|
export default function reversePositionInRange(
|
|
3
|
-
position,
|
|
4
|
-
rangeLength,
|
|
5
|
-
isInBetweenPositions
|
|
3
|
+
position: number,
|
|
4
|
+
rangeLength: number,
|
|
5
|
+
isInBetweenPositions: boolean
|
|
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
|
+
|
|
12
12
|
// ac.posInt,
|
|
13
13
|
// ac.posInt,
|
|
14
14
|
// ac.bool
|
package/src/{splitRangeIntoTwoPartsIfItIsCircular.js → splitRangeIntoTwoPartsIfItIsCircular.ts}
RENAMED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { Range } from "./types";
|
|
2
|
+
|
|
1
3
|
//
|
|
2
|
-
|
|
4
|
+
|
|
3
5
|
//takes a potentially circular range and returns an array containing the range split on the origin
|
|
4
6
|
export default function splitRangeIntoTwoPartsIfItIsCircular(
|
|
5
|
-
range,
|
|
6
|
-
sequenceLength
|
|
7
|
+
range: Range,
|
|
8
|
+
sequenceLength: number
|
|
7
9
|
) {
|
|
8
|
-
// ac.throw([ac.range, ac.number], arguments);
|
|
9
10
|
if (sequenceLength !== 0) {
|
|
10
11
|
sequenceLength = sequenceLength || Infinity;
|
|
11
12
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { Range } from "./types";
|
|
2
|
+
|
|
1
3
|
import { assign } from "lodash-es";
|
|
2
4
|
import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
|
3
5
|
|
|
4
6
|
export default function translateRange(
|
|
5
|
-
rangeToBeAdjusted,
|
|
6
|
-
translateBy,
|
|
7
|
-
rangeLength
|
|
7
|
+
rangeToBeAdjusted: Range,
|
|
8
|
+
translateBy: number,
|
|
9
|
+
rangeLength: number
|
|
8
10
|
) {
|
|
9
11
|
return assign({}, rangeToBeAdjusted, {
|
|
10
12
|
start: normalizePositionByRangeLength(
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { Range } from "./types";
|
|
3
|
+
|
|
1
4
|
//
|
|
2
5
|
export default function trimNonCicularRangeByAnotherNonCircularRange(
|
|
3
|
-
rangeToBeTrimmed,
|
|
4
|
-
trimmingRange
|
|
5
|
-
) {
|
|
6
|
-
// ac.throw([ac.range, ac.range], arguments);
|
|
6
|
+
rangeToBeTrimmed: Range,
|
|
7
|
+
trimmingRange: Range
|
|
8
|
+
): Range | undefined {
|
|
7
9
|
let outputTrimmedRange;
|
|
8
10
|
if (!rangeToBeTrimmed) {
|
|
9
11
|
return outputTrimmedRange;
|
package/src/{trimNumberToFitWithin0ToAnotherNumber.js → trimNumberToFitWithin0ToAnotherNumber.ts}
RENAMED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
//
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
export default function trimNumberToFitWithin0ToAnotherNumber(
|
|
4
|
-
numberToBeTrimmed,
|
|
5
|
-
max
|
|
4
|
+
numberToBeTrimmed: number,
|
|
5
|
+
max: number
|
|
6
6
|
) {
|
|
7
|
-
// ac.throw([ac.number, ac.number], arguments);
|
|
8
7
|
if (numberToBeTrimmed < 0) {
|
|
9
8
|
numberToBeTrimmed = 0;
|
|
10
9
|
}
|
|
@@ -2,6 +2,7 @@ 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";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* trims range, but does *not* adjust it
|
|
@@ -18,10 +19,10 @@ import { extend } from "lodash-es";
|
|
|
18
19
|
* }
|
|
19
20
|
*/
|
|
20
21
|
export default function trimRangeByAnotherRange(
|
|
21
|
-
rangeToBeTrimmed,
|
|
22
|
-
trimmingRange,
|
|
23
|
-
sequenceLength
|
|
24
|
-
) {
|
|
22
|
+
rangeToBeTrimmed: Range,
|
|
23
|
+
trimmingRange: Range,
|
|
24
|
+
sequenceLength: number
|
|
25
|
+
): Range | undefined | null {
|
|
25
26
|
if (!rangeToBeTrimmed || !trimmingRange) {
|
|
26
27
|
console.warn("invalid range input");
|
|
27
28
|
return null; //a null return val means something went wrong with this function
|
|
@@ -50,10 +51,8 @@ export default function trimRangeByAnotherRange(
|
|
|
50
51
|
return rangeToBeTrimmed;
|
|
51
52
|
}
|
|
52
53
|
//and trim both pieces by the already calculated overlaps
|
|
53
|
-
const splitRangesToBeTrimmed =
|
|
54
|
-
rangeToBeTrimmed,
|
|
55
|
-
sequenceLength
|
|
56
|
-
);
|
|
54
|
+
const splitRangesToBeTrimmed: (Range | undefined | null)[] =
|
|
55
|
+
splitRangeIntoTwoPartsIfItIsCircular(rangeToBeTrimmed, sequenceLength);
|
|
57
56
|
splitRangesToBeTrimmed.forEach(function (nonCircularRangeToBeTrimmed, index) {
|
|
58
57
|
overlaps.forEach(function (overlap) {
|
|
59
58
|
if (nonCircularRangeToBeTrimmed) {
|
|
@@ -68,7 +67,7 @@ export default function trimRangeByAnotherRange(
|
|
|
68
67
|
});
|
|
69
68
|
//filter out any of the split ranges that have been fully deleted!
|
|
70
69
|
const outputSplitRanges = splitRangesToBeTrimmed.filter(
|
|
71
|
-
function (trimmedRange) {
|
|
70
|
+
function (trimmedRange): trimmedRange is Range {
|
|
72
71
|
if (trimmedRange) {
|
|
73
72
|
return true;
|
|
74
73
|
}
|
|
@@ -100,4 +99,5 @@ export default function trimRangeByAnotherRange(
|
|
|
100
99
|
end: outputTrimmedRange.end
|
|
101
100
|
});
|
|
102
101
|
}
|
|
102
|
+
return undefined;
|
|
103
103
|
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Range {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
type?: string;
|
|
5
|
+
locations?: Range[];
|
|
6
|
+
overlapsSelf?: boolean;
|
|
7
|
+
yOffset?: number;
|
|
8
|
+
aminoAcids?: unknown[];
|
|
9
|
+
forward?: boolean;
|
|
10
|
+
notes?: Record<string, unknown> | string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
//
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import trimRangeByAnotherRange from "./trimRangeByAnotherRange";
|
|
4
4
|
|
|
5
|
+
import { Range } from "./types";
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* "zeroes" a subrange of a container range by
|
|
7
9
|
* adjusting subRange start and end such that it is as if the container range start = 0.
|
|
@@ -17,11 +19,10 @@ import trimRangeByAnotherRange from "./trimRangeByAnotherRange";
|
|
|
17
19
|
* }
|
|
18
20
|
*/
|
|
19
21
|
export default function zeroSubrangeByContainerRange(
|
|
20
|
-
subRange,
|
|
21
|
-
containerRange,
|
|
22
|
-
sequenceLength
|
|
22
|
+
subRange: Range,
|
|
23
|
+
containerRange: Range,
|
|
24
|
+
sequenceLength: number
|
|
23
25
|
) {
|
|
24
|
-
// ac.throw([ac.range, ac.range, ac.posInt], arguments);
|
|
25
26
|
//first check to make sure the container range fully contains the subRange
|
|
26
27
|
const trimmedSubRange = trimRangeByAnotherRange(
|
|
27
28
|
subRange,
|
|
@@ -33,9 +34,10 @@ export default function zeroSubrangeByContainerRange(
|
|
|
33
34
|
"subRange must be fully contained by containerRange! Otherwise this function does not make sense"
|
|
34
35
|
);
|
|
35
36
|
}
|
|
36
|
-
const newSubrange = {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const newSubrange: Range = {
|
|
38
|
+
start: subRange.start - containerRange.start,
|
|
39
|
+
end: subRange.end - containerRange.start
|
|
40
|
+
};
|
|
39
41
|
if (newSubrange.start < 0) {
|
|
40
42
|
newSubrange.start += sequenceLength;
|
|
41
43
|
}
|
package/translateRange.d.ts
CHANGED
|
@@ -1 +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 +1 @@
|
|
|
1
|
-
export default function trimAnnStartEndToFitSeqLength(annStartOrEnd:
|
|
1
|
+
export default function trimAnnStartEndToFitSeqLength(annStartOrEnd: number, sequenceLength: number): number;
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
end: any;
|
|
4
|
-
} | undefined;
|
|
1
|
+
import { Range } from './types';
|
|
2
|
+
export default function trimNonCicularRangeByAnotherNonCircularRange(rangeToBeTrimmed: Range, trimmingRange: Range): Range | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function trimNumberToFitWithin0ToAnotherNumber(numberToBeTrimmed:
|
|
1
|
+
export default function trimNumberToFitWithin0ToAnotherNumber(numberToBeTrimmed: number, max: number): number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Range } from './types';
|
|
1
2
|
/**
|
|
2
3
|
* trims range, but does *not* adjust it
|
|
3
4
|
* returns a new range if there is one, or null, if it is trimmed completely
|
|
@@ -12,4 +13,4 @@
|
|
|
12
13
|
* end:
|
|
13
14
|
* }
|
|
14
15
|
*/
|
|
15
|
-
export default function trimRangeByAnotherRange(rangeToBeTrimmed:
|
|
16
|
+
export default function trimRangeByAnotherRange(rangeToBeTrimmed: Range, trimmingRange: Range, sequenceLength: number): Range | undefined | null;
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Range {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
type?: string;
|
|
5
|
+
locations?: Range[];
|
|
6
|
+
overlapsSelf?: boolean;
|
|
7
|
+
yOffset?: number;
|
|
8
|
+
aminoAcids?: unknown[];
|
|
9
|
+
forward?: boolean;
|
|
10
|
+
notes?: Record<string, unknown> | string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Range } from './types';
|
|
1
2
|
/**
|
|
2
3
|
* "zeroes" a subrange of a container range by
|
|
3
4
|
* adjusting subRange start and end such that it is as if the container range start = 0.
|
|
@@ -12,4 +13,4 @@
|
|
|
12
13
|
* end:
|
|
13
14
|
* }
|
|
14
15
|
*/
|
|
15
|
-
export default function zeroSubrangeByContainerRange(subRange:
|
|
16
|
+
export default function zeroSubrangeByContainerRange(subRange: Range, containerRange: Range, sequenceLength: number): Range;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|