github.com/bio-cr/fastx.cr
0.3.0 / published Jun 26, 2026 / repository
FASTA/FASTQ reader and writer for Crystal.
Fastx.cr
Small FASTA/FASTQ I/O for Crystal.
Installation
Add this to shard.yml:
dependencies:
fastx:
github: bio-cr/fastx.cr
Then run:
shards install
Features
- Read and write FASTA
- Read and write FASTQ
- Auto-handle gzip when the path ends with
.gz - Iterate with owned
Stringvalues or lower-allocation borrowedBytes - Stream large records line by line without accumulating full sequences
- Encode/decode nucleotide bases and FASTQ quality scores
Quick Start
Read FASTA:
require "fastx"
Fastx::Fasta::Reader.open("reads.fa.gz") do |reader|
reader.each do |header, sequence|
puts "#{header}\t#{sequence.bytesize}"
end
end
Read FASTQ:
Fastx::Fastq::Reader.open("reads.fq.gz") do |reader|
reader.each do |identifier, sequence, quality|
puts "#{identifier}\t#{sequence.bytesize}\t#{quality.bytesize}"
end
end
Write FASTA:
Fastx::Fasta::Writer.open("out.fa", line_width: 80) do |writer|
writer.write("seq1", "ACGTACGT")
end
Write FASTQ:
Fastx::Fastq::Writer.open("out.fq.gz") do |writer|
writer.write("seq1", "ACGT", "!!!!")
end
Guides
- Getting started
- Reading FASTA and FASTQ
- Writing FASTA and FASTQ
- Streams and limits
- Base and quality encoding
License
MIT License