Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

bx-distance-models

Latest version: v0.2.1

Overview

Last scanned
30 Nov 2026
Published
30 Nov 2026
npm package Publisher: aaboyles
0 Stars
0 Forks
2 Versions
238 Downloads
Rust Repo language

Scan summary

bx-distance-models was last scanned on 30 Nov 2026 at version 0.2.1. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 2 versions; the latest was published on 30 Nov 2026.
  • Findings: 1 rule fired in version 0.2.1 (1 low). The score describes this version only.
  • Downloads: 238 downloads.

Versions

2 versions published
Versions and the rules that fired in each
VersionPublishedStatus
0.2.1 LATEST 30 Nov 2026 1 rule fired
0.2.0 20 Nov 2026 1 rule fired

Rules fired in 0.2.1: 1

Findings

1 Low

Findings for v0.2.1. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

WebAssembly module included

The package includes a WebAssembly (.wasm) module. It cannot be reviewed as source, but it runs sandboxed inside the JavaScript runtime and can access only what the host code gives it. WebAssembly is common in parsers, codecs and cryptography libraries. Shown for awareness.

LOW
Checking access…

🔒 Create a free account to see all 1 finding with descriptions and instance counts

The score describes 0.2.1; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

BX Distance Models

High-performance nucleotide sequence distance calculations compiled to WebAssembly. This library provides a collection of evolutionary and statistical distance metrics for comparing DNA sequences, optimized for speed and accuracy in browser and Node.js environments.

Features

  • Multiple Distance Metrics: Support for basic, evolutionary, and diagnostic distance models
  • WebAssembly Performance: Compiled to WASM for near-native speed in JavaScript environments
  • Zero Dependencies: Minimal runtime dependencies for maximum portability
  • Batch Processing: SequenceSet encodes sequences once (2 bits per base plus a validity mask) and compares 64 sites per instruction with popcount
  • Thresholded Output: return only pairs within a distance threshold, with exact early exit for far-apart pairs
  • Ambiguity Codes: skip IUPAC ambiguity codes (fast path), or resolve/average them (fallback used only for sequences that contain them)
  • Transition/Transversion Analysis: Built-in diagnostics for evolutionary analysis
  • Gap Handling: Gaps, N and other non-nucleotide characters are skipped

Supported Metrics

Basic Distance Metrics
  • SNPs Distance: Count of single nucleotide polymorphisms (absolute count)
  • Hamming Distance: Proportion of differing positions between sequences (0-1)
  • P-Distance: Simple proportion of nucleotide differences
Evolutionary Models
  • TN93 (Tamura-Nei 93): Sophisticated model accounting for different transition/transversion rates
  • JC69 (Jukes-Cantor): Simple evolutionary distance model
  • K2P (Kimura 2-Parameter): Two-parameter model for transitions and transversions
  • T92 (Tamura 1992), as tn92: Kimura's two-parameter model extended for G+C-content bias

Evolutionary distances are expected substitutions per site, so they can exceed 1. When two sequences are too divergent for a model (one of its logarithms would need a non-positive argument, e.g. p ≥ 3/4 for JC69), the distance is Infinity; it never falls within a finite links() threshold. A log argument within rounding error of zero (≤ 1e-12) counts as zero, so a pair exactly on a model's boundary is Infinity too, rather than a spurious distance of about 19.

When two sequences share no comparable sites at all (for example, they only overlap at gaps), every distance is NaN: it is undefined, not maximal. links() never includes such a pair, and the SNP count is 0.

TN93 when a base is missing. If one of A, C, G, T never occurs in a pair's compared sites, some TN93 terms are 0/0 (no substitution of that kind is possible either). This library drops those terms, their limit. HIV-TRACE's tn93 uses the K2P formula for such a pair instead (and reports 1000 when that saturates). Both are defensible; they give different values. To match tn93, create the set with { tn93K2pFallback: true } (see SequenceSet); 'tn93' then uses K2P for those pairs, still Infinity on saturation and NaN with nothing to compare. Pairs with all four bases are unaffected.

Diagnostics
  • Transitions Count: Purine-to-purine (A↔G) and pyrimidine-to-pyrimidine (C↔T) changes
  • Transversions Count: Purine-to-pyrimidine and pyrimidine-to-purine changes
  • Ts/Tv Ratio: Transition-to-transversion ratio

