d4.cr
d4.cr
A pure Crystal reader and writer for D4 genomic data files. No Rust runtime or d4binding library is required.
Install
Add this shard to shard.yml, then run shards install:
dependencies:
d4:
github: kojix2/d4.cr
Requires Crystal 1.21 or later.
Usage
require "d4"
D4.create("depth.d4", chromosomes: [D4::Chromosome.new("chr1", 1000_i64)],
dictionary: D4::Dictionary.new(0_i32, 8_i32)) do |writer|
writer.write_values("chr1", 0, [1_i32, 2_i32, 3_i32])
end
D4.open("depth.d4") do |file|
p file.values("chr1", 0, 3) # => [1, 2, 3]
p file.sum("chr1", 0, 3) # => 6
end
The reader supports multiple tracks, embedded indexes, and raw or DEFLATE secondary data. The writer creates one track. HTTP range reading is available with require "d4/http".
Long writes and index construction support progress reporting and cooperative cancellation. Output is published only after finalization succeeds:
control = D4::WriteControl.new { |progress| puts progress }
D4.create("depth.d4", chromosomes: chromosomes, control: control) do |writer|
writer.write_values("chr1", 0, values)
end
# Another fiber or thread may call control.cancel.
The same control can be passed to D4.writer, D4.build_indexes, or directly to D4::Writer and D4::IndexBuilder.
A GUI coverage viewer is available in the d4-plot repository.
Development
crystal spec --single-module
crystal tool format --check src spec
License
MIT. See LICENSE. Rust-generated test fixtures retain the upstream notice in THIRD_PARTY_NOTICES.md.
d4.cr
- 0
- 0
- 0
- 2
- 0
- about 1 hour ago
- October 10, 2026
MIT License
Thu, 15 Oct 2026 03:16:09 GMT