The Nim FASTA/FASTQ parsing library for SeqFu.
nimble install readfximport readfx
# Using the C wrapper (klib)
for record in readFQ("example.fastq"):
echo record.name, ": ", record.sequence.len
# Using pointer-based version (more efficient, reuses memory)
for record in readFQPtr("example.fastq.gz"):
echo $record.name, ": ", record.sequenceLen
# Using the native Nim implementation
var r: FQRecord
var f = xopen[GzFile]("example.fastq.gz")
defer: f.close()
while f.readFastx(r):
echo r.name, ": ", r.sequence.len
# Reading paired-end FASTQ files
for pair in readFQPair("sample_R1.fastq.gz", "sample_R2.fastq.gz"):
echo "R1: ", pair.read1.name, " (", pair.read1.sequence.len, " bp)"
echo "R2: ", pair.read2.name, " (", pair.read2.sequence.len, " bp)"
# Pointer-based paired-end iteration (zero-copy, pointers are reused)
for pair in readFQPairPtr("sample_R1.fastq.gz", "sample_R2.fastq.gz"):
echo "Pair length: ", pair.read1.sequenceLen + pair.read2.sequenceLen
# Pointer-based interleaved paired-end iteration
for pair in readFQInterleavedPairPtr("sample.interleaved.fastq.gz", checkNames = true):
echo "Pair length: ", pair.read1.sequenceLen + pair.read2.sequenceLenFQRecordPtr now includes cached nameLen, commentLen, sequenceLen, and
qualityLen fields. These lengths exclude the trailing NUL terminator and
avoid repeated cstring scans in pointer-heavy code. Because FQRecordPtr
layout changed, downstream projects must be recompiled after upgrading to this
release.
- Original library by Heng Li (kseq.h) and Andreas Wilm (readfq)
- Updated and maintained by Andrea Telatin and the Quadram Institute Bioscience Core Bioinformatics team
- Co-authored by Claude code