Installation

From NPM
npm install bx-distance-models
From Source

Clone the repository and follow the Build for Development section.

Usage

The package is a wasm-pack web build: a plain ES module that browsers (including module Web Workers) can load straight from node_modules, no bundler needed. Call its default export, init, once before using anything else; it fetches and instantiates the .wasm file next to the module. The examples below assume this has been done.

import init, { tn93_distance } from 'bx-distance-models';
await init(); // or init({ module_or_path: url }) to load the .wasm from elsewhere
Basic Example (JavaScript/TypeScript)
import { snps_distance, hamming_distance, tn93_distance } from 'bx-distance-models';

// Simple pairwise distances
const seq1 = 'ATCGATCG';
const seq2 = 'ATCGATCC';

// Count SNPs (absolute differences)
const snps = snps_distance(seq1, seq2); // Returns: 1

// Hamming distance (proportion)
const hamming = hamming_distance(seq1, seq2); // Returns: 0.125 (1/8)

// TN93 evolutionary distance
const tn93 = tn93_distance(seq1, seq2); // Returns: evolutionary distance
Handling Gaps and Ambiguous Bases

Both sequences must be properly aligned. Every metric compares only sites where both sequences hold A, C, G or T (either case; U is read as T). Gaps (-, .), N, ? and any other character are skipped and do not count toward the number of compared sites:

const seq1 = 'ATCG-ATCG';  // Gap at position 4
const seq2 = 'ATCGTNCGG';  // Ambiguous nucleotide (N) at position 5

// Distances are computed ignoring these positions
const distance = hamming_distance(seq1, seq2);

Partial IUPAC ambiguity codes (R, Y, S, W, K, M, B, D, H, V) are skipped by the single-pair functions. SequenceSet can resolve them, and N, instead; see Ambiguity codes.

Transition/Transversion Analysis
import { transitions_count, transversions_count, ts_tv_ratio } from 'bx-distance-models';

const seq1 = 'ATCG';
const seq2 = 'AGCG';  // A->G transition at position 1

const transitions = transitions_count(seq1, seq2);    // Returns: 1
const transversions = transversions_count(seq1, seq2); // Returns: 0
const ratio = ts_tv_ratio(seq1, seq2);                // Returns: Infinity (1/0)
Batch Processing - Pairwise Distances

For many sequences, build a SequenceSet. It encodes every sequence once and returns typed arrays instead of one JS object per pair:

import { SequenceSet, get_distance_index } from 'bx-distance-models';

const seqs = ['ATCGATCG', 'ATCGATCC', 'GCGCGCGC'];
const set = new SequenceSet(seqs);

// Upper triangle, row by row: (0,1), (0,2), (1,2)
const d = set.distances('tn93');            // Float64Array [d01, d02, d12]
get_distance_index(0, 2, seqs.length);      // 1: position of pair (0, 2) in d

// Only pairs within a threshold, as parallel typed arrays.
// For snps/hamming/p_distance/jc69/k2p/tn93, far-apart pairs stop early.
const links = set.links('tn93', 0.015);
const { source, target, distance } = links; // Uint32Array, Uint32Array, Float64Array
links.free();

set.free(); // release WASM memory when done

Metric names: snps, hamming, p_distance, jc69, k2p, tn92, tn93, transitions, transversions, ts_tv_ratio.

Row ranges and Web Workers

distances() and links() take an optional row range [rowStart, rowEnd). Results for consecutive ranges concatenate to the full triangle, so long jobs can be chunked (for progress or cancellation) or split across Web Workers. row_splits(k) gives k + 1 row boundaries with nearly equal pair counts:

// main.js
const splits = new SequenceSet(seqs).row_splits(navigator.hardwareConcurrency);
const parts = await Promise.all([...Array(splits.length - 1)].map((_, w) => new Promise(resolve => {
  const worker = new Worker(new URL('./distance-worker.js', import.meta.url), { type: 'module' });
  worker.onmessage = e => { resolve(e.data); worker.terminate(); };
  worker.postMessage({ seqs, start: splits[w], end: splits[w + 1] });
})));
// parts[0], parts[1], ... concatenated = the full upper triangle

