hts
Version, currently 0.0.310 versions
github.com/bio-cr/hts.cr
HTSlib bindings for Crystal
14 stars
3 dependents
License: MIT
Nothing has been indexed for 0.0.3 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
hts:
github: bio-cr/hts.cr
version: ~> 0.0.3Then run:
shards installshard.yml
No shard.yml has been indexed for 0.0.3. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
# HTS.cr
[](https://github.com/bio-cr/hts.cr/actions/workflows/ci.yml)
[](https://bio-crystal.slack.com/)
[](https://bio-cr.github.io/hts.cr/)
[](https://deepwiki.com/bio-cr/hts.cr)
[](https://tokei.kojix2.net/github/bio-cr/hts.cr)
[](https://doi.org/10.5281/zenodo.6462533)
HTS.cr provides [Crystal](https://github.com/crystal-lang/crystal) bindings for [HTSlib](https://github.com/samtools/htslib) that allow you to read and write file formats commonly used in genomics, such as [SAM, BAM, VCF, and BCF](http://samtools.github.io/hts-specs/).
## Requirements
- [Crystal](https://crystal-lang.org)
- [HTSlib](https://github.com/samtools/htslib)
- Ubuntu : `apt install libhts-dev`
- macOS : `brew install htslib`
- Any OS : Build from [source code](https://github.com/samtools/htslib)
- Make sure that `pkg-config` can detect htslib: `pkg-config --libs htslib`
## Installation
Add hts to your `shard.yml`:
```yaml
dependencies:
hts:
github: bio-cr/hts.cr
branch: develop
```
Run `shards install`
## Usage
Read SAM / BAM / CRAM
```crystal
require "hts/bam"
HTS::Bam.open(bam_path) do |bam|
bam.each do |r|
tags = r.aux
p name: r.qname,
chrom: r.chrom,
start: r.pos + 1,
cigar: r.cigar.to_s,
seq: r.seq,
qual: r.qual_string,
nm: tags.get_int("NM"),
mc: tags.get_string("MC")
end
end
```
Read VCF / BCF
```crystal
require "hts/bcf"
HTS::Bcf.open(bcf_path) do |bcf|
bcf.each do |r|
p chrom: r.chrom,
pos: r.pos + 1,
id: r.id,
qual: r.qual,
filter: r.filter,
ref: r.ref,
alt: r.alt,
info_dp: r.info.get_int("DP"),
genotypes: r.format.get_string("GT")
end
end
```
## API Overview
- High level API - Classes include Bam, Bcf, Tabix, Faidx, etc.
- LibHTS - Native C bindings to HTSLib
- For more information, please see [API documentation](https://bio-cr.github.io/hts.cr/).
```
┌──────────────────── HTS ────────────────────┐
│ │
│ ┌─ Bam ────────┬─ Bcf ───────┬─ Tabix ────┐ │
│ │ SAM BAM CRAM │ VCF BCF │ TABIX │ │
│ └──────────────┴─────────────┴────────────┘ │
│ ┌─LibHTS2───────────┐ │
│ ┌─LibHTS────────────┤ Macro functions ├─┐ │
│ │ Native C bindings └───────────────────┘ │ │
│ └─────────────────────────────────────────┘ │
└─────────────────────────────────────────────┘
```
LibHTS2: Since methods cannot be added to `Lib` in the Crystal language, macro functions are implemented in the LibHTS2 module. This is different from Ruby-htslib.
## Looking for flexibility?
The Crystal language is suited for creating efficient command-line tools. The Ruby language, on the other hand, is suited for exploratory analysis.
- [ruby-htslib](https://github.com/kojix2/ruby-htslib)
## Contributing
:rocket: Feel free to fork it!
git clone https://github.com/bio-cr/hts.cr
cd hts.cr
crystal spec
Bug reports and pull requests are welcome.
## Benchmark
https://github.com/brentp/vcf-bench
code: https://github.com/kojix2/vcf-bench/blob/kojix2/crystal-htslib/read.cr
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.0.3- Tagged
- Aug 1, 2026
- Commit
7b090186a224- Indexed
- not yet
Dependents
Repository
github.com/bio-cr/hts.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 10