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 from FASTA (fai/fai+gzi) index

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.

Writing to FASTA with an Index (fai/fai+gzi)

Writing FASTA with an index can be performed in plain text and compressed forms. In compressed form the compression used is bgzip. In addition to fai there will also be a gzi file in compressed form. You can specify to compress using gz suffix at the end. Index paths are automatically inferred.

# Plain text
seq = Sequence("id", "desc", "ACGT") # id, description, sequence
writer = SeqWriter("out.fasta", True) # set index true
writer.write(seq)
writer.close()

# Compressed
seq = Sequence("id", "desc", "ACGT") # id, description, sequence
writer = SeqWriter("out.fa.gz", True) # set index true
writer.write(seq)
writer.close()

Planned soon for the major release v1.0.0

  • Support for fastq Indexes

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.5-cp39-abi3-win_amd64.whl (222.4 kB view details)

Uploaded CPython 3.9+Windows x86-64

rsbio_seq-0.1.5-cp39-abi3-musllinux_1_2_x86_64.whl (517.9 kB view details)

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

rsbio_seq-0.1.5-cp39-abi3-musllinux_1_2_aarch64.whl (514.7 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

rsbio_seq-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (346.4 kB view details)

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

rsbio_seq-0.1.5-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (335.0 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

rsbio_seq-0.1.5-cp39-abi3-macosx_11_0_arm64.whl (309.2 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

rsbio_seq-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl (326.5 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for rsbio_seq-0.1.5-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 04809f6b94b925bbec2cdeae5bb76b84322615e45c97e24c19aaffef826e87aa
MD5 12e223b071b26d27500b2495cfe09d95
BLAKE2b-256 ddcc371d8226e822141b7779109a563ea9e477a482f258f3c02cdbde882bd22f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rsbio_seq-0.1.5-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3b7ef0492192381bf7bf7bfc51bdacc7b22490d1c5d9aae0010ca1c8857c9b6c
MD5 89fdedf913e912412248fdbb611370c4
BLAKE2b-256 a8b7a2936807a327491f8638c7cad355fa2cf6c31abd2d8a563ae892b48d2957

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rsbio_seq-0.1.5-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 6f71b52374c5d7381a385c899fffd09d7a83963e499286ea3fd0b9bb7dd12f28
MD5 57f54be33b53049674590a1e96437ea1
BLAKE2b-256 3e0347ff73444f2c88b15a89f01b23e5d9bfeea9dd7393fb2145f99d74a22052

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rsbio_seq-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef17234fec30a3a52fcc1d71e22cf31e4d641ed56ffab7b1e8d04079992f0cef
MD5 e81dc02dc0bd06ec392c7bbf690812d4
BLAKE2b-256 75c2df21ec8dcb345bc5f68c143d3a625ae682167027d0acab31d5f3b6464e31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rsbio_seq-0.1.5-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fc10f135a7570f97d791c3bb730ba71c3d9a310e0529d0928c7cef8c8aeca835
MD5 92c53e6274f7829450728eeddb138183
BLAKE2b-256 218b9ed0a99cc04a9e8f2563ca7cf550e190544bdd25802f74759ad41e4cb097

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rsbio_seq-0.1.5-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cacf9cde17e05236d7278ad16d598148e76a62ab669ae2222b052fa92e465427
MD5 091232dda8fc868726ab0265cfb4838a
BLAKE2b-256 bd243c953de910c3fbc94ac6ad1fb0d394c5525a779ef4cdaabf96755e11e90b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rsbio_seq-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9e725b2501ffb5bedfbb58a1b78c7a73294434887bc011d51b61df2c157b513f
MD5 670fcb53a0126f335eb42fed53b783e9
BLAKE2b-256 743d435c61744e807fb4eafcdc34a280352440a0ac931b06094ecc5a89321430

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