Back to All ProjectsTechnical Specification & Results Sheet
Sequencing & Bioinformatics81% Sequence Identity vs Dorado

HMM Nanopore Basecaller

Numba-Accelerated 1,025-State 5-Mer Basecaller on Raw POD5 Signals

Built a 1,025-state 5-mer Hidden Markov Model (log-space Baum-Welch EM and 4x downsampled Viterbi decoding) in Python with Numba JIT multi-core execution to decode raw nanopore POD5 ionic current reads, achieving 81% sequence identity against Oxford Nanopore Dorado.

Validated Accuracy

81.0% Identity

Global Bio.Align.PairwiseAligner benchmark vs Oxford Nanopore Dorado HAC

Markov State Space

1,025 States

1,024 canonical 5-mers + 1 catch-all UNK state (sparse O(6N) transitions)

Training Throughput

50,000 Samples/Batch

Numba @njit(parallel=True, fastmath=True) log-space Baum-Welch EM

Reference Alignment

NC_000022.11 (Chr 22)

Two-pass multiprocessing DTW search pinned at offset 38,010,200 bp

Skills & Stack:
Python
Numba JIT
Hidden Markov Models
POD5 / FASTQ
Biopython
Pandas / NumPy / SciPy
Git

System Architecture & Quantitative Results

Eight-module Python and Numba JIT basecalling pipeline (Pod5DataLoader, SignalPreprocessor, BaseSignatureAnalyzer, SignalAligner, HMMBasecaller, SignalVisualizer, main_test, evaluate_accuracy) decoding 4 kHz raw Oxford Nanopore .pod5 ionic current traces from first principles.
Restricting the transition graph to self-loops (pstay=0.50p_{\text{stay}} = 0.50), catch-all escape (pto_unknown=0.05p_{\text{to\_unknown}} = 0.05), and the 4 valid step-1 overlapping 5-mer successors (pstep=0.1125p_{\text{step}} = 0.1125) inside pre-filtered NumbaList adjacency lists cuts per-step complexity by 200x from dense O(N2)O(N^2) to sparse O(6N)O(6N).
  • POD5 Ingestion & Conditioning (signal_preprocessor.py): Context-managed pod5.Reader streaming followed by 3×IQR3\times\text{IQR} spike clipping, 5-point medfilt, 3rd-degree polynomial baseline drift removal, RobustScaler z-IQR standardisation, and MAD derivative event segmentation.
  • Exploratory Signature Clustering (base_signature_analyzer.py): Extracts 6 moments per event plateau (mean, std, duration, median, skewness, kurtosis) for PCA dimensionality reduction, Ward hierarchical dendrograms, and K-Means clustering.
  • Zero-Copy Two-Pass Parallel DTW (signal_aligner.py): Downsamples query traces by the physical translocation ratio (4000 Hz/450 bp s−14000\text{ Hz} / 450\text{ bp s}^{-1}) and distributes coarse-to-fine fastdtw windows across CPU cores via Pool.imap_unordered with _init_worker shared reference memory.
  • Log-Space Numba Kernels (hmm_basecaller.py): Custom @njit(fastmath=True) _logsumexp_jit kernel preventing IEEE-754 underflow across _forward_pass_log_jit, _backward_pass_log_jit, 50,000-sample batched Baum-Welch EM (sigmai≥0.20sigma_i \ge 0.20 floor), and 4×4\times downsampled Viterbi decoding (viterbi_downsample_factor = 4).
  • Dorado Benchmark (evaluate_accuracy.py): Global pairwise alignment (Bio.Align.PairwiseAligner) against Oxford Nanopore Dorado (dna_r10.4.1_e8.2_400bps_hac@v5.0.0) confirming 81.0% sequence identity on human GIAB HG002 reads.

Results, Signal Conditioning & Diagnostic Plots

[Fig. 1]Viterbi MAP 5-Mer Decoding & Baum-Welch Gaussian Emission Posteriors

Left: Piecewise 5-mer Viterbi state sequence decoded over RobustScaler-normalised 4 kHz ionic current (HG002 read 2536858a). Right: Learned Gaussian emission densities (sigma >= 0.20 floor) showing homopolymer overlap vs mixed purine/pyrimidine separation.

Viterbi MAP 5-Mer Decoding & Baum-Welch Gaussian Emission Posteriors

[Fig. 2]Two-Pass Multiprocessing DTW Alignment & 6-Feature Event PCA Projection

Left: Coarse-to-fine fastdtw cost landscape across human chromosome 22 using the Nanopolish R9.4 5-mer pore model. Right: BaseSignatureAnalyzer 6-feature PCA projection (mean, std, dwell duration, median, skewness, kurtosis).

Two-Pass Multiprocessing DTW Alignment & 6-Feature Event PCA Projection

[Fig. 3]Five-Stage POD5 Signal Conditioning & Apache Arrow Architecture

3x IQR outlier clipping, 5-point median filtering, 3rd-order polynomial drift subtraction, and RobustScaler normalisation streamed directly from Apache Arrow POD5 tables.

Five-Stage POD5 Signal Conditioning & Apache Arrow Architecture
Five-Stage POD5 Signal Conditioning & Apache Arrow Architecture

Want the Full Development Story?

Read the behind-the-scenes journey, design trade-offs, limitations & future ideas

Read Full Blog Article