Skip to content

Refine networks#21

Merged
ncborcherding merged 5 commits into
develfrom
refine-networks
Jun 27, 2026
Merged

Refine networks#21
ncborcherding merged 5 commits into
develfrom
refine-networks

Conversation

@ncborcherding

@ncborcherding ncborcherding commented Jun 27, 2026

Copy link
Copy Markdown
Member

On clonally expanded repertoires buildNetwork() spent most of its time recomputing distances between identical sequences and skipping length-incompatible pairs one at a time. The engine was effectively all-pairs within each V/J block.

What

The C++ core was rewritten around candidate generation. No new dependencies, and the default output is unchanged.

  • Deduplication to unique (sequence, V, J) representatives. Distance work runs over representatives, then edges expand back to member nodes.
  • Length + V/J blocking as an index. Representatives are bucketed by length and only length-compatible buckets in the same block are compared (Hamming compares equal length only).
  • Candidate hashing. Levenshtein and Damerau use SymSpell deletion neighborhoods (Damerau at radius 2k). Hamming uses pigeonhole segment indexing. Each falls back to length-blocked comparison when the edit radius is too large.
  • Integer output. The engine returns node indices and labels are attached in R, removing string churn from the parallel core.
  • New expand argument. "clique" (default) reproduces exact edge multiplicity for community detection. "star" preserves connected components with far fewer edges.

Performance (identical output, clique mode)

Case Before After
25k cells, many V genes, Levenshtein t=2 6.8s 3.3s (~2.1x)
15k unique seqs, one block, Levenshtein t=1 35.1s 0.49s (~70x)

star expansion also cut edge count ~13x on the first case with identical connected components.

Bug fixes

  • Banded Levenshtein band edge. The boundary cell seeded the diagonal predecessor with D[i-1][0] instead of D[i-1][start_j-1], so pairs whose only optimal alignment rides the band edge were missed (true distance == |Δlen| == threshold), including identical sequences at tight normalized thresholds. Masked before because callers passed loose thresholds (wide band). The fix only recovers true edges (verified: 4 added, 0 removed across the regression grid, all confirmed against adist).
  • Threshold boundary. Normalized cutoffs are now robust to floating-point rounding, so a normalized distance exactly equal to the threshold is kept, matching the documented inclusive behavior.

Testing

  • New set-equality regression harness over a wide grid (every metric x normalize x threshold x V/J filter, plus duplicate-heavy, empty-string, single-member, and unequal-length cases). clique mode is byte-identical to the previous engine apart from the band-bug recoveries now baked into the golden snapshot.
  • New tests: star preserves components and vertex sets, Damerau transposition trap, and Levenshtein vs stats::adist exactness across thresholds.
  • Full package test suite passes.

jwokaty and others added 4 commits April 28, 2026 09:03
Rewrite the C++ core (fastEditEdges.cpp) around candidate generation
instead of all-pairs comparison. No new dependencies, and the default
(clique) output is identical to the previous engine.
- Deduplicate to unique (sequence, V, J) representatives so clonal
  expansion no longer drives quadratic distance computation.
- Use length and V/J blocking as an index. Only length-compatible
  representatives in the same block are compared.
- Add SymSpell deletion-neighborhood hashing for Levenshtein (radius k)
  and Damerau (radius 2k, since a transposition costs 2 in Levenshtein),
  and pigeonhole segment indexing for Hamming. Both fall back to
  length-blocked comparison outside their range.
- Return integer node indices from the engine and attach labels in R,
  avoiding millions of barcode strings inside the parallel core.
- Add an `expand` argument to buildNetwork(): "clique" (default) keeps
  exact edge multiplicity, "star" preserves connected components with
  far fewer edges for a large memory win.
Fix a pre-existing banded Levenshtein error that dropped pairs whose
only optimal alignment rides the band edge, including identical
sequences at a tight normalized threshold. The boundary cell read the
wrong diagonal value. The fix only recovers true edges. Also make the
normalized-threshold cutoff robust to floating-point rounding so a
normalized distance exactly equal to the threshold is kept.
Add a set-equality regression harness plus star, Damerau, and
Levenshtein-vs-adist correctness tests. Bump version to 1.7.1.
@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.59036% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
R/buildNetwork.R 73.33% 4 Missing ⚠️
Files with missing lines Coverage Δ
src/fastEditEdges.cpp 98.14% <100.00%> (ø)
R/buildNetwork.R 57.81% <73.33%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ncborcherding ncborcherding merged commit 8c03003 into devel Jun 27, 2026
2 of 3 checks passed
@ncborcherding ncborcherding deleted the refine-networks branch June 27, 2026 19:33
ncborcherding added a commit that referenced this pull request Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants