Skip to content

LOLA enrichment (Wasm)

Wasm bindings for gtars-lola — LOLA (Locus Overlap Analysis) enrichment testing, runnable entirely in the browser. Given a user set of regions, a universe, and a region database (built in memory from API-served BED data), computes Fisher's exact test enrichment of the user set against every database region set.

See the Rust gtars-lola reference for the full statistical details — Fisher's exact test via hypergeometric survival function, CMLE odds ratio, contingency table semantics, and compatibility notes with R LOLA. This page is a Wasm-focused binding reference.

import init, {
LolaRegionDB,
runLOLA,
checkUniverseAppropriateness,
} from '@databio/gtars';
await init();

Construct from an array of { regions, name } objects, where regions is an array of [chr, start, end] tuples and name is the filename-like identifier:

const dbEntries = [
{
name: 'encode_k562_ctcf.bed',
regions: [
['chr1', 100, 200],
['chr1', 400, 500],
['chr2', 1000, 1100],
],
},
{
name: 'encode_hela_ctcf.bed',
regions: [
['chr1', 150, 250],
['chr2', 1050, 1150],
],
},
];
const db = new LolaRegionDB(dbEntries);

The constructor builds an IGD overlap index internally and wraps it with minimal annotation (filename only). To attach richer per-file metadata — cell type, tissue, antibody, etc. — build the annotated RegionDB on the Rust side and serve it through a different transport (e.g. a custom binary format), or expose a method that accepts RegionSetAnno objects alongside the regions.

db.numRegionSets // number
db.listRegionSets() // string[] — filenames
db.collectionAnno // Array of { collectionname, collector, date, source, description } (empty for an in-memory DB)
// Extract region sets by 0-based index as a RegionSetList
// (pass null for "all sets"; names are populated from filenames)
const rsl = db.getRegionSets(null);
const rsl2 = db.getRegionSets([0, 5, 12]);

getRegionSets() returns a RegionSetList with .names populated from the database filenames.

Runs Fisher's exact test for every (user_set, db_set) pair and returns a column-oriented object suitable for dropping directly into a DataFrame or table.

runLOLA(
userSets: Array<Array<[string, number, number]>>,
universe: Array<[string, number, number]>,
regionDb: LolaRegionDB,
minOverlap?: number, // default 1
direction?: string, // "enrichment" (default) | "depletion"
): LolaResultColumnar

Parameters:

  • userSets — array of user sets, where each user set is an array of [chr, start, end] tuples. Pass a single-element outer array [peaks] for a one-user-set analysis.
  • universe — a single array of [chr, start, end] tuples representing the background.
  • regionDb — a LolaRegionDB.
  • minOverlap — minimum bp overlap to count as overlapping (default 1).
  • direction — "enrichment" (default, P(X ≥ a), alternative "greater") or "depletion" (P(X ≤ a), alternative "less"). "less" is accepted as an alias for depletion; any other value (including "greater") runs enrichment.

Returns an object with parallel arrays (one entry per (user_set, db_set) pair) using camelCase keys:

keytypemeaning
userSetnumber[]0-based user-set index
dbSetnumber[]0-based db-set index
collection(string | null)[]per-file annotation, usually null in Wasm
pValueLognumber[]-log10(p) from Fisher's exact test, capped at ~322
oddsRationumber[]CMLE odds ratio (matches R fisher.test()$estimate)
supportnumber[]overlap count between user set and db set
rnkPv, rnkOr, rnkSupnumber[]1-based per-metric ranks within the user set
maxRnknumber[]max of the three ranks
meanRnknumber[]mean of the three ranks
b, c, dnumber[]signed contingency values (can be negative)
qValue(number | null)[]BH-adjusted p-value (applied automatically inside runLOLA)
description, cellType, tissue, antibody, treatment, dataSource(string | null)[]per-file metadata
filenamestring[]db set file name
sizenumber[]number of regions in the db set

Like the Python binding, Wasm runLOLA auto-applies annotate_results + apply_fdr_correction internally — you don't need to call them separately. Rows come back sorted by descending pValueLog, then ascending meanRnk (matching R LOLA output order).

import init, {
LolaRegionDB,
runLOLA,
RegionSet,
} from '@databio/gtars';
await init();
// Helper to convert a RegionSet to the tuple form LOLA expects
function toTuples(rs: RegionSet): Array<[string, number, number]> {
// Iterate rs and pull chr/start/end — or keep the original BedEntries
// if you still have them in scope from constructing the RegionSet.
// ...
}
// 1. Build the region database from API-fetched data
const dbEntries = await fetchDatabaseRegions(); // [{ name, regions }, ...]
const db = new LolaRegionDB(dbEntries);
// 2. Prepare user sets and universe as tuple arrays
const userSets = [userPeakTuples];
const universe = universeTuples;
// 3. Run enrichment
const results = runLOLA(userSets, universe, db, 1, 'enrichment');
// 4. Pivot to row-oriented view for rendering
const n = results.pValueLog.length;
for (let i = 0; i < n; i++) {
console.log(
`${results.filename[i]} ` +
`p=${results.pValueLog[i].toFixed(2)} ` +
`OR=${results.oddsRatio[i].toFixed(2)} ` +
`support=${results.support[i]}`
);
}

Diagnostic check — for each user set, reports what fraction of user-set regions overlap the universe and whether there are many-to-many mappings.

const report = checkUniverseAppropriateness(userSets, universe);
// Returns a column-oriented object:
// {
// userSet: number[],
// totalRegions: number[],
// regionsInUniverse: number[],
// coverage: number[], // 0.0 to 1.0 per user set
// manyToMany: number[], // count of user regions overlapping >1 universe region
// warnings: string[] // free-form warning messages, pooled across user sets
// }
const n = report.userSet.length;
for (let i = 0; i < n; i++) {
console.log(
`user set ${report.userSet[i]}: ` +
`${(report.coverage[i] * 100).toFixed(1)}% coverage, ` +
`${report.manyToMany[i]} many-to-many`
);
}
for (const w of report.warnings) {
console.warn('⚠', w);
}

Warnings fire when coverage drops below 50% (severe) or 90% (moderate), or when any user region overlaps more than one universe region.

  • wasm/regionset — RegionSet, RegionSetList, and the ConsensusBuilder used upstream of LOLA analyses.
  • gtars-lola — full Rust API reference, including the contingency table math, p-value computation, and CMLE odds ratio details.