@teselagen/range-utils 0.3.7 → 0.3.9
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 +94 -0
- package/flipContainedRange.d.ts +1 -1
- package/index.cjs +2619 -0
- package/index.d.ts +52 -51
- package/index.js +1791 -6100
- package/index.umd.cjs +2623 -0
- package/package.json +2 -3
- package/src/adjustRangeToDeletionOfAnotherRange.test.js +166 -105
- package/src/adjustRangeToInsert.js +29 -26
- package/src/adjustRangeToInsert.test.js +197 -109
- package/src/adjustRangeToRotation.js +4 -5
- package/src/adjustRangeToRotation.test.js +203 -119
- package/src/checkIfNonCircularRangesOverlap.js +18 -15
- package/src/checkIfNonCircularRangesOverlap.test.js +67 -42
- package/src/checkIfPotentiallyCircularRangesOverlap.js +22 -12
- package/src/checkIfPotentiallyCircularRangesOverlap.test.js +115 -70
- package/src/collapseOverlapsGeneratedFromRangeComparisonIfPossible.js +72 -41
- package/src/collapseOverlapsGeneratedFromRangeComparisonIfPossible.test.js +183 -84
- package/src/convertRangeIndices.js +24 -20
- package/src/convertRangeIndices.test.js +40 -21
- package/src/convertRangeTo0Based.js +7 -4
- package/src/convertRangeTo1Based.js +8 -4
- package/src/doesRangeSpanEntireSequence.js +4 -4
- package/src/doesRangeSpanOrigin.js +3 -3
- package/src/expandOrContractCircularRangeToPosition.js +45 -38
- package/src/expandOrContractNonCircularRangeToPosition.js +24 -21
- package/src/expandOrContractRangeByLength.js +16 -11
- package/src/expandOrContractRangeByLength.test.js +109 -71
- package/src/expandOrContractRangeToPosition.js +17 -9
- package/src/flipContainedRange.js +133 -72
- package/src/flipContainedRange.test.js +143 -117
- package/src/generateRandomRange.js +17 -15
- package/src/generateRandomRange.test.js +21 -21
- package/src/getAnnotationRangeType.js +25 -21
- package/src/getAnnotationRangeType.test.js +56 -57
- package/src/getEachPositionInRangeAsArray.js +13 -13
- package/src/getEachPositionInRangeAsArray.test.js +12 -8
- package/src/getLengthOfOverlappingRegionsBetweenTwoRanges.js +16 -8
- package/src/getLengthOfOverlappingRegionsBetweenTwoRanges.test.js +32 -24
- package/src/getMiddleOfRange.js +1 -1
- package/src/getMiddleOfRange.test.js +5 -13
- package/src/getOverlapOfNonCircularRanges.js +30 -30
- package/src/getOverlapsOfPotentiallyCircularRanges.js +5 -5
- package/src/getOverlapsOfPotentiallyCircularRanges.test.js +3 -23
- package/src/getPositionFromAngle.js +12 -7
- package/src/getRangeAngles.js +1 -1
- package/src/getRangeAngles.test.js +10 -11
- package/src/getRangeLength.test.js +5 -5
- package/src/getRangesBetweenTwoRanges.js +31 -22
- package/src/getSequenceWithinRange.js +13 -13
- package/src/getSequenceWithinRange.test.js +43 -45
- package/src/getShortestDistanceBetweenTwoPositions.js +10 -6
- package/src/getShortestDistanceBetweenTwoPositions.test.js +11 -13
- package/src/getYOffsetForPotentiallyCircularRange.js +33 -21
- package/src/getYOffsetsForPotentiallyCircularRanges.js +26 -19
- package/src/getYOffsetsForPotentiallyCircularRanges.test.js +42 -29
- package/src/getZeroedRangeOverlaps.js +30 -15
- package/src/getZeroedRangeOverlaps.test.js +75 -36
- package/src/index.js +52 -51
- package/src/index.test.js +6 -8
- package/src/invertRange.test.js +103 -93
- package/src/isPositionCloserToRangeStartThanRangeEnd.js +18 -6
- package/src/isPositionCloserToRangeStartThanRangeEnd.test.js +36 -16
- package/src/isPositionWithinRange.js +4 -4
- package/src/isRangeOrPositionWithinRange.js +18 -12
- package/src/isRangeOrPositionWithinRange.test.js +6 -6
- package/src/isRangeWithinRange.js +2 -3
- package/src/loopEachPositionInRange.js +3 -3
- package/src/modulatePositionByRange.js +8 -8
- package/src/modulatePositionByRange.test.js +10 -11
- package/src/modulateRangeBySequenceLength.js +7 -7
- package/src/modulateRangeBySequenceLength.test.js +39 -16
- package/src/normalizePositionByRangeLength.js +22 -18
- package/src/normalizePositionByRangeLength.test.js +23 -23
- package/src/normalizePositionByRangeLength1Based.js +7 -4
- package/src/normalizePositionByRangeLength1Based.test.js +9 -9
- package/src/normalizeRange.js +7 -7
- package/src/normalizeRange.test.js +9 -9
- package/src/provideInclusiveOptions.js +36 -23
- package/src/reversePositionInRange.js +16 -12
- package/src/splitRangeIntoTwoPartsIfItIsCircular.js +31 -28
- package/src/splitRangeIntoTwoPartsIfItIsCircular.test.js +22 -11
- package/src/translateRange.js +18 -8
- package/src/translateRange.test.js +18 -19
- package/src/trimAnnStartEndToFitSeqLength.js +9 -0
- package/src/trimAnnStartEndToFitSeqLength.test.js +35 -0
- package/src/trimNonCicularRangeByAnotherNonCircularRange.js +45 -42
- package/src/trimNumberToFitWithin0ToAnotherNumber.js +13 -10
- package/src/trimRangeByAnotherRange.js +20 -19
- package/src/trimRangeByAnotherRange.test.js +6 -6
- package/src/zeroSubrangeByContainerRange.js +29 -19
- package/src/zeroSubrangeByContainerRange.test.js +57 -47
- package/trimAnnStartEndToFitSeqLength.d.ts +1 -0
- package/trimAnnStartEndToFitSeqLength.test.d.ts +1 -0
- package/index.mjs +0 -6928
- package/index.umd.js +0 -6932
|
@@ -1,123 +1,207 @@
|
|
|
1
|
-
import adjustRangeToRotation from
|
|
1
|
+
import adjustRangeToRotation from "./adjustRangeToRotation.js";
|
|
2
2
|
|
|
3
|
-
import assert from
|
|
3
|
+
import assert from "assert";
|
|
4
4
|
|
|
5
|
+
describe("adjustRangeToRotation", function () {
|
|
6
|
+
it("defaults to a rotateBy=0 if a null or undefined is passed ", () => {
|
|
7
|
+
assert.deepEqual(
|
|
8
|
+
adjustRangeToRotation(
|
|
9
|
+
{
|
|
10
|
+
start: 1,
|
|
11
|
+
end: 2
|
|
12
|
+
},
|
|
13
|
+
null,
|
|
14
|
+
10
|
|
15
|
+
),
|
|
16
|
+
{
|
|
17
|
+
start: 1,
|
|
18
|
+
end: 2
|
|
19
|
+
}
|
|
20
|
+
);
|
|
5
21
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
22
|
+
assert.deepEqual(
|
|
23
|
+
adjustRangeToRotation(
|
|
24
|
+
{
|
|
25
|
+
start: 1,
|
|
26
|
+
end: 2
|
|
27
|
+
},
|
|
28
|
+
undefined,
|
|
29
|
+
10
|
|
30
|
+
),
|
|
31
|
+
{
|
|
32
|
+
start: 1,
|
|
33
|
+
end: 2
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
assert.deepEqual(
|
|
37
|
+
adjustRangeToRotation(
|
|
38
|
+
{
|
|
39
|
+
start: 1,
|
|
40
|
+
end: 2
|
|
41
|
+
},
|
|
42
|
+
NaN,
|
|
43
|
+
10
|
|
44
|
+
),
|
|
45
|
+
{
|
|
46
|
+
start: 1,
|
|
47
|
+
end: 2
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
it("defaults to an infinite length if no length is passed", () => {
|
|
52
|
+
assert.deepEqual(
|
|
53
|
+
adjustRangeToRotation(
|
|
54
|
+
{
|
|
55
|
+
start: 1,
|
|
56
|
+
end: 2
|
|
57
|
+
},
|
|
58
|
+
1,
|
|
59
|
+
null
|
|
60
|
+
),
|
|
61
|
+
{
|
|
62
|
+
start: 0,
|
|
63
|
+
end: 1
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
assert.deepEqual(
|
|
67
|
+
adjustRangeToRotation(
|
|
68
|
+
{
|
|
69
|
+
start: 1,
|
|
70
|
+
end: 2
|
|
71
|
+
},
|
|
72
|
+
1,
|
|
73
|
+
undefined
|
|
74
|
+
),
|
|
75
|
+
{
|
|
76
|
+
start: 0,
|
|
77
|
+
end: 1
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
it("shifts start and end if rotating before non circular range", function () {
|
|
82
|
+
//0123456789
|
|
83
|
+
//atgcatgccc
|
|
84
|
+
// rr
|
|
85
|
+
//
|
|
86
|
+
assert.deepEqual(
|
|
87
|
+
adjustRangeToRotation(
|
|
88
|
+
{
|
|
89
|
+
start: 1,
|
|
90
|
+
end: 2
|
|
91
|
+
},
|
|
92
|
+
1,
|
|
93
|
+
10
|
|
94
|
+
),
|
|
95
|
+
{
|
|
96
|
+
start: 0,
|
|
97
|
+
end: 1
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
assert.deepEqual(
|
|
101
|
+
adjustRangeToRotation(
|
|
102
|
+
{
|
|
103
|
+
start: 1,
|
|
104
|
+
end: 2
|
|
105
|
+
},
|
|
106
|
+
undefined,
|
|
107
|
+
10
|
|
108
|
+
),
|
|
109
|
+
{
|
|
110
|
+
start: 1,
|
|
111
|
+
end: 2
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
assert.deepEqual(
|
|
115
|
+
adjustRangeToRotation(
|
|
116
|
+
{
|
|
117
|
+
start: 1,
|
|
118
|
+
end: 2
|
|
119
|
+
},
|
|
120
|
+
2,
|
|
121
|
+
10
|
|
122
|
+
),
|
|
123
|
+
{
|
|
124
|
+
start: 9,
|
|
125
|
+
end: 0
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
assert.deepEqual(
|
|
129
|
+
adjustRangeToRotation(
|
|
130
|
+
{
|
|
131
|
+
start: 1,
|
|
132
|
+
end: 2
|
|
133
|
+
},
|
|
134
|
+
3,
|
|
135
|
+
10
|
|
136
|
+
),
|
|
137
|
+
{
|
|
138
|
+
start: 8,
|
|
139
|
+
end: 9
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
//0123456789
|
|
143
|
+
//atgcatgccc
|
|
144
|
+
//rrrrr rrr
|
|
145
|
+
//
|
|
146
|
+
assert.deepEqual(
|
|
147
|
+
adjustRangeToRotation(
|
|
148
|
+
{
|
|
149
|
+
start: 7,
|
|
150
|
+
end: 4
|
|
151
|
+
},
|
|
152
|
+
3,
|
|
153
|
+
10
|
|
154
|
+
),
|
|
155
|
+
{
|
|
156
|
+
start: 4,
|
|
157
|
+
end: 1
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
assert.deepEqual(
|
|
161
|
+
adjustRangeToRotation(
|
|
162
|
+
{
|
|
163
|
+
start: 7,
|
|
164
|
+
end: 4
|
|
165
|
+
},
|
|
166
|
+
5,
|
|
167
|
+
10
|
|
168
|
+
),
|
|
169
|
+
{
|
|
170
|
+
start: 2,
|
|
171
|
+
end: 9
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
assert.deepEqual(
|
|
175
|
+
adjustRangeToRotation(
|
|
176
|
+
{
|
|
177
|
+
start: 7,
|
|
178
|
+
end: 4
|
|
179
|
+
},
|
|
180
|
+
6,
|
|
181
|
+
10
|
|
182
|
+
),
|
|
183
|
+
{
|
|
184
|
+
start: 1,
|
|
185
|
+
end: 8
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
//0123456 789
|
|
189
|
+
//atgcatg ccc
|
|
190
|
+
//rrrrrrr rrr
|
|
191
|
+
//
|
|
192
|
+
assert.deepEqual(
|
|
193
|
+
adjustRangeToRotation(
|
|
194
|
+
{
|
|
195
|
+
start: 7,
|
|
196
|
+
end: 6
|
|
197
|
+
},
|
|
198
|
+
3,
|
|
199
|
+
10
|
|
200
|
+
),
|
|
201
|
+
{
|
|
202
|
+
start: 4,
|
|
203
|
+
end: 3
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
});
|
|
123
207
|
});
|
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
//
|
|
2
2
|
// ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
|
|
3
|
-
export default function checkIfNonCircularRangesOverlap(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export default function checkIfNonCircularRangesOverlap(
|
|
4
|
+
range,
|
|
5
|
+
comparisonRange
|
|
6
|
+
) {
|
|
7
|
+
// ac.throw([ac.range, ac.range], arguments);
|
|
8
|
+
if (range.start < comparisonRange.start) {
|
|
9
|
+
if (range.end < comparisonRange.start) {
|
|
7
10
|
//----llll
|
|
8
11
|
//--------cccc
|
|
9
12
|
//no overlap
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
return false;
|
|
14
|
+
} else {
|
|
12
15
|
//----llll
|
|
13
16
|
//-------cccc
|
|
14
17
|
//overlap
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
if (range.start > comparisonRange.end) {
|
|
19
22
|
//------llll
|
|
20
23
|
// -cccc
|
|
21
24
|
//no overlap
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
return false;
|
|
26
|
+
} else {
|
|
24
27
|
//-----llll
|
|
25
28
|
// -cccc
|
|
26
29
|
//overlap
|
|
27
|
-
|
|
28
|
-
}
|
|
30
|
+
return true;
|
|
29
31
|
}
|
|
30
|
-
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,45 +1,70 @@
|
|
|
1
|
-
import {expect} from
|
|
1
|
+
import { expect } from "chai";
|
|
2
2
|
|
|
3
|
-
import checkIfNonCircularRangesOverlap from
|
|
3
|
+
import checkIfNonCircularRangesOverlap from "./checkIfNonCircularRangesOverlap.js";
|
|
4
4
|
// checkIfNonCircularRangesOverlap(frame, sequence, minimumOrfSize, forward, circular)
|
|
5
|
-
describe(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
5
|
+
describe("checkIfNonCircularRangesOverlap", function () {
|
|
6
|
+
it("returns true if non circular ranges do overlap", function () {
|
|
7
|
+
expect(
|
|
8
|
+
checkIfNonCircularRangesOverlap(
|
|
9
|
+
{
|
|
10
|
+
start: 5,
|
|
11
|
+
end: 100
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
start: 50,
|
|
15
|
+
end: 50
|
|
16
|
+
}
|
|
17
|
+
)
|
|
18
|
+
).to.equal(true);
|
|
19
|
+
expect(
|
|
20
|
+
checkIfNonCircularRangesOverlap(
|
|
21
|
+
{
|
|
22
|
+
start: 5,
|
|
23
|
+
end: 100
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
start: 50,
|
|
27
|
+
end: 500
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
).to.equal(true);
|
|
31
|
+
expect(
|
|
32
|
+
checkIfNonCircularRangesOverlap(
|
|
33
|
+
{
|
|
34
|
+
start: 5,
|
|
35
|
+
end: 100
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
start: 0,
|
|
39
|
+
end: 5
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
).to.equal(true);
|
|
43
|
+
});
|
|
44
|
+
it("returns false if non circular ranges do not overlap", function () {
|
|
45
|
+
expect(
|
|
46
|
+
checkIfNonCircularRangesOverlap(
|
|
47
|
+
{
|
|
48
|
+
start: 5,
|
|
49
|
+
end: 100
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
start: 1,
|
|
53
|
+
end: 4
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
).to.equal(false);
|
|
57
|
+
expect(
|
|
58
|
+
checkIfNonCircularRangesOverlap(
|
|
59
|
+
{
|
|
60
|
+
start: 5,
|
|
61
|
+
end: 100
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
start: 101,
|
|
65
|
+
end: 101
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
).to.equal(false);
|
|
69
|
+
});
|
|
45
70
|
});
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
//
|
|
2
|
-
import checkIfNonCircularRangesOverlap from
|
|
2
|
+
import checkIfNonCircularRangesOverlap from "./checkIfNonCircularRangesOverlap";
|
|
3
3
|
|
|
4
|
-
import splitRangeIntoTwoPartsIfItIsCircular from
|
|
4
|
+
import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIsCircular";
|
|
5
5
|
// ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
|
|
6
6
|
|
|
7
|
-
export default function checkIfPotentiallyCircularRangesOverlap(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
export default function checkIfPotentiallyCircularRangesOverlap(
|
|
8
|
+
range,
|
|
9
|
+
comparisonRange
|
|
10
|
+
) {
|
|
11
|
+
// ac.throw([ac.range, ac.range], arguments);
|
|
12
|
+
//split the potentially circular ranges and compare each part for overlap
|
|
13
|
+
return splitRangeIntoTwoPartsIfItIsCircular(range, Infinity).some(
|
|
14
|
+
function (splitRange) {
|
|
15
|
+
return splitRangeIntoTwoPartsIfItIsCircular(
|
|
16
|
+
comparisonRange,
|
|
17
|
+
Infinity
|
|
18
|
+
).some(function (splitComparisonRange) {
|
|
19
|
+
return checkIfNonCircularRangesOverlap(
|
|
20
|
+
splitRange,
|
|
21
|
+
splitComparisonRange
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|