Skip to main content

CI crates.io

Needletail

Needletail is a MIT-licensed, minimal-copying FASTA/FASTQ parser and k-mer processing library for Rust.

The goal is to write a fast and well-tested set of functions that more specialized bioinformatics programs can use. Needletail's goal is to be as fast as the readfq C library at parsing FASTX files and much (i.e. 25 times) faster than equivalent Python implementations at k-mer counting.

Example

extern crate needletail;
use needletail::{parse_fastx_file, Sequence, FastxReader};
//!
fn main() {
    let filename = "tests/data/28S.fasta";
//!
    let mut n_bases = 0;
    let mut n_valid_kmers = 0;
    let mut reader = parse_fastx_file(&filename).expect("valid path/file");
    while let Some(record) = reader.next() {
        let seqrec = record.expect("invalid record");
        // keep track of the total number of bases
        n_bases += seqrec.num_bases();
        // normalize to make sure all the bases are consistently capitalized and
        // that we remove the newlines since this is FASTA
        let norm_seq = seqrec.normalize(false);
        // we make a reverse complemented copy of the sequence first for
        // `canonical_kmers` to draw the complemented sequences from.
        let rc = norm_seq.reverse_complement();
        // now we keep track of the number of AAAAs (or TTTTs via
        // canonicalization) in the file; note we also get the position (i.0;
        // in the event there were `N`-containing kmers that were skipped)
        // and whether the sequence was complemented (i.2) in addition to
        // the canonical kmer (i.1)
        for (_, kmer, _) in norm_seq.canonical_kmers(4, &rc) {
            if kmer == b"AAAA" {
                n_valid_kmers += 1;
            }
        }
    }
    println!("There are {} bases in your file.", n_bases);
    println!("There are {} AAAAs in your file.", n_valid_kmers);
}

Installation

Needletail requires rust and cargo to be installed. Please use either your local package manager (homebrew, apt-get, pacman, etc) or install these via rustup.

Once you have Rust set up, you can include needletail in your Cargo.toml file like:

[dependencies]
needletail = "0.4"

To install needletail itself for development:

git clone https://github.com/onecodex/needletail
cargo test  # to run tests

Python

To work on the Python library on a Mac OS X/Unix system (requires Python 3):

# you need the nightly version of Rust installed
curl https://sh.rustup.rs -sSf | sh
rustup default nightly

# finally, install the library in the local virtualenv
maturin develop --cargo-extra-args="--features=python"

Building binary wheels and pushing to PyPI

# The Mac build requires switching through a few different python versions
maturin build --cargo-extra-args="--features=python" --release --strip

# The linux build is automated through cross-compiling in a docker image
docker run --rm -v $(pwd):/io konstin2/maturin:master build --cargo-extra-args="--features=python" --release --strip
twine upload target/wheels/*

Getting Help

Questions are best directed as GitHub issues. We plan to add more documentation soon, but in the meantime "doc" comments are included in the source.

Contributing

Please do! We're happy to discuss possible additions and/or accept pull requests.

Acknowledgements

Starting from 0.4, the parsers algorithms is taken from seq_io. While it has been slightly modified, it is mainly coming from that library. Links to the original files are available in src/parser/fast{a,q}.rs.

Metadata

Release files for needletail 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for needletail 0.4.0
File Actions
needletail-0.4.0-cp38-cp38-manylinux1_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.5+ x86-64 Details for needletail-0.4.0-cp38-cp38-manylinux1_x86_64.whl
needletail-0.4.0-cp38-cp38-macosx_10_7_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.7+ x86-64 Details for needletail-0.4.0-cp38-cp38-macosx_10_7_x86_64.whl
needletail-0.4.0-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details for needletail-0.4.0-cp37-cp37m-manylinux1_x86_64.whl
needletail-0.4.0-cp37-cp37m-macosx_10_7_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.7+ x86-64 Details for needletail-0.4.0-cp37-cp37m-macosx_10_7_x86_64.whl
needletail-0.4.0-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details for needletail-0.4.0-cp36-cp36m-manylinux1_x86_64.whl
needletail-0.4.0-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details for needletail-0.4.0-cp35-cp35m-manylinux1_x86_64.whl

Total release size: 1.6 MB

Release files / needletail-0.4.0-cp38-cp38-manylinux1_x86_64.whl

Download URL needletail-0.4.0-cp38-cp38-manylinux1_x86_64.whl
Size 280.1 kB
Tags CPython 3.8 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
1d83e16af807f3a1c0ccbb659759a80e99d356e2c506ca8984883a26158b2463
BLAKE2b-256 checksum
How to use checksums
9c859c00f3f111319d034e5b1dd782d69b4b19ffd66a5e9011f6c37d6412404c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / needletail-0.4.0-cp38-cp38-macosx_10_7_x86_64.whl

Download URL needletail-0.4.0-cp38-cp38-macosx_10_7_x86_64.whl
Size 223.2 kB
Tags CPython 3.8 macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
ee109a1e696dc7f34e731f71db57905bb327b7ea207d220c848f3baad8c30e18
BLAKE2b-256 checksum
How to use checksums
c0f4654c8a600879d76adb559e6cd450b37ecd27cb768154ec254d68bbb850c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / needletail-0.4.0-cp37-cp37m-manylinux1_x86_64.whl

Download URL needletail-0.4.0-cp37-cp37m-manylinux1_x86_64.whl
Size 280.1 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
4432d30f249b3f4707660c15383fde523b4ae5ce1d187e0aeeb667ef705081f7
BLAKE2b-256 checksum
How to use checksums
cb8358f4ba3294db97f8d36e8af27e3b860ae3dd1d703feb376e36b56a6f1059
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / needletail-0.4.0-cp37-cp37m-macosx_10_7_x86_64.whl

Download URL needletail-0.4.0-cp37-cp37m-macosx_10_7_x86_64.whl
Size 223.2 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
aa23a9df7e215b5ebb46f51e35008aacda2bdf67a9c405be1fa1199a536b28a3
BLAKE2b-256 checksum
How to use checksums
1f984efc9f8e44082049f9ab5134e4b488ae6d5cc3a71b1d0979d2fcb67170f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / needletail-0.4.0-cp36-cp36m-manylinux1_x86_64.whl

Download URL needletail-0.4.0-cp36-cp36m-manylinux1_x86_64.whl
Size 280.4 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
c681c0463ba8347dca58f481287698a2fe39cac88c7635780f2bc3d1688e11a6
BLAKE2b-256 checksum
How to use checksums
a5d11f7fb0f7bbefab66c092e6e665a669f189f1b5c9611725c09c449331e055
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / needletail-0.4.0-cp35-cp35m-manylinux1_x86_64.whl

Download URL needletail-0.4.0-cp35-cp35m-manylinux1_x86_64.whl
Size 280.1 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
399b0c18b6ac655b1254043ecf6cbcdf1cc1b40c50fa55a6613b1b0088b0c05d
BLAKE2b-256 checksum
How to use checksums
20a0519837b6429c9f8e154589bebd3c92f85a3ecb7f2fbf26e49593b1598797
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Security for needletail 0.4.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page