Learn R Programming

seqmagick: Sequence Manipulation Utilities

Tools for reading and writing biological sequences in multiple formats, including ‘FASTA’, ‘PHYLIP’, ‘CLUSTAL’, ‘STOCKHOLM’, ‘MEGA’ and ‘GenBank’. Supports interleaved and sequential layouts where applicable, and reads or writes gzip, bzip2 and xz compressed files transparently. Converts between formats, renames sequences via a two-column mapping, summarizes sequence counts, lengths, GC content and ambiguous characters, and manipulates sequence sets (e.g., filtering by patterns and computing consensus sequences from alignments). Also includes functions to download nucleotide records from NCBI by accession.

:writing_hand: Authors

YuLab@SMU https://yulab-smu.top

:page_facing_up: Supported file formats

FormatReadWrite
FASTA (.fas/.fa/.fasta):heavy_check_mark::heavy_check_mark:
PHYLIP (.phy):heavy_check_mark::heavy_check_mark:
CLUSTAL (.clw):heavy_check_mark:-
STOCKHOLM (.sth):heavy_check_mark:-
MEGA (.meg):heavy_check_mark:-
GenBank (.gb):heavy_check_mark:-
NCBI (online):heavy_check_mark:-

Both sequential and interleaved layouts are supported for FASTA and PHYLIP. Compressed files (gzip, bzip2, xz) are handled transparently.

:hammer: Installation

Install from CRAN:

install.packages("seqmagick")

Or grab the development version from GitHub:

if (!requireNamespace("remotes", quietly=TRUE))
    install.packages("remotes")
remotes::install_github("YuLab-SMU/seqmagick")

:bulb: Quick Examples

library(seqmagick)

fas <- system.file("extdata/HA.fas", package = "seqmagick")

## reading/writing FASTA files
x <- fa_read(fas)
fa_write(x[1:5], "sub.fa.gz")     # gzip/bzip2/xz supported

## a quick summary (counts, lengths, GC content)
fa_summary(fas)

## sequence manipulation
bs_filter(x, 'ATGAAAGTAAAA', by='sequence')   # keep matching sequences

## renaming sequences via two-column mapping
map <- data.frame(old = names(x)[1:2],
                  new = c("HA_HK", "HA_BR"))
y <- bs_rename(x, map)

## format conversion (requires aligned sequences)
fas2phy("aln.fas", "aln.phy")
phy2fas("aln.phy", "aln.fas")

## download nucleotide records from NCBI
seqs <- ncbi_fa_read(acc = c("AB115403", "CY084969"))

For more details, please see the online vignette.

If you use seqmagick, please cite:

Yu G (2026). seqmagick: Sequence Manipulation Utilities. R package version 0.1.9, https://github.com/YuLab-SMU/seqmagick.

Copy Link

Version

Install

install.packages('seqmagick')

Monthly Downloads

794

Version

0.1.9

License

Artistic-2.0

Issues

Pull Requests

Stars

Forks

Maintainer

Guangchuang Yu

Last Published

August 30th, 2026

Functions in seqmagick (0.1.9)

bam2DNAStringSet2

bam2DNAStringSet2
bs_aln

bs_aln
fa_to_interleaved

fa_to_interleaved
download_genbank

download_genbank
consensus

consensus
fa_combine

fa_combine
bam2DNAStringSet

bam2DNAStringSet
bs_hamming

bs_hamming
bs_rename

bs_rename
bs_filter

bs_filter
gb_read

gb_read
fa_write

fa_write
ncbi_fa_read

ncbi_fa_read
fas2phy

fas2phy
fa_rename

fa_rename
phy2fas

phy2fas
get_id

get_id
fa_filter

fa_filter
fa_summary

fa_summary
mega_read

read sequence alignment file
seqlen

seqlen
replaceInside

replaceInside
seqmagick-package

seqmagick: Sequence Manipulation Utilities
phy_read

phy_read
phy_write

phy_write
renameTXT

renameTXT