@gmod/bbi
Version:
Parser for BigWig/BigBed files
56 lines • 1.54 kB
JavaScript
;
/**
* Adapted from a combination of Range and _Compound in the
* Dalliance Genome Explorer, (c) Thomas Down 2006-2010.
*/
Object.defineProperty(exports, "__esModule", { value: true });
class Range {
ranges;
constructor(arg1) {
this.ranges = arg1;
}
get min() {
return this.ranges[0].min;
}
get max() {
return this.ranges.at(-1).max;
}
contains(pos) {
for (const r of this.ranges) {
if (r.min <= pos && r.max >= pos) {
return true;
}
}
return false;
}
isContiguous() {
return this.ranges.length > 1;
}
getRanges() {
return this.ranges.map(r => new Range([r]));
}
toString() {
return this.ranges.map(r => `[${r.min}-${r.max}]`).join(',');
}
union(s1) {
const allRanges = [...this.ranges, ...s1.ranges].sort((a, b) => {
return a.min !== b.min ? a.min - b.min : a.max - b.max;
});
const merged = [];
let current = allRanges[0];
for (let i = 1; i < allRanges.length; i++) {
const nxt = allRanges[i];
if (nxt.min > current.max + 1) {
merged.push(current);
current = nxt;
}
else if (nxt.max > current.max) {
current = { min: current.min, max: nxt.max };
}
}
merged.push(current);
return new Range(merged);
}
}
exports.default = Range;
//# sourceMappingURL=range.js.map