ruby-htslib

Gem Version CI The MIT License DOI Docs Stable

:dna: HTSlib - high-throughput sequencing data manipulation - for Ruby

:apple: Feel free to fork it out if you can develop it!

:bowtie: alpha stage.

Requirements

  • htslib
    • Ubuntu : apt install libhts-dev
    • macOS : brew install htslib

Installation

gem install htslib

If you installed htslib with Ubuntu/apt or Mac/homebrew, pkg-config will automatically detect the location of the shared library.

Or you can set the environment variable HTSLIBDIR.

export HTSLIBDIR="/your/path/to/htslib" # libhts.so

Usage

Low level API

HTS::LibHTS

require 'htslib'

a = HTS::LibHTS.hts_open("a.bam", "r")
b = HTS::LibHTS.hts_get_format(a)
p b[:category]
p b[:format]

Note: Managed struct is not used in ruby-htslib. You may need to free the memory by yourself.

High level API

A high-level API based on hts-python or hts-nim is under development. We will change and improve the API to make it better.

require 'htslib'

bam = HTS::Bam.new("a.bam")

bam.each do |r|
  p name:  r.qname,
    flag:  r.flag,
    start: r.start + 1,
    mpos:  r.mate_pos + 1,
    mqual: r.mapping_quality,
    seq:   r.sequence,
    cigar: r.cigar.to_s,
    qual:  r.base_qualities.map { |i| (i + 33).chr }.join
end

Documentation

Development

To get started with development

git clone --recursive https://github.com/kojix2/ruby-htslib
cd ruby-htslib
bundle install
bundle exec rake htslib:build
bundle exec rake test

c2ffi : I am trying to find a way to automatically generate a low-level API using c2ffi.

Contributing

Ruby-htslib is a library under development, so even small improvements like typofix are welcome! Please feel free to send us your pull requests.

License

MIT License.