Skip to main content

A Python interface to gb-io, a fast GenBank parser written in Rust.

Project description

🧬🏦 gb-io.py Stars

A Python interface to gb-io, a fast GenBank parser written in Rust.

Actions Coverage License PyPI Wheel Python Versions Python Implementations Source Mirror GitHub issues

🗺️ Overview

gb-io.py is a Python package that provides an interface to gb-io, a very fast GenBank format parser implemented in Rust. It can reach much higher speed than the Biopython or the scikit-bio parsers.

This library has no external dependency and is available for all modern Python versions (3.7+).

🔧 Installing

Install the gb-io package directly from PyPi which hosts pre-compiled wheels that can be installed with pip:

$ pip install gb-io

Wheels are provided for the following platforms:

  • Linux, CPython, x86-64
  • Linux, PyPy, x86-64
  • Linux, CPython, Aarch64
  • MacOS, CPython, x86-64
  • MacOS, PyPy, x86-64

Otherwise, the source distribution will be downloaded, and a local copy of the Rust compiler will be downloaded to build the package, unless it is already installed on the host machine.

💡 Usage

Use the gb_io.load function to obtain a list of all GenBank records in a file:

records = gb_io.load("tests/data/AY048670.1.gb")

Reading from a file-like object is supported as well, both in text and binary mode:

with open("tests/data/AY048670.1.gb") as file:
    records = gb_io.load(file)

It is also possible to iterate over each record in the file without having to load the entirety of the file contents to memory with the gb_io.iter method, which returns an iterator instead of a list:

for record in gb_io.iter("tests/data/AY048670.1.gb"):
    print(record.name, record.sequence[:10])

📝 Example

The following small script will extract all the CDS features from a GenBank file, and write them in FASTA format to an output file:

import gb_io

with open("tests/data/AY048670.1.faa", "w") as dst:
    for record in gb_io.iter("tests/data/AY048670.1.gb"):
        for feature in filter(lambda feat: feat.type == "CDS", record.features):
            qualifiers = feature.qualifiers.to_dict()
            dst.write(">{}\n".format(qualifiers["locus_tag"][0]))
            dst.write("{}\n".format(qualifiers["translation"][0]))

Compared to similar implementations using Bio.SeqIO.parse, Bio.GenBank.parse and Bio.GenBank.Scanner.GenBankScanner.parse_cds_features, the performance is the following:

gb_io.iter GenBankScanner GenBank.parse SeqIO.parse
Time (s) 2.264 7.982 15.259 19.351
Speed (MiB/s) 136.5 37.1 20.5 16.2
Speedup x8.55 x2.42 x1.27 -

💭 Feedback

⚠️ Issue Tracker

Found a bug ? Have an enhancement request ? Head over to the GitHub issue tracker if you need to report or ask something. If you are filing in on a bug, please include as much information as you can about the issue, and try to recreate the same bug in a simple, easily reproducible situation.

🏗️ Contributing

Contributions are more than welcome! See CONTRIBUTING.md for more details.

⚖️ License

This library is provided under the MIT License. The gb-io Rust crate package was written by David Leslie and is licensed under the terms of the MIT License. This package vendors the source of several additional packages that are licensed under the Apache-2.0, MIT or BSD-3-Clause licenses; see the license file distributed with the source copy of each vendored dependency for more information.

This project is in no way not affiliated, sponsored, or otherwise endorsed by the original gb-io authors. It was developed by Martin Larralde during his PhD project at the European Molecular Biology Laboratory in the Zeller team.

Project details


Download files

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

Source Distribution

gb-io-0.1.0.tar.gz (11.2 MB view hashes)

Uploaded Source

Built Distributions

gb_io-0.1.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (312.5 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

gb_io-0.1.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (312.1 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

gb_io-0.1.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (312.1 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

gb_io-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (348.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

gb_io-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (344.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

gb_io-0.1.0-cp310-cp310-macosx_10_15_x86_64.whl (312.2 kB view hashes)

Uploaded CPython 3.10 macOS 10.15+ x86-64

gb_io-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (348.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

gb_io-0.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (344.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

gb_io-0.1.0-cp39-cp39-macosx_10_15_x86_64.whl (312.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.15+ x86-64

gb_io-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (348.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

gb_io-0.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (344.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

gb_io-0.1.0-cp38-cp38-macosx_10_14_x86_64.whl (311.8 kB view hashes)

Uploaded CPython 3.8 macOS 10.14+ x86-64

gb_io-0.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (348.2 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

gb_io-0.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (344.5 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

gb_io-0.1.0-cp37-cp37m-macosx_10_14_x86_64.whl (311.8 kB view hashes)

Uploaded CPython 3.7m macOS 10.14+ x86-64

Supported by

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