Coder Social home page Coder Social logo

bsaintjo / slow5-rs Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 0.0 1010 KB

Low level bindings and wrapper for slow5lib, an alternative for ONT Nanopore sequencing FAST5 output

License: Apache License 2.0

Rust 100.00%
ffi nanopore-sequencing rust fast5 genomics nanopore oxford oxford-nanopore bioinformatics compbio

slow5-rs's Introduction

slow5-rs

License Crates.io docs.rs Rust stable codecov

A library for interacting with SLOW5/BLOW5 files in the Rust programming language.

For more information check out the main slow5lib repository or the paper.

This repository provides two crates:

  • slow5lib-sys: Bindings to the C library using bindgen
  • slow5: Rust API built on-top of slow5lib-sys

The interface for slow5 is largely stable and now updated primarily to follow new versions slow5lib. If there is additional functionality you'd like to see, please file a Github Issue.

Installation

Add the following to your Cargo.toml:

[dependencies]
slow5 = "0.11"

Git

If you'd like to download the git version, use the following command to download the repo

git clone --recursive https://github.com/bsaintjo/slow5-rs.git

Getting started

Reading signal from SLOW5 file

use slow5::{FileReader, RecordExt};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut slow5 = FileReader::open("examples/example.slow5").unwrap();
    for record in slow5.records() {
        for signal in record?.picoamps_signal_iter() {
            // Do stuff
        }
    }
    Ok(())
}

Writing a compressed BLOW5 file with attributes

use std::error::Error;
use slow5::{FileWriter, SignalCompression, Record};

fn main() -> Result<(), Box<dyn Error>> {
    let tmp_dir = std::env::temp_dir();
    let output = tmp_dir.join("test.blow5");
    let mut writer = FileWriter::options()
        .signal_compression(SignalCompression::StreamVByte)
        .attr("attribute", "value", 0)
        .create(output)?;
    let rec = Record::builder()
        .read_id("test_id")
        .read_group(0)
        .digitisation(4096.0)
        .offset(4.0)
        .range(12.0)
        .sampling_rate(4000.0)
        .raw_signal(&[0, 1, 2, 3])
        .build()?;
    writer.add_record(&rec)?;
    writer.close();
    Ok(())
}

More example code

For more example code, see the test code. Several examples from the original library have been ported to rust and can be found in the examples directory.

Feature flags

  • zstd: Enable zstd-based compression
    • enabled by default
  • zlib-ng: Enable usage of high performance zlib-ng
    • adds cmake dependency
  • serde: Enable serde dependency
    • Mainly for serializing Record into serde-compatible formats

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

slow5-rs's People

Contributors

bsaintjo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

slow5-rs's Issues

Not an issue

Hey,

Just saw this repo by chance and I am glad you are working on a rust API for slow5. @Psy-Fer in our team will be very much interested as he is turning away from Python to Rust recently. If you want any help with understanding slow5lib side, feel free to ping me, will be glad to help to make your rust API full-fledged.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.