Package: gb-io
🧬🏦gb-io.pyA Python interface togb-io, a fastGenBankparser written inRust.🗺️ Overviewgb-io.pyis a Python package that provides an interface togb-io, a very
fast GenBank format parser implemented in Rust. It can reach much higher
speed than theBiopythonor
thescikit-bioparsers.This library has no external dependency and is available for all modern Python
versions (3.7+).🔧 InstallingInstall thegb-iopackage directly fromPyPiwhich hosts pre-compiled wheels that can be installed withpip:$pipinstallgb-ioWheels are provided for the following platforms:Linux, CPython, x86-64Linux, CPython, Aarch64MacOS, CPython, x86-64MacOS, PyPy, x86-64Windows, CPython, x86-64Windows, PyPy, x86-64Otherwise, 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.💡 UsageUse thegb_io.loadfunction 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:withopen("tests/data/AY048670.1.gb")asfile: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 thegb_io.itermethod, which returns an iterator instead of a list:forrecordingb_io.iter("tests/data/AY048670.1.gb"):print(record.name,record.sequence[:10])You can use thegb_io.dumpmethod to write one or more records to a file
(either given as a path, or a file-like handle):withopen("tests/data/AY048670.1.gb","wb")asfile:gb_io.dump(records,file)📝 ExampleThe following small script will extract all the CDS features from a GenBank
file, and write them in FASTA format to an output file:importgb_iowithopen("tests/data/AY048670.1.faa","w")asdst:forrecordingb_io.iter("tests/data/AY048670.1.gb"):forfeatureinfilter(lambdafeat: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 usingBio.SeqIO.parse,Bio.GenBank.parseandBio.GenBank.Scanner.GenBankScanner.parse_cds_features, the performance is
the following:gb_io.iterGenBankScannerGenBank.parseSeqIO.parseTime (s)2.2647.98215.25919.351Speed (MiB/s)136.537.120.516.2Speedupx8.55x2.42x1.27-💭 Feedback⚠️ Issue TrackerFound a bug ? Have an enhancement request ? Head over to theGitHub issue
trackerif 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.🏗️ ContributingContributions are more than welcome! SeeCONTRIBUTING.mdfor more details.⚖️ LicenseThis library is provided under theMIT License.
Thegb-ioRust crate package was written byDavid Leslieand is licensed under the terms of theMIT License.
This package vendors the source of several additional packages that are
licensed under theApache-2.0,MITorBSD-3-Clauselicenses;
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 theoriginalgb-ioauthors. It was developed
byMartin Larraldeduring his PhD project
at theEuropean Molecular Biology Laboratoryin
theZeller team.