// distance-worker.js
import init, { SequenceSet } from 'bx-distance-models';
const ready = init();
self.onmessage = async ({ data: { seqs, start, end } }) => {
  await ready;
  const set = new SequenceSet(seqs);
  const d = set.distances('tn93', start, end);
  set.free();
  self.postMessage(d, [d.buffer]);
};

Without a bundler or import map, import the module by URL instead, e.g. import init, { SequenceSet } from './node_modules/bx-distance-models/pkg/bx_distance_models.js'; init() finds bx_distance_models_bg.wasm relative to that URL.

Each worker encodes its own copy of the sequences (a few milliseconds), so no SharedArrayBuffer or cross-origin isolation is needed.

Ambiguity codes
const set = new SequenceSet(seqs, 'resolve'); // or 'average', 'gapmm'; default 'skip'

The modes are those of HIV-TRACE's tn93 -a (veg/tn93), and TN93 distances agree with it to 1e-12 (see Testing):

  • 'skip' (default): sites where either sequence holds a partial ambiguity code are not compared. Every pair uses the fast bit-plane kernel.
  • 'resolve': a site counts as a match if the two codes share a base (R vs A); otherwise it is averaged.
  • 'average': each site contributes every pair of bases the two codes allow, weighted equally (R vs A is half a match and half an A↔G transition). Counts can be fractional.
  • 'gapmm': as 'average', and a gap facing anything other than a gap is compared as an N (any base), so a gap facing A adds a quarter to each of A-A, A-C, A-G and A-T: three quarters of a mismatch. Gap facing gap is skipped. Every metric uses it, not only TN93.

HIV-TRACE's -g (tn93 -a resolve -g FRACTION, what HIV-TRACE runs) is 'resolve' with a maximum ambiguity fraction:

const set = new SequenceSet(seqs, 'resolve', { maxAmbiguityFraction: 0.015 });
const links = set.links('tn93', 0.015); // early exit still applies

Each pair is resolved, unless the sites resolution touched are at least that fraction of the pair's compared sites; then the pair is averaged instead. As in tn93 (ambig_count in computeTN93), a resolved site is a base facing a code that contains it (R facing A, N facing anything), or two ambiguity codes facing each other, whether or not they share a base. A base facing a code that does not contain it (R facing C) is averaged in either case and does not count. 1 never averages, 0 always does. The decision costs one scan per pair: the bit-plane counts are shared, and only the ambiguous sites are counted again with the averaging table.

N and ? are fourfold ambiguity codes (any base) in 'resolve', 'average' and 'gapmm', as in tn93: N facing A counts as a match (A-A) when resolving, and adds a quarter to each of A-A, A-C, A-G and A-T when averaging. 'skip' and the single-pair functions skip them. Releases up to 0.1.0 skipped N in every mode (see the changelog).

Other characters that are not nucleotides (-, ., X, *, digits, ...) are gaps: skipped, or compared as N in 'gapmm'. tn93 itself drops such characters while reading FASTA (shifting the rest of the sequence), which an aligned per-site comparison cannot do. U is read as T everywhere; tn93 reads it as a separate code that skip mode skips.

Sequences without ambiguity codes still use the fast path; only pairs involving a sequence that contains them pay for the extra work. Partial codes are visited one by one, which costs in proportion to their number; sites compared as N (and gaps in 'gapmm') are counted with popcounts over the 64-site words that hold any. set.ambiguous_count() reports how many sequences need either.

Legacy batch functions

The original batch functions keep their signatures and now run on the same kernel:

import { compute_pairwise_distances } from 'bx-distance-models';

const sequences = [
  { id: 'seq1', seq: 'ATCGATCG' },
  { id: 'seq2', seq: 'ATCGATCC' },
  { id: 'seq3', seq: 'GCGCGCGC' }
];

// Compute all pairwise distances using Hamming metric (default)
const distances = compute_pairwise_distances(sequences, 'hamming');
// Returns: [
//   { source: 'seq1', target: 'seq2', distance: 0.125 },
//   { source: 'seq1', target: 'seq3', distance: 1.0 },
//   { source: 'seq2', target: 'seq3', distance: 0.875 }
// ]

// Using TN93 evolutionary model
const evolutionaryDistances = compute_pairwise_distances(sequences, 'tn93');

