| Title: | GPU-Portable Pairwise and Codon-Aware Multiple Sequence Alignment |
|---|---|
| Description: | Sequence alignment from one portable C++17 core: edit-distance (Levenshtein / WFA-equivalent) and Smith-Waterman local pairwise alignment with score and CIGAR reconstruction, plus multiple sequence alignment in DNA, protein and codon-aware modes (MACSE-class: whole-codon indels that preserve the reading frame, optional frameshift refinement). The core builds and runs anywhere (it is the CPU backend, so it needs no GPU toolchain); the wavefront/GPU backend (ROCm/CUDA) computes the same results with acceleration and is tracked in the sibling C++ repository. A batch API aligns many pairs in one call and reports how many were resolved, so silent under-serving is impossible. Designed to slot into data.frame/tibble pipelines. |
| Authors: | Angel Robles-Fernandez [aut, cre] |
| Maintainer: | Angel Robles-Fernandez <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 2.0.0.9000 |
| Built: | 2026-10-11 11:14:05 UTC |
| Source: | https://github.com/alrobles/genoaligner-r |
Pairwise sequence alignment from one portable C++17 core: edit distance (Levenshtein / WFA-equivalent) and Smith-Waterman local alignment, both with score and CIGAR reconstruction. The core builds and runs anywhere (it is the CPU backend, so it needs no GPU toolchain); the sibling C++ library tracks the GPU (ROCm/CUDA) backend that computes the same results with wavefront acceleration.
The two entry points are align (edit distance bounded by
smax) and align_sw (local Smith-Waterman with affine
gaps). Both are vectorised over pairs, so a two-column pipeline
(query, reference) maps straight to a data.frame of scores and CIGARs.
Maintainer: Angel Robles-Fernandez [email protected]
Authors:
Angel Robles-Fernandez [email protected]
Useful links:
Report bugs at https://github.com/alrobles/genoaligner-r/issues
Computes the Levenshtein edit distance (substitution = 1, insertion = 1, deletion = 1) between each pair of sequences, with an optional CIGAR reconstruction. This is the same distance the WFA formulation computes; wavefront/GPU speed is a backend concern, the result is identical.
align_edit(pattern, text, smax = 64, with_cigar = TRUE)align_edit(pattern, text, smax = 64, with_cigar = TRUE)
pattern |
Character vector; query sequences (recycled to match
|
text |
Character vector; reference sequences (recycled to match
|
smax |
Numeric; maximum edit distance searched, in |
with_cigar |
Logical; if |
A pair is resolved only when its true distance is at most smax;
otherwise score is NA and the pair is reported as
resolved = FALSE. The count of resolved pairs is deliberately visible:
a caller that only reads scores can silently miss that most input was
abandoned when smax is set too tightly.
A data.frame with one row per pair and columns:
score (edit distance, NA if unresolved), resolved
(logical), cigar (over {M, X, I, D}, NA if unresolved or
!with_cigar), rescore_ok and wellformed_ok
(validation flags computed in the library).
CIGAR convention (identical for align_edit and align_sw):
M/X consume a text and a pattern base; I consumes an
extra text base; D consumes an extra pattern base.
align_edit("ACGTACGT", "ACGTTCGT", smax = 8) align_edit(c("AAAACCC", "ACGT"), c("AAAATCC", "ACCT"), smax = 8)align_edit("ACGTACGT", "ACGTTCGT", smax = 8) align_edit(c("AAAACCC", "ACGT"), c("AAAATCC", "ACCT"), smax = 8)
Local alignment with affine gap penalties {match, mismatch, gap_open,
gap_extend}. Penalties are positive and subtracted. A pair with score
== 0 has no positive-scoring local alignment (disjoint sequences); all four
coordinates are -1 and cigar is empty.
align_sw(text, pattern, scoring = c(2L, -3L, 5L, 2L), with_cigar = TRUE)align_sw(text, pattern, scoring = c(2L, -3L, 5L, 2L), with_cigar = TRUE)
text |
Character vector; row-axis sequences (recycled). |
pattern |
Character vector; column-axis sequences (recycled). |
scoring |
Numeric vector of length 4, named or positional:
|
with_cigar |
Logical; if |
A data.frame with one row per pair and columns: score,
start_i, start_j, end_i, end_j (0-based
coordinates of the aligned span, -1 when score is 0/unknown),
cigar (over the span), rescore_ok, wellformed_ok and
too_large (the pair's matrix exceeded the supported size limit).
align_sw("TTTACGTGTT", "ACGTGT", scoring = c(2, -3, 5, 2)) align_sw(c("ACGTACGT", "GGGG"), c("ACGTTCGT", "ACGT"), c(2, -3, 5, 2))align_sw("TTTACGTGTT", "ACGTGT", scoring = c(2, -3, 5, 2)) align_sw(c("ACGTACGT", "GGGG"), c("ACGTTCGT", "ACGT"), c(2, -3, 5, 2))
Requires the ape package (in Suggests; used here only).
as_dnabin(x)as_dnabin(x)
x |
A |
An ape::DNAbin matrix.
if (requireNamespace("ape", quietly = TRUE)) { as_dnabin(msa_align(c("ACGTACGT", "ACGTTCGT"))) }if (requireNamespace("ape", quietly = TRUE)) { as_dnabin(msa_align(c("ACGTACGT", "ACGTTCGT"))) }
Real mitochondrial cytochrome b (cytb) records downloaded from NCBI nuccore for three hare species (Lepus granatensis, L. timidus, L. europaeus) — all flagged as population-genetic candidates in the EcoSeek genominer database (https://genominer.ecoseek.org) — plus the European rabbit (Oryctolagus cuniculus) as an outgroup.
lepus_cytblepus_cytb
A data.frame with 37 rows and 4 columns:
NCBI nuccore accession (character).
Species epithet: granatensis, timidus,
europaeus or cuniculus (character).
Full NCBI FASTA header (character).
Nucleotide sequence as downloaded, untrimmed (character, 400–1200 bp; MN098958.1 contains one IUPAC ambiguity code, W).
Sequences are shipped exactly as retrieved: mixed lengths, untrimmed,
and including two mislabelled records (XM_017337704.3 and XM_051846530.2,
predicted nuclear mRNAs that a "cytochrome b" title search returns but
that are not the mitochondrial gene). The lepus-cytb vignette uses them
to show that a near-zero local alignment score flags a mislabelled record.
NCBI nuccore, downloaded 2026-09-24; see
data-raw/lepus_cytb.R in the source repository for the exact
eutils queries and snapshot FASTAs.
data(lepus_cytb) table(lepus_cytb$species) align_edit(lepus_cytb$sequence[1:3], lepus_cytb$sequence[2], smax = 200)data(lepus_cytb) table(lepus_cytb$species) align_edit(lepus_cytb$sequence[1:3], lepus_cytb$sequence[2], smax = 200)
Progressive MSA: fragment-corrected k-mer distances, a deterministic neighbor-joining guide tree, post-order profile-vs-profile semiglobal alignment (free end gaps, position-specific gap penalties). The pipeline is deterministic: identical input always produces identical output.
msa_align( seqs, names = NULL, mode = c("dna", "protein"), guide = "nj", iter_refine = 0L, fft_band = 0L, fft_lags = 4L, fft_min_rel = 0.1 )msa_align( seqs, names = NULL, mode = c("dna", "protein"), guide = "nj", iter_refine = 0L, fft_band = 0L, fft_lags = 4L, fft_min_rel = 0.1 )
seqs |
Character vector; unaligned sequences (no |
names |
Optional character vector of sequence names, same length as
|
mode |
|
guide |
Guide-tree construction; only |
iter_refine |
Integer |
fft_band |
Integer |
fft_lags |
Integer |
fft_min_rel |
Numeric |
An object of class genoaligner_msa with components
aligned (character matrix, one row per input sequence, one column
per alignment position), qc (per-sequence data.frame; all
NA outside codon mode) and params (echo of the effective
request). See msa_codon for the codon-aware mode.
msa_align(c("ACGTACGTAA", "ACGTTCGT", "ACGTACG")) msa_align(c(insulin = "MALWMRLLPLL", insulin2 = "MALWTRLLPLL"), mode = "protein")msa_align(c("ACGTACGTAA", "ACGTTCGT", "ACGTACG")) msa_align(c(insulin = "MALWMRLLPLL", insulin2 = "MALWTRLLPLL"), mode = "protein")
Codon-aware MSA of coding sequences: each sequence is tokenized to codons
(NCBI genetic-code table gc) and aligned over a codon
substitution matrix (BLOSUM62 on the translated amino acids plus a
per-identical-nucleotide bonus and a stop-codon penalty). With the default
refine = FALSE every indel is a whole codon, so every aligned row
stays a multiple of 3 and the reading frame is preserved by construction.
msa_codon( seqs, names = NULL, gc = 1L, refine = FALSE, iter_refine = 0L, fft_band = 0L, fft_lags = 4L, fft_min_rel = 0.1 )msa_codon( seqs, names = NULL, gc = 1L, refine = FALSE, iter_refine = 0L, fft_band = 0L, fft_lags = 4L, fft_min_rel = 0.1 )
seqs |
Character vector; unaligned sequences (no |
names |
Optional character vector of sequence names, same length as
|
gc |
Integer; NCBI genetic code: |
refine |
Logical; run the stage-2 frameshift refinement pass. |
iter_refine |
Integer |
fft_band |
Integer |
fft_lags |
Integer |
fft_min_rel |
Numeric |
With refine = TRUE a MACSE-style stage-2 pass reintroduces
internal 1-2 nt frameshift events as narrow columns, so the output is a
nucleotide MSA no longer guaranteed to be a multiple of 3 — that is the
intended semantics for sequences that truly carry frameshifts.
A genoaligner_msa object. In codon mode qc carries
measured values per input sequence: frame (chosen reading frame,
0-2), n_stops (stop codons in the tokenized stream) and
partial (partial/ambiguous codons and held-out frameshift
blocks). A clean coding sequence reports n_stops = 0.
msa_codon(c("ATGATAATCACC", "ATGATTATCACCTGA")) msa_codon(c("ATGATAATCACC", "ATGATTATCACCTGA"), gc = 2)msa_codon(c("ATGATAATCACC", "ATGATTATCACCTGA")) msa_codon(c("ATGATAATCACC", "ATGATTATCACCTGA"), gc = 2)