RSBio-Seq
██████ ███████ ██████ ██ ██████ ███████ ███████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ███████ ██████ ██ ██ ██ █████ ███████ █████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ▄▄ ██
██ ██ ███████ ██████ ██ ██████ ███████ ███████ ██████
▀▀
RSBio-Seq reads and writes FASTA (.fasta, .fa, .fna) and FASTQ
(.fastq, .fq) files. Append .gz for compressed files. File format is
inferred from these lowercase filename extensions; .bgz and .bgzf suffixes
are not supported.
| Operation | Plain text | Ordinary gzip (.gz) |
BGZF (.gz) |
|---|---|---|---|
| Sequential reading | Supported | Supported | Supported |
| Indexed reading | Requires .fai |
Unsupported | Requires .fai and .gzi |
| Building indexes for existing files | Creates .fai |
Unsupported | Creates .fai and .gzi |
| Writing | Supported | Use index=False (default) |
Use index=True; also creates .fai and .gzi |
The sequential reader uses a buffered Rust parser in src/io.rs, inspired by
klib's kseq.h,
with direct reads into record buffers that become owned strings, and support
for wrapped FASTA/FASTQ records, LF/CRLF
line endings, and concatenated gzip members (including BGZF). FASTQ quality
length must match sequence length; malformed input raises OSError during
iteration. The library does not depend on the Rust bio crate.
Installation
1. From PyPI (Recommended)
Use the following command to install from PyPI.
pip install rsbio-seq
2. Build and install from source
To build from source, make sure you have the following programs installed.
- Rust - https://www.rust-lang.org/tools/install
- Maturin - https://www.maturin.rs/installation
- Python environment with Python >=3.9 - https://www.python.org/downloads/
From a checkout of this repository, create and activate a virtual environment, then install Maturin and build the extension into that environment:
python -m venv .venv
# Linux/macOS
source .venv/bin/activate
# Windows PowerShell: .venv\Scripts\Activate.ps1
python -m pip install "maturin>=1.9.3,<2.0"
maturin develop
# Optional optimized build:
maturin develop --release
To build a release mode wheel for installation, use this command.
maturin build --release
The wheel is written to target/wheels. Install the wheel matching your platform
and Python version (replace the placeholder with the actual filename):
python -m pip install "target/wheels/<wheel-filename>.whl"
Usage
Once installed you can import the library and use as follows.
Reading
from rsbio_seq import SeqReader, Sequence, ascii_to_phred
# each seq entry is of type Sequence
seq: Sequence
for seq in SeqReader("path/to/seq.fasta.gz"):
print(seq.id)
print(seq.seq)
# FASTA records have an empty quality string.
print(seq.qual) # prints an empty line
# optional description attribute
print(seq.desc)
For FASTQ, qual contains the quality string. For example, "IIII" decodes
to four Phred scores of 40:
from rsbio_seq import SeqReader, ascii_to_phred
for seq in SeqReader("path/to/seq.fastq.gz"):
print(seq.qual)
print(ascii_to_phred(seq.qual))
assert ascii_to_phred("IIII") == [40, 40, 40, 40]
Reading from FASTA or FASTQ (fai/fai+gzi) indexes
The indexed reader retrieves FASTA and FASTQ records by ID from plain text or BGZF-compressed files. Both formats require a .fai index; FASTQ indexes also contain quality offsets.
from rsbio_seq import SeqReaderIndexed, Sequence
seqs = SeqReaderIndexed(
"path/to/seq.fa",
"path/to/seq.fa.fai"
)
seq: Sequence = seqs["Record_1"]
print(seq.id)
print(seq.seq)
print(seq.desc)
"Record_2" in seqs # returns a boolean
For FASTQ, use the same API with a .fq or .fastq file and its index. The returned record includes its quality string.
seqs = SeqReaderIndexed("path/to/seq.fq", "path/to/seq.fq.fai")
seq = seqs["Read_1"]
print(seq.seq)
print(seq.qual)
BGZF-compressed FASTA and FASTQ files also require a .gzi index. Indexed access requires BGZF compression rather than ordinary gzip.
seqs = SeqReaderIndexed(
"path/to/seq.fa.gz",
"path/to/seq.fa.gz.fai",
"path/to/seq.fa.gz.gzi",
)
seq: Sequence = seqs["Record_1"]
print(seq.id)
print(seq.seq)
print(seq.desc)
"Record_2" in seqs # returns a boolean
# BGZF-compressed FASTQ
reads = SeqReaderIndexed(
"path/to/seq.fq.gz",
"path/to/seq.fq.gz.fai",
"path/to/seq.fq.gz.gzi",
)
read = reads["Read_1"]
print(read.seq)
print(read.qual)
A missing record ID raises KeyError. Errors opening the file or loading its
indexes raise OSError.
Indexing existing files
from rsbio_seq import build_index, SeqReaderIndexed
build_index("reads.fa") # creates reads.fa.fai
build_index("reads.fq.gz") # BGZF input; creates .fai and .gzi
reads = SeqReaderIndexed("reads.fq.gz", "reads.fq.gz.fai", "reads.fq.gz.gzi")
read = reads["Read_1"]
build_index(path) indexes an existing file without rewriting it. Compressed
input must be BGZF; ordinary gzip raises OSError. Existing indexes are replaced
after input validation. Record IDs are the first whitespace-delimited token
following > or @ in the header. Indexing requires unique IDs, nonempty
sequences, no blank lines, and sequence lines without whitespace. Each record
must use consistent line widths and LF or CRLF endings, except that the final
line may be shorter or have no newline. FASTQ quality length and wrapping must
match the sequence. Invalid or truncated input raises OSError. Rebuild the
indexes if the input file changes.
Writing
from rsbio_seq import SeqWriter, Sequence, phred_to_ascii
# writing fasta
seq = Sequence("id", "desc", "ACGT") # id, description, sequence
writer = SeqWriter("out.fasta")
writer.write(seq)
writer.close()
# writing fastq
seq = Sequence("id", "desc", "ACGT", "IIII") # id, description, sequence, quality
writer = SeqWriter("out.fastq")
writer.write(seq)
writer.close()
# writing gzipped
seq = Sequence("id", "desc", "ACGT", "IIII") # id, description, sequence, quality
writer = SeqWriter("out.fq.gz")
writer.write(seq)
writer.close()
# writing gzipped with phred score translation
qual = phred_to_ascii([40, 40, 40, 40])
seq = Sequence("id", "desc", "ACGT", qual) # id, description, sequence, quality
writer = SeqWriter("out.fq.gz")
writer.write(seq)
writer.close()
Call writer.close() after the last write to finalize the output and any
indexes, especially the .gzi index for BGZF output. Close a writer only once
and do not write to it afterward. Creating a writer replaces any existing file
at the output path.
For FASTQ, supply a quality string with exactly one character per sequence base;
the writer does not validate these lengths. Use ASCII sequence and quality
strings without embedded line breaks, and IDs without whitespace. For indexed
output, use unique IDs and nonempty sequences. FASTA output ignores qual.
We provide two utility functions for your convenience.
phred_to_ascii- convert phred scores list of numbers to a stringascii_to_phred- convert the quality string to a list of numbers
Quality strings use ASCII characters. These helpers convert between quality strings and numerical scores using Phred+33 encoding. For standard printable FASTQ qualities, use scores from 0 to 93.
Writing FASTA or FASTQ with indexes (fai/fai+gzi)
Set index=True to write a FASTA or FASTQ file with a .fai index. With
index=True, a .gz suffix selects BGZF compression and also creates a .gzi
index. With index=False, .gz output uses ordinary gzip. Index paths are
inferred from the output filename. Call close() to finish writing the file and
indexes before reading them.
from rsbio_seq import SeqWriter, Sequence
# Plain text
seq = Sequence("id", "desc", "ACGT") # id, description, sequence
writer = SeqWriter("out.fasta", index=True)
writer.write(seq)
writer.close()
# Compressed
seq = Sequence("id", "desc", "ACGT") # id, description, sequence
writer = SeqWriter("out.fa.gz", index=True)
writer.write(seq)
writer.close()
FASTQ indexes include offsets for both sequences and quality strings.
from rsbio_seq import SeqWriter, SeqReaderIndexed, Sequence
seq = Sequence("Read_1", "desc", "ACGT", "IIII")
# Creates out.fq and out.fq.fai
writer = SeqWriter("out.fq", index=True)
writer.write(seq)
writer.close()
# Creates out.fq.gz, out.fq.gz.fai, and out.fq.gz.gzi
writer = SeqWriter("out.fq.gz", index=True)
writer.write(seq)
writer.close()
reads = SeqReaderIndexed("out.fq.gz", "out.fq.gz.fai", "out.fq.gz.gzi")
read = reads["Read_1"]
print(read.seq) # ACGT
print(read.qual) # IIII
For wrapped output, pass a line width of at least 10 to writer.write(seq, wrap=60). FASTQ sequences and quality strings are wrapped at the same width.
Authors
- Anuradha Wickramarachchi https://anuradhawick.com
- Vijini Mallawaarachchi https://vijinimallawaarachchi.com
Support and contributions
Please get in touch via author websites or GitHub issues. Thanks!
License
RSBio-Seq is dual licensed under the Apache License, Version 2.0 or the GNU General Public License, Version 3 only, at your option.
SPDX license expression: Apache-2.0 OR GPL-3.0-only.
Metadata
Release files for rsbio-seq 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 2.8 MB
Release files / rsbio_seq-1.1.0-cp39-abi3-win_amd64.whl
| Download URL | rsbio_seq-1.1.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 257.0 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
58b6f78d80e702101d70e1048b8053bee467604274aa69d5095d0261f9768947
|
|
BLAKE2b-256 checksum How to use checksums |
d55c624d18fb62bc00ed948823774d744dabe16c42f09bdaf7e5f52c83736895
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / rsbio_seq-1.1.0-cp39-abi3-musllinux_1_2_x86_64.whl
| Download URL | rsbio_seq-1.1.0-cp39-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 585.5 kB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
350043c3da1883220e7565de12c0efc52712f96633390b5b48e6fa81c0364a18
|
|
BLAKE2b-256 checksum How to use checksums |
082a7180ccf9b224af94dd2c4e7d688af7044034f8efe4d9f5f181794839f0c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / rsbio_seq-1.1.0-cp39-abi3-musllinux_1_2_aarch64.whl
| Download URL | rsbio_seq-1.1.0-cp39-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 549.2 kB |
| Tags | CPython 3.9 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
5887c5c3dd3868d6e33d396ae5c9a1f03d010911e27a8d75c457983715b063c2
|
|
BLAKE2b-256 checksum How to use checksums |
5116adc260f718d76148ef80f4ed06282918c7fdd57862f4761986c4edd9ba53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / rsbio_seq-1.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | rsbio_seq-1.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 374.4 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
1d673abdc151757d6f336aa1e07a675b82f446416fef27fe2bdee5ad20e70c2b
|
|
BLAKE2b-256 checksum How to use checksums |
f0768beb21e7517f2f4925eebde04f1da2824d0d74b8c03266e9aa9fb8075b60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / rsbio_seq-1.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | rsbio_seq-1.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 371.3 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
f18dee63c244e4e426fcc72ade14fa4e94e052855e069b1c9c20274ad9b12f84
|
|
BLAKE2b-256 checksum How to use checksums |
f9ebc1f9d83d6146062b10680f36c1dbdbc1048d855ae8f0d9a4f1581c5831cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / rsbio_seq-1.1.0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | rsbio_seq-1.1.0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 346.5 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
9d05139e3edff942b79323e15ac70285b3cc2452787f387f4ce074ce2093323b
|
|
BLAKE2b-256 checksum How to use checksums |
240917f3d270850fbd496c3f5de50c995e586c002feb1f08ac74106468efa6c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / rsbio_seq-1.1.0-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | rsbio_seq-1.1.0-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 358.8 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
82905a65212e6f762a1d3d484e7b592003259d19b0a06de655f4cc1268b3d899
|
|
BLAKE2b-256 checksum How to use checksums |
845fcdf7158e89ef03412a5d28534fa70d53867771d217be4f48901312264b48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for rsbio-seq 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.