Building one JS object per pair costs several times more than computing the distance, so prefer SequenceSet when there are many sequences. compute_pairwise_distances_flat(ids, seqs, metric) and compute_pairwise_distances_flat_all(ids, seqs) return Float64Arrays in the same order as SequenceSet.distances().

React Component Example
import React, { useState, useEffect } from 'react';
import init, { hamming_distance, tn93_distance } from 'bx-distance-models';

const ready = init();

function SequenceDistanceCalculator() {
  const [seq1, setSeq1] = useState('ATCGATCG');
  const [seq2, setSeq2] = useState('ATCGATCC');
  const [results, setResults] = useState({});

  useEffect(() => {
    ready.then(() => {
      const hamming = hamming_distance(seq1, seq2);
      const tn93 = tn93_distance(seq1, seq2);
      setResults({ hamming, tn93 });
    });
  }, [seq1, seq2]);

  return (
    <div>
      <input 
        value={seq1} 
        onChange={(e) => setSeq1(e.target.value)} 
        placeholder="Sequence 1"
      />
      <input 
        value={seq2} 
        onChange={(e) => setSeq2(e.target.value)} 
        placeholder="Sequence 2"
      />
      <div>
        <p>Hamming Distance: {results.hamming?.toFixed(4)}</p>
        <p>TN93 Distance: {results.tn93?.toFixed(4)}</p>
      </div>
    </div>
  );
}

API Reference

Basic Metrics
snps_distance(seq1: string, seq2: string) -> number

Returns the absolute count of single nucleotide polymorphisms.

hamming_distance(seq1: string, seq2: string) -> number

Returns the proportion of differing positions (0.0 to 1.0).

p_distance(seq1: string, seq2: string) -> number

Returns the simple proportion of nucleotide differences.

Evolutionary Models

These return substitutions per site (not capped at 1), or Infinity when the model saturates.

tn93_distance(seq1: string, seq2: string) -> number

Tamura-Nei 93 distance (separate rates for A↔G, C↔T and transversions; base frequencies from the two sequences). Without the K2P fallback when a base is missing (SequenceSet has it as an option).

jc69_distance(seq1: string, seq2: string) -> number

Jukes-Cantor 69 distance (simple model, assumes equal substitution rates). Infinity when p ≥ 3/4.

k2p_distance(seq1: string, seq2: string) -> number

Kimura 2-parameter distance (accounts for different transition/transversion rates).

tn92_distance(seq1: string, seq2: string) -> number

Tamura (1992) distance, often called T92: d = −h·ln(1 − P/h − Q) − ½(1 − h)·ln(1 − 2Q), with h = θ₁ + θ₂ − 2θ₁θ₂ from the G+C content θ of each sequence. Equals K2P when both are 50% G+C.

Diagnostics
transitions_count(seq1: string, seq2: string) -> number

Count of purine-to-purine (A↔G) and pyrimidine-to-pyrimidine (C↔T) substitutions.

transversions_count(seq1: string, seq2: string) -> number

Count of purine-to-pyrimidine and pyrimidine-to-purine substitutions.

ts_tv_ratio(seq1: string, seq2: string) -> number

Ratio of transitions to transversions (useful for quality assessment).

Batch Processing
new SequenceSet(seqs: string[], ambiguity?: 'skip' | 'resolve' | 'average' | 'gapmm', options?: SequenceSetOptions)

Encodes aligned sequences once. Throws on an unknown ambiguity mode, an unknown option, or an invalid one. Options:

  • maxAmbiguityFraction?: number ('resolve' only, 0 to 1): HIV-TRACE's -g; see Ambiguity codes.
  • tn93K2pFallback?: boolean: 'tn93' uses K2P for a pair in which a base never occurs, as HIV-TRACE's tn93 does (default: the TN93 terms that vanish drop out). See Evolutionary Models.

The .d.ts exports AmbiguityMode and SequenceSetOptions for these arguments.

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm bx-distance-models

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Plug and Pray: Your AI Agents Are Taking Orders From Strangers
Research

Plug and Pray: Your AI Agents Are Taking Orders From Strangers

CVE

Java4Shell (CVE-2026-114938): Easy to Crash, Hard to Exploit — Less Than 0.12% of JVMs Estimated at Risk of RCE

Vulnerability Insights

OpenSSH Password Authentication Bypass on Alpine Linux (*sshole) – CVE-2026-123158

Frame 2085668439 (1)
Group 1261154229