NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Alignment-free Comparison of Metagenomics Sequences via Approximate String Matching

Jian Chen, Le Yang, Lu Li, Steve Goodison, Yijun SunbioRxiv 2020

Abstract

Quantifying pairwise sequence similarities is a key step in metagenomics studies. Alignment-free methods provide a computationally efficient alternative to alignment-based methods for large-scale sequence analysis. Several neural network-based methods have recently been developed for this purpose. However, existing methods do not perform well on sequences of varying lengths and are sensitive to the presence of insertions and deletions. In this paper, we describe the development of a new method, referred to as AsMac, that addresses the aforementioned issues. We proposed a novel neural network structure for approximate string matching for the extraction of pertinent information from biological sequences and developed an efficient gradient computation algorithm for training the constructed neural network. We performed a large-scale benchmark study using real-world data that demonstrated the effectiveness and potential utility of the proposed method.

Introduction

In bioinformatics, comparing DNA or RNA sequences is the foundational process for tasks ranging from phylogenetic tree construction to taxonomic identification in microbiome samples. The gold standard for these comparisons is the Needleman-Wunsch (NW) algorithm, which utilizes dynamic programming to determine the optimal alignment. However, the $O(L^2)$ computational complexity of NW makes it a significant bottleneck for the millions of long sequences generated by modern "third-generation" sequencing technologies like PacBio or Nanopore.

To mitigate this, researchers often turn to "alignment-free" methods that count short snippets, or k-mers. While computationally efficient, these methods are brittle; a single insertion or deletion (indel) can shift the sequence and disrupt k-mer counts. Recent deep learning models have attempted to learn sequence embeddings to solve this, but they often struggle with variable-length sequences and lack robust mechanisms to handle indels. This paper introduces AsMac (and its core Continuous Sequence Matching (CSM) function) to bridge the gap between alignment accuracy and alignment-free speed.

Methods: The CSM Architecture

The authors introduce the CSM function as a specialized, differentiable layer within a Siamese neural network. This architecture allows the model to learn embeddings that directly correspond to evolutionary distances.

Siamese Network and Embedding

The model employs two identical neural network branches with shared weights. Each branch processes an input sequence and converts it into a high-dimensional embedding vector. The network is trained so that the cosine distance between these two vectors approximates the actual alignment distance calculated by traditional methods.

Overview of the AsMac/CSM architecture. Panel (a) shows the Siamese network training process. Panels (b) and (c) detail the internal mechanics of the CSM layer, illustrating the approximate string matching and differentiable dynamic programming.

Alignment as Convolution

In a standard Convolutional Neural Network (CNN), a kernel slides over data using a dot product. In CSM, the kernel is treated as a learnable "short sequence." Instead of a simple dot product, the model identifies the Best Approximate Subsequence (BAS)—effectively performing a localized mini-alignment between the kernel and the input sequence. This makes the model inherently "indel-aware."

Differentiable Dynamic Programming

To enable training via backpropagation, the authors implemented a "soft-max" version of the NW recursion. This mathematical smoothing allows gradients to flow back through the discrete steps of the alignment process, updating the kernel sequences to better capture biological motifs.

Efficient Training and Optimization

To handle the scale of metagenomics data, the researchers developed a fast random batching strategy. By sampling $n$ sequences and calculating all $O(n^2)$ pairwise distances simultaneously, they significantly reduced the time required for the model to converge.

Batch-wise training strategy. The model computes a cosine distance matrix from sequence embeddings and minimizes the loss relative to the ground-truth alignment distance matrix.

Key Results and Benchmarking

The study evaluated AsMac on four diverse 16S rRNA datasets, including the massive Greengenes database and noisy real-world data from the Zymo Mock Community.

  • Superior Accuracy: On the Greengenes dataset, AsMac achieved a Mean Relative Error (MRE) of 4.5%, significantly outperforming previous state-of-the-art neural models like SENSE and traditional k-mer methods like kmacs (~12.7% MRE).
  • Robustness to Noise: On the noisy Zymo dataset, where other methods saw error rates double, AsMac maintained a low 13.1% MRE, demonstrating its resilience to sequencing errors and biological noise.
  • Parameter Efficiency: Remarkably, AsMac achieved these results with only ~4,200 parameters—nearly ten times fewer than competing models—proving that a biologically-informed architecture is more effective than simply increasing model size.

Conclusion

AsMac represents a significant advancement in alignment-free sequence comparison. By embedding the logic of dynamic programming directly into a neural network, it achieves high accuracy and robustness to indels while remaining computationally efficient. Future work will focus on expanding the model to handle the larger alphabets of protein sequences and improving the interpretability of the learned kernels to better understand the biological motifs the network prioritizes.

Summary updated

BibTeX
@misc{chen2020alignment,
  author = {Jian Chen and Le Yang and Lu Li and Steve Goodison and Yijun Sun},
  title = {{Alignment-free Comparison of Metagenomics Sequences via Approximate String Matching}},
  year = {2020},
  doi = {10.1101/2020.05.24.113852},
  howpublished = {bioRxiv},
}
Figure