| align_pq | R Documentation |
Build a multiple sequence alignment from the refseq slot of a
phyloseq-class object, or from a set of sequences
given directly. Two backends are available:
"decipher" (default), the pure-R DECIPHER::AlignSeqs(), which needs no
external program;
"mafft", the MAFFT command-line aligner driven through ips::mafft(),
which is considerably faster on large sets of sequences and is the usual
choice for metabarcoding-scale data.
The alignment is returned as a DNAStringSet, not as a phyloseq object.
Gap characters are valid DNA letters, so an alignment can technically be
written back into a refseq slot, but the sequences of that slot are
consumed as unaligned elsewhere in the pqverse (clustering, BLAST, primer
trimming), so MiscMetabar never does it for you. Feed the returned alignment
to build_phytree_pq() or Biostrings::writeXStringSet() instead.
align_pq(
x,
method = c("decipher", "mafft"),
exec = NULL,
mafft_method = "auto",
thread = -1,
force = FALSE,
verbose = FALSE,
...
)
x |
(required) A |
method |
One of |
exec |
Path to the MAFFT executable. Only used when
|
mafft_method |
The MAFFT strategy passed to |
thread |
Number of threads given to MAFFT. Default to -1, i.e. MAFFT detects the number of available cores itself. |
force |
Logical, if TRUE sequences that are already all of the same length are realigned anyway. Default to FALSE, in which case such sequences are assumed to be aligned already and returned untouched. |
verbose |
Logical, if TRUE report the aligner used and the width of the resulting alignment. Default to FALSE. |
... |
Additional arguments passed on to |
A DNAStringSet of aligned sequences, all of the same width, in the
order of the input.
MAFFT is an external program and is not installed by MiscMetabar. It is available from https://mafft.cbrc.jp/alignment/software/, and from the usual package managers:
Debian / Ubuntu: sudo apt install mafft
macOS (Homebrew): brew install mafft
conda: conda install -c bioconda mafft
Windows: use the installer from the MAFFT website, or run it under WSL.
If the executable is not on the PATH, either pass its path with exec or
set it once for the session with
options(MiscMetabar.mafftpath = "/path/to/mafft").
Adrien Taudière
is_mafft_installed(), build_phytree_pq()
data(data_fungi_mini)
df <- subset_taxa_pq(data_fungi_mini, taxa_sums(data_fungi_mini) > 12000)
# Pure-R alignment, no external program required
ali <- align_pq(df, method = "decipher", verbose = TRUE)
ali
if (MiscMetabar::is_mafft_installed()) {
# The same alignment with MAFFT, much faster on large refseq slots
ali_mafft <- align_pq(df, method = "mafft", verbose = TRUE)
# A more accurate (and slower) MAFFT strategy; `exec` gives an explicit
# path to the executable
ali_linsi <- align_pq(df, method = "mafft", mafft_method = "localpair")
# Sequences can also be given directly
align_pq(phyloseq::refseq(df), method = "mafft")
# Feed the alignment to a tree builder or write it to a FASTA file
Biostrings::writeXStringSet(ali_mafft, file.path(tempdir(), "refseq_aligned.fasta"))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.