# Tangermeme: A High-Performance Framework for Deep Learning Interpretability in Genomics
## Introduction
Interpreting deep learning models applied to biological sequences has become a central challenge in computational genomics. As models grow more complex, the need for efficient, scalable tools that can extract meaningful biological insights from model predictions becomes increasingly critical. Tangermeme is a software framework designed to address this gap by providing optimized, flexible, and computationally efficient methods for sequence preprocessing, model interpretation, and regulatory motif discovery. This article explores the key technical innovations and capabilities of Tangermeme, from its low-level encoding strategies to its novel seqlet-calling algorithm.
## Optimized One-Hot Encoding
One-hot encoding is a foundational step in virtually every deep learning pipeline applied to DNA sequences. In this representation, each nucleotide in a sequence is converted into a binary vector where only one element is set to one, indicating the identity of the nucleotide at that position. Traditional implementations of one-hot encoding follow a two-step procedure: first mapping characters to numeric indices and then using those indices to construct the final binary matrix. This approach introduces unnecessary computational overhead because it requires an intermediate array allocation, which becomes especially costly when processing large genomes or numerous sequences simultaneously.
Tangermeme introduces a streamlined encoding strategy that eliminates this intermediate step entirely. Rather than converting characters to indices first, Tangermeme directly interprets the byte representation of each character as an index for one-hot encoding. This allows the framework to produce the final encoded matrix in a single pass, avoiding the memory allocation burden of an intermediary array. The result is a significant speedup, particularly for long sequences or large batch sizes.
Additionally, Tangermeme encodes sequences using unsigned 8-bit integers rather than the more commonly used signed 32-bit or 64-bit floating-point representations. This choice dramatically reduces memory consumption and accelerates computation, as integer arithmetic is inherently faster than floating-point operations on most hardware platforms. Despite its efficiency, the encoding scheme degrades gracefully when it encounters unexpected or non-standard characters, and it provides the flexibility to exclude specific characters from the encoding, such as ambiguous nucleotide codes (typically represented as N), if desired.
### Benchmarking Encoding Performance
To demonstrate the practical advantages of this encoding approach, Tangermeme’s one-hot encoding implementation was benchmarked against several widely used genomic deep learning tools, including SeqPro, CREsted, gReLU, Selene SDK, and the ChromBPNet encoding function. Each tool was evaluated solely on its one-hot encoding functionality using the full chromosome 1 reference genome (hg38). All timing experiments were conducted on a single thread to ensure a fair comparison, avoiding complications introduced by parallel processing. Some packages, such as SeqPro and Selene SDK, required additional alphabet-definition steps that were excluded from the timing measurements, reflecting only the core encoding performance.
The results showed that Tangermeme’s approach consistently outperformed the competing implementations in terms of encoding speed, validating the benefits of avoiding intermediate calculations and leveraging compact integer representations.
## Models Used for Evaluation
Tangermeme was evaluated using five publicly available deep learning models that predict genomic regulatory phenomena. Two of these models—BPNet models predicting the binding profiles of the transcription factors E2F3 and MYC—were trained by the Tangermeme team. The remaining three models, DeepSEA/Beluga, ChromBPNet, and ProCapNet, were downloaded from public repositories and hosted for convenience.
The BPNet models were trained using the bpnet-lite v0.9.0 command-line tool with default parameters. BPNet generates predictions at base-pair resolution, producing two types of outputs per nucleotide: a profile output representing the probability of an observed sequencing read mapping to each position, and a count output representing the log of the total number of reads within the input window. These correspond to the shape and strength of transcription factor binding, respectively.
The training data consisted of chromatin immunoprecipitation followed by sequencing (ChIP-seq) experiments from the ENCODE Compendium. For E2F3, the experiment identifier was ENCSR036QIR, and for MYC it was ENCSR000EGJ, both using the control track ENCSR000BLJ. Training loci were drawn from peak regions in the associated peak files along with GC-matched negative examples derived from those same peaks. Input windows of 2,114 base pairs were extracted and centered on either the peak summits or selected background regions, with a random positional jitter of up to ±128 base pairs applied to introduce variability. During training, half of the examples were reverse-complemented, meaning both the input sequence and the corresponding output profiles were flipped along their respective axes. A fixed count loss weight of 100 was used during optimization.
The DeepSEA/Beluga model was obtained from the Kipoi model repository and was modified to use the standard ACGT nucleotide alphabet in place of the original AGCT ordering. For evaluation purposes, only the MYC output from K562 cells was considered. The ChromBPNet and ProCapNet models were retrieved from the ENCODE Compendium, and only fold 0 of each model was used for downstream analyses.
## Simulation Framework
To illustrate how Tangermeme decouples sequence manipulation operations from model inference, a series of simulations were conducted using the profile prediction output of a ChromBPNet model. These simulations explored several analytical transformations, including marginalizations, ablations, and variant effect predictions.
For the marginalization and ablation experiments, a set of 100 randomly generated DNA sequences, each 2,114 base pairs in length, was created using nucleotide probabilities derived from the human genome (28% A/T, 22% C/G). In the marginalization analysis, the subsequence ATGATGTCAT was inserted into the middle of each sequence, and predictions were computed both before and after the insertion. The results were averaged across all 100 sequences. In the ablation analysis, the same subsequence was first introduced into the sequences, and then a dinucleotide shuffle was applied to a specific window (between positions 1,030 and 1,075) to create the ablated versions. This shuffle disrupts local sequence context while preserving dinucleotide composition.
For the attribution-based analyses, DeepLIFT and SHAP methods were employed. Due to the averaging already performed across the 100 sequences, only a single background shuffle per sequence was needed, reducing computational cost without sacrificing statistical reliability. Saturation mutagenesis was performed in a windowed fashion, focusing specifically on the 1,040–1,075 base pair region surrounding the motif insertion site. This windowed approach accelerated computation while preserving the exactness of the analysis. For variant effect predictions, a single nucleotide substitution (G to A) was introduced at position 1,053.
### Comparing Seqlet Discovery Algorithms
A key component of the simulation work involved benchmarking Tangermeme’s recursive seqlet caller against the well-established TF-MoDISo seqlet calling algorithm. In these experiments, 100 uniform-random sequences of length 2,114 were generated, and the MYC binding motif CACGTG was inserted at the center of each. The MYC BPNet model was then used to generate feature attribution scores via DeepLIFT/SHAP, and both seqlet callers were applied to identify regions of the sequence that drive the model’s predictions.
The recursive seqlet caller was first evaluated at P-value thresholds of 0.01 and 0.001, and the TF-MoDISo algorithm was run with its default settings. A representative example from these runs is shown in the companion figure. The recursive caller was then tested across a broad range of P-value thresholds, from 0.5 down to 0.5 raised to the 12th power, as well as at a permissive threshold of 0.125. The seqlet boundary masks produced by each algorithm were compared against ground-truth labels corresponding to the central 6 base pairs where the MYC motif was inserted.
While this comparison has inherent limitations—seqlet callers could theoretically identify the motif at positions other than the center by chance—the imperfection affects all algorithms equally and does not obscure the broader trends that emerge from the comparison.
To assess real-world performance, the two algorithms were further benchmarked on a practical seqlet-calling scenario. Attribution scores were computed using DeepLIFT/SHAP with the same ChromBPNet model on K562 ATAC-seq peak regions, and then the seqlet callers were applied to identify regulatory motifs. Each algorithm was timed across ten replicate runs at increasing numbers of input examples, providing a robust estimate of computational efficiency under realistic conditions.
## Seqlet Calling: A Recursive Statistical Approach
Tangermeme features a novel seqlet-calling algorithm that distinguishes itself from existing approaches through its use of recursive statistical testing. A seqlet is defined as a contiguous span of nucleotides within a sequence that exhibits statistically significant attribution values, indicating that those positions contribute meaningfully to the model’s prediction. Tangermeme’s seqlet caller is the first algorithm capable of directly calling seqlets of variable length, offering greater flexibility than fixed-length approaches.
### Definition and Parameters
At its core, a seqlet is defined as a span of nucleotides whose cumulative attribution sum is statistically significant compared to a null distribution. Furthermore, all subspans within the seqlet that exceed a minimum length threshold (default: 4 nucleotides) must also meet the same statistical criterion. This recursive property ensures that seqlets are internally coherent and not artifacts of noisy attribution scores at individual positions. Shorter subspans below the minimum length are exempt from this requirement to prevent random noise from fragmenting seqlet calls and to allow seqlets to contain uninformative characters at their boundaries.
The algorithm is governed by a small set of interpretable parameters:
– **P-value threshold**: The most critical parameter, controlling the stringency of seqlet calls. Lower thresholds produce fewer but more confident seqlets.
– **Minimum seqlet length**: Helps filter out noise in attribution profiles; particularly relevant when attributions are noisy.
– **Maximum seqlet length**: Does not affect seqlets shorter than the specified maximum, offering flexibility in discovery resolution.
– **Flanking regions**: Optional extensions added to seqlet boundaries to improve robustness in downstream analyses.
– **Number of bins**: Controls the discretization of continuous attribution values into a finite set of integerized scores; broadly robust across a range of values and primarily affects computational time and memory usage.
### Algorithmic Procedure
The seqlet calling algorithm proceeds through several well-defined computational stages:
**Step 1 — Binning and Integerization**: Attribution values are min-max scaled using the global minimum and maximum across all positions in the dataset, multiplied by the number of bins, and floored to produce integerized scores. This discretization converts continuous attribution values into a form suitable for statistical modeling.
**Step 2 — Frequency Histogram Construction**: A frequency histogram is computed from the integerized scores, representing how often each discrete attribution value appears across all positions in all sequences. This histogram encodes the empirical distribution of attribution strengths in the data.
**Step 3 — Null Distribution Calculation**: Using the frequency histogram, null distributions are constructed for each possible seqlet length. These null distributions answer the question: what cumulative attribution sum would be expected by randomly sampling a given number of attribution values from the observed distribution, without regard to their contiguity? The null distributions are computed iteratively, with the distribution for length ( t ) derived from the distribution for length ( t-1 ), forming a convolution-like procedure. Each null distribution spans from 0 to ( t times (b-1) ), where ( b ) is the number of bins.
**Step 4 — Conversion to Survival Functions**: The probability density functions of the null distributions are converted to 1 minus their cumulative distribution functions (1 − CDFs). This transformation allows P-values to be obtained through direct indexing rather than numerical integration, dramatically accelerating the lookup process.
**Step 5 — P-value Computation**: The original attribution values are binned using the same procedure as in Step 1, and the resulting integerized scores are used to index into the 1 − CDF matrices, yielding P-values for every possible seqlet span at every position and length.
**Step 6 — Seqlet Decoding**: Seqlets are identified by finding spans where the P-value falls below the threshold and where all subspans (longer than the minimum length) also satisfy the threshold. This is accomplished through a two-pass procedure: first, shorter spans are propagated to block longer non-significant spans, and then the search proceeds from the maximum seqlet length downward, always calling the longest qualifying span at each position. Overlapping seqlets at the same positions are prevented by marking columns as occupied once a seqlet is called.
This procedure guarantees that the longest seqlet is reported for a given set of positions, though it is not guaranteed to be the most statistically significant one.
## Seqlet Annotation
Once seqlets have been identified, the next step is to determine which known regulatory motifs they most closely resemble. Tangermeme provides an annotation function that uses Tomtom-lite, a streamlined version of the Tomtom motif matching tool, to compare the nucleotide sequence within each seqlet against a user-supplied motif database. The annotation is performed by identifying the motif with the lowest P-value for each seqlet, indicating the best match.
In the evaluation described here, the motif database was a curated subset of JASPAR2024, restricted to motifs derived from ChIP-seq experiments performed in Homo sapiens. This biologically focused database ensures that the annotations are relevant to human regulatory genomics.
## Seqlet Counting and Analysis
With seqlets called and annotated, Tangermeme provides several counting and statistical capabilities to extract higher-level biological insights from the results.
### Motif Occurrence Counting
The most basic analysis involves counting how many times each annotated motif appears across all sequences. This produces an ( n times m ) count matrix, where ( n ) is the number of sequences and ( m ) is the number of motifs in the database. Summing across sequences yields the total number of occurrences for each motif, while summing across motifs gives the total number of seqlets called per sequence. These statistics provide a high-level overview of the regulatory landscape captured by the model and the data.
### Pairwise Motif Co-occurrence Analysis
Tangermeme also supports counting pairwise co-occurrences of motifs, producing an ( n times m times m ) tensor. This analysis can be performed in two modes:
– **Symmetric mode**: The co-occurrence of motifs A and B is counted in both the A row and the B row, producing a symmetric matrix. This mode is the default and is useful when the relationship between motifs is of interest regardless of order.
– **Asymmetric mode**: Motifs are counted according to their sequential order in the sequence from start to end, without accounting for the strandedness of the motifs. This mode is particularly relevant for analyses of transcriptional initiation, where the order and orientation of regulatory elements matter, though the user must manually ensure correct strandedness.
Additionally, users can specify whether repeated occurrences of the same motif should each be counted or whether only unique motif pairs should be considered. For example, in a sequence containing three copies of motif A followed by one copy of motif B, the asymmetric mode can record either three A–B pairs or just one, depending on the analysis goals. This is especially important for motifs that form arrays, such as KLF binding sites, where the raw count of array elements can dominate the statistics.
### Spacing Analysis
Tangermeme further enables the analysis of spacing between co-occurring motifs. For each pair of motifs, the tool counts how often they appear at each possible intervening distance up to a user-defined maximum. All spacings beyond this maximum are excluded from the analysis. The resulting spacing matrices can be symmetric or asymmetric depending on the mode selected. Because many motif pairs do not co-occur at all and those that do are unlikely to appear at many different distances, these matrices tend to be highly sparse, and appropriate storage and visualization strategies are important for interpreting the results.
## Frequently Asked Questions (FAQ)
### What is Tangermeme?
Tangermeme is a software framework designed for deep learning interpretability in genomics. It provides optimized tools for sequence encoding, model interpretation, motif discovery through seqlet calling, and downstream statistical analysis of regulatory elements.
### How does Tangermeme’s one-hot encoding differ from standard implementations?
Unlike conventional approaches that first convert characters to numeric indices and then use those indices to build the encoding matrix—requiring an intermediate array—Tangermeme directly interprets the byte value of each character as an index. This single-pass approach eliminates unnecessary memory allocation and intermediate computation, resulting in faster encoding speeds and lower memory usage.
### What makes the seqlet caller unique?
Tangermeme’s seqlet caller is the first algorithm capable of directly calling seqlets of variable length using a recursive statistical testing framework. By defining seqlets as contiguous spans where the attribution sum is statistically significant and all longer subspans within them are also significant, it produces principled, interpretable results with only a few tunable parameters.
### What models are compatible with Tangermeme?
Tangermeme is designed to work with any deep learning model that produces attribution scores or prediction profiles for DNA sequences. It has been demonstrated with BPNet, ChromBPNet, ProCapNet, and DeepSEA/Beluga models, but its modular architecture supports integration with a wide range of genomic deep learning frameworks.
### Can Tangermeme handle ambiguous nucleotide codes?
Yes. The one-hot encoding scheme gracefully handles unexpected or non-standard characters and provides the option to exclude specific characters, such as ambiguous codes (N), from the encoding if desired.
### What is the significance of the P-value threshold in seqlet calling?
The P-value threshold is the most important parameter to tune in seqlet calling. It determines the statistical significance required for a span of nucleotides to be considered a seqlet. Lower thresholds produce fewer, more confident seqlets, while higher thresholds may capture more subtle signals but risk including false positives.
### How does seqlet counting work?
After seqlets are called and annotated, Tangermeme can count motif occurrences per sequence, count total occurrences per motif across all sequences, compute pairwise co-occurrence matrices, and analyze the spacing between co-occurring motifs. These statistics can be computed in symmetric or asymmetric modes and with options for handling repeated motif occurrences.
### Is Tangermeme designed for large-scale genomic analyses?
Yes. Tangermeme’s memory-efficient encoding, optimized computation, and support for windowed analyses make it well-suited for processing entire chromosomes or large numbers of sequences. Its ability to perform attribution calculations with minimal background shuffles further enhances its scalability.
## Conclusion
Tangermeme represents a significant advance in the toolkit available for interpreting deep learning models applied to biological sequences. By optimizing the lowest-level operations such as one-hot encoding—eliminating unnecessary intermediate calculations and memory allocations—Tangermeme achieves substantial performance improvements over existing tools. The framework’s novel recursive seqlet caller introduces a principled, flexible approach to motif discovery that directly handles variable-length seqlets and requires only a handful of intuitive parameters. Combined with its comprehensive seqlet annotation, counting, and spacing analysis capabilities, Tangermeme provides an end-to-end pipeline for extracting biologically meaningful insights from deep learning models of gene regulation. Its efficient design and modular architecture position it as a valuable resource for researchers seeking to understand how sequence features influence model predictions in genomics and beyond.
Thank you for reading



