Skip to main content

RSBio-Seq is a fast and light-weight sequence reading library (built on top of rust bio crate).

Project description

RSBio-Seq

Cargo tests Downloads PyPI - Version Upload to PyPI License: GPL v3

██████  ███████ ██████  ██  ██████        ███████ ███████  ██████  
██   ██ ██      ██   ██ ██ ██    ██       ██      ██      ██    ██ 
██████  ███████ ██████  ██ ██    ██ █████ ███████ █████   ██    ██ 
██   ██      ██ ██   ██ ██ ██    ██            ██ ██      ██ ▄▄ ██ 
██   ██ ███████ ██████  ██  ██████        ███████ ███████  ██████  
                                                              ▀▀   

RSBio-Seq intends to provide reading/writing facility on common sequence formats (FASTA/FASTQ) in both raw (fasta, fa, fna, fastq, fq) and compressed formats (.gz).

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.

To build and install the development version of the wheel.

maturin develop # this installs the development version in the env
maturin develop --release # this installs a release version in the env

To build a release mode wheel for installation, use this command.

maturin build --release

You will find the whl file inside the target/wheels directory. Your whl file will have a name depicting your python environment and CPU architecture. The built wheel can be installed using this command.

pip install target/wheels/*.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)
    # for fastq quality line
    print(seq.qual) # prints IIII
    print(ascii_to_phred(seq.qual)) # prints [40, 40, 40, 40]
    # optional description attribute
    print(seq.desc)

Reading Indexed Fasta

Index reader supports fasta in raw text and bgzipped formats.

seqs = SeqReaderIndexed(
    "path/tp/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 bgzipped fasta files, a gzi file is required.

seqs = SeqReaderIndexed(
    "path/tp/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

Using an invalid key will result in KeyError.

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()

Note: close() is only required if you want to read the file again in the same function/code scope. Closing opened files is a good practice either way.

We provide two utility functions for your convenience.

  • phred_to_ascii - convert phred scores list of numbers to a string
  • ascii_to_phred - convert the quality string to a list of numbers

RSBio-Seq reads and write quality string in ascii format only. Please use these helper functions to translate if you intend to read them.

Authors

Support and contributions

Please get in touch via author websites or GitHub issues. Thanks!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rsbio_seq-0.1.4-cp39-abi3-win_amd64.whl (213.2 kB view details)

Uploaded CPython 3.9+Windows x86-64

rsbio_seq-0.1.4-cp39-abi3-musllinux_1_2_x86_64.whl (504.9 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

rsbio_seq-0.1.4-cp39-abi3-musllinux_1_2_aarch64.whl (502.1 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

rsbio_seq-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (333.5 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

rsbio_seq-0.1.4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (322.6 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

rsbio_seq-0.1.4-cp39-abi3-macosx_11_0_arm64.whl (298.1 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

rsbio_seq-0.1.4-cp39-abi3-macosx_10_12_x86_64.whl (314.8 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file rsbio_seq-0.1.4-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: rsbio_seq-0.1.4-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 213.2 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.8

File hashes

Hashes for rsbio_seq-0.1.4-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2722ef42c920dd64f5951bd167e01d36808f44b72c28d86ae2c97ef1f4af9705
MD5 936ad379be02cb0a4fddb20825fa0e72
BLAKE2b-256 12d67b4793469b1a12ec27e78f5f65f75f8479d26941f042783b429cb2d79253

See more details on using hashes here.

File details

Details for the file rsbio_seq-0.1.4-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for rsbio_seq-0.1.4-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a9dffbafd177635c2153bdaee7e8625ba582142804f3c3385baaa7dc7d54b417
MD5 6cff6c6d37019a9ed08109bc0fccbb76
BLAKE2b-256 fcd9c542cf240c339b9e257824e4b8722f2d82fda45dce798ba0327d43cd6373

See more details on using hashes here.

File details

Details for the file rsbio_seq-0.1.4-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for rsbio_seq-0.1.4-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7d66a3b21622aeec987e864ff57215b5c071f4ec8d8127b65b68c755138c0b5b
MD5 e9e9c40ea22445b1db19e782a390972f
BLAKE2b-256 c0196689f811fd0098d80822740e6a4edabdce6aac81c683ea380109acbd657a

See more details on using hashes here.

File details

Details for the file rsbio_seq-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rsbio_seq-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64f97210c527ee130811c432b19b9e68d9c2afe53461be0ab4ddc33458cda53c
MD5 f7f79f9ee537f15c7a7eefdb6e52011d
BLAKE2b-256 d15f82eb40af14ddcee3118b0fdbc25b9b6ad5870e904aaced2c4769a7a4ab6d

See more details on using hashes here.

File details

Details for the file rsbio_seq-0.1.4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rsbio_seq-0.1.4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 11994327f7b4720b85d297380f552515d20771fd3c7fc368fdc3f3122fa04ddb
MD5 84cc3444aca370bfce4023a12b4d7281
BLAKE2b-256 14d3f66a737237aa0331564065efea0a4490c41bd92146d7f38779de005c09cf

See more details on using hashes here.

File details

Details for the file rsbio_seq-0.1.4-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rsbio_seq-0.1.4-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72ab5d3626ded235c674c82b75c00d68a7972db9c8d481565e0ff99ce7037224
MD5 f687afd8ceb78ac34a25ba86cea6b6be
BLAKE2b-256 85c9ccafea4441252c26c9a9397d55294285b7dee5e66f7481ba5388fcc4e387

See more details on using hashes here.

File details

Details for the file rsbio_seq-0.1.4-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rsbio_seq-0.1.4-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c42bc2a39c413de661de6594ea19f9ea1eb108e6baa39e07f54ae7d24e245878
MD5 57467ebeeb4b8079343043afeea75d71
BLAKE2b-256 fd0c96af2cf2d0d58e793bb7045cc51aaa80ce5f28ee6bf989e2bc3382eea67b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page