RegionSet & models (Wasm)
The @databio/gtars Wasm bindings expose gtars' core interval-analysis types directly to JavaScript and TypeScript, with no server round-trip. This page covers everything in the regionset Wasm module — RegionSet, RegionSetList, ConsensusBuilder, and the result types for statistics and BED classification.
See the Rust reference pages for the underlying semantics:
- gtars-core —
Region,RegionSet,RegionSetList - gtars-genomicdist — the stats, interval algebra, and consensus/classifier methods that
RegionSetgains in Wasm
Import
Section titled “Import”import init, { RegionSet, RegionSetList, ConsensusBuilder,} from '@databio/gtars';
await init(); // initializes the wasm module; top-level await in ESM environmentsRegionSet
Section titled “RegionSet”A sorted collection of genomic regions constructed from an array of [chr, start, end, rest] tuples. Construction sorts by (chr, start).
Construction
Section titled “Construction”// BED-like entries: [chr, start, end, rest]// `rest` is any trailing BED metadata — pass "" if you have BED3 dataconst entries: [string, number, number, string][] = [ ['chr1', 100, 200, 'peak1'], ['chr1', 300, 400, 'peak2'], ['chr2', 500, 600, 'peak3'],];
const rs = new RegionSet(entries);Properties
Section titled “Properties”rs.numberOfRegions // numberrs.meanRegionWidth // numberrs.nucleotidesLength // number (total bp)rs.identifier // string — canonical MD5 id over first 3 columnsrs.firstRegion // string — debug repr of the first regionrs.classify // BedClassificationOutput (see below)Statistics
Section titled “Statistics”// Per-chromosome summary stats — returns { [chr]: ChromosomeStatistics }const stats = rs.chromosomeStatistics();
// Region widths (end - start)const widths: number[] = rs.calcWidths();
// Gaps between consecutive regions (positive gaps only; overlapping pairs are dropped)const gaps: number[] = rs.calcNeighborDistances();
// Per-region min-neighbor distanceconst nn: number[] = rs.calcNearestNeighbors();
// Single-linkage clusters at a stitching radius; returns a cluster id per regionconst clusterIds: number[] = rs.cluster(5_000);Region distribution
Section titled “Region distribution”// Bin counts for plotting; chrom_sizes is optionalconst chromSizes = { chr1: 248956422, chr2: 242193529 };
// With chrom_sizes → reference-aligned bins (comparable across files)const dist = rs.regionDistribution(250, chromSizes);
// Without chrom_sizes → bins derived from observed max end (NOT comparable)const distLocal = rs.regionDistribution(250, null);// Array of { chr, start, end, n, rid }Interval set algebra
Section titled “Interval set algebra”All operations return a new RegionSet. Metadata (rest fields) is dropped by operations that merge or synthesize new intervals.
const chromSizes = { chr1: 248956422 };
const trimmed = rs.trim(chromSizes);const merged = rs.reduce();const disjoint = rs.disjoin();const proms = rs.promoters(2000, 0);const shifted = rs.shift(100);const resized = rs.resize(500, 'center');const flanked = rs.flank(1000, true, false);const narrowed = rs.narrow(100, 200, null);const gapped = rs.gaps(chromSizes);
const diff = rs.setdiff(other);const pInter = rs.pintersect(other);const inter = rs.intersect(other);const combined = rs.concat(other);const unioned = rs.union(other);
const jac: number = rs.jaccard(other);RegionSetList
Section titled “RegionSetList”A collection of named RegionSets — the gtars equivalent of Bioconductor's GRangesList. Provides indexed pairwise operations without copying whole RegionSets on every call.
Construction
Section titled “Construction”// Empty builder + add()const rsl = new RegionSetList();rsl.add(rs1, 'rep1');rsl.add(rs2, 'rep2');rsl.add(rs3, 'rep3');
// Or build directly from BED entries for multiple sets at onceconst rsl2 = RegionSetList.fromEntries( [ [['chr1', 100, 200, ''], ['chr1', 300, 400, '']], // set 1 [['chr1', 150, 250, '']], // set 2 [['chr2', 500, 600, '']], // set 3 ], ['rep1', 'rep2', 'rep3'], // names; pass null to leave unnamed);Accessors
Section titled “Accessors”rsl.length // number of setsconst rs = rsl.get(0); // RegionSet at index (throws on out-of-range)rsl.names // string[] or nullconst flat = rsl.concat(); // flatten into a single RegionSet (no merge)Indexed pair operations
Section titled “Indexed pair operations”These let you compute operations on pairs by index without shuttling full RegionSets across the JS/Wasm boundary — useful for building N×N analysis grids:
const n = rsl.regionCount(0); // regions in set 0const pCount = rsl.pintersectCount(0, 1); // pairwise intersect countconst jac = rsl.jaccardAt(0, 1); // Jaccard between sets 0 and 1const un = rsl.unionAt(0, 1); // union as a new RegionSetconst diff = rsl.setdiffAt(0, 1); // set 0 minus set 1
const except = rsl.unionExcept(2); // union of everything but index 2Bulk operations
Section titled “Bulk operations”O(n) N-way operations via prefix/suffix arrays.
// Union of all setsconst unionAll = rsl.unionAll();
// Intersection of all setsconst interAll = rsl.intersectAll();
// Prefix/suffix-based leave-one-out: all N "union except i" results in O(n) unionsconst bulk = rsl.bulkUnionExcept();// { union_regions, union_nucleotides, except_unique: number[] }// except_unique[i] = number of regions unique to set i vs. the union of all othersPairwise Jaccard matrix
Section titled “Pairwise Jaccard matrix”const result = rsl.pairwiseJaccard();// { matrix: number[][], names: string[] | null }//// matrix is symmetric with 1.0 on the diagonal — one row per set, one col per set.ConsensusBuilder
Section titled “ConsensusBuilder”Builder pattern for consensus region analysis — given N input region sets, compute the reduced union annotated with per-region replicate support.
import { ConsensusBuilder } from '@databio/gtars';
const cb = new ConsensusBuilder();cb.add(rep1);cb.add(rep2);cb.add(rep3);
const consensus = cb.compute();// Array of { chr, start, end, count }
// Keep regions present in ≥ 2/3 replicatesconst robust = consensus.filter(r => r.count >= 2);console.log(`${robust.length} robust regions`);count is the number of input sets (not regions) that overlap each union region.
Result types
Section titled “Result types”ChromosomeStatistics
Section titled “ChromosomeStatistics”Returned by rs.chromosomeStatistics() → { [chr: string]: ChromosomeStatistics }.
| field | type |
|---|---|
chromosome | string |
number_of_regions | number |
start_nucleotide_position | number — leftmost start |
end_nucleotide_position | number — rightmost end |
minimum_region_length, maximum_region_length | number |
mean_region_length, median_region_length | number |
The values in the returned object are plain JS objects with these fields (serialized from Rust), not class instances.
RegionDistribution
Section titled “RegionDistribution”Entries in the array returned by rs.regionDistribution(n_bins, chrom_sizes).
| field | type |
|---|---|
chr | string |
start, end, n, rid | number |
n is the count of regions whose midpoint falls in the bin; rid is the bin's row index within its chromosome.
BedClassificationOutput
Section titled “BedClassificationOutput”Returned by the rs.classify getter. Identifies the BED/ENCODE subtype based on column analysis (uses the bedclassifier feature, enabled by default in the Wasm build).
| field | type |
|---|---|
bed_compliance | string |
data_format | string — e.g. "UcscBed", "EncodeNarrowPeak", etc. |
compliant_columns, non_compliant_columns | number |
See also
Section titled “See also”- wasm/partitions —
GeneModel,PartitionList,calcPartitions/calcExpectedPartitions. - wasm/signal —
SignalMatrixandcalcSummarySignal. - wasm/lola —
LolaRegionDBandrunLOLA. - wasm/overlappers — low-level overlap engine.
- gtars-core and gtars-genomicdist — Rust reference with algorithmic details and caveats that apply identically in Wasm.