Skip to content

IO Module API

Namespace: fq::io


FastqRecord

Zero-copy view of FASTQ record, using std::string_view pointing to continuous memory in FastqBatch.

Fields

FieldTypeDescription
idstd::string_viewRecord identifier
sequencestd::string_viewDNA sequence
qualitystd::string_viewQuality score string
separatorstd::string_viewSeparator line (usually +)

Key Methods

cpp
auto averageQuality(int qualityEncoding = 33) const -> double;
auto length() const -> size_t;
auto gcContent() const -> double;
auto nRatio() const -> double;

FastqBatch

Container for batch storage of multiple FASTQ records, maintaining continuous memory buffer.

Key Methods

cpp
auto records() const -> const std::vector<FastqRecord>&;
auto size() const -> size_t;
auto empty() const -> bool;
void clear();
void reserve(size_t count);

Memory Model

FastqBatch
├── buffer_     Continuous memory block (stores raw text)
└── records_    FastqRecord array (string_view points to buffer_)

FastqReader

FASTQ file reader, supports plain text and gzip compressed formats.

Construction and Usage

cpp
fq::io::FastqReader reader("input.fastq.gz");

fq::io::FastqBatch batch;
while (reader.nextBatch(batch, 10000)) {
    for (const auto& record : batch.records()) {
        // Process each record
    }
}

Key Methods

cpp
explicit FastqReader(const std::string& path);
auto nextBatch(FastqBatch& batch, size_t batchSize = 10000) -> bool;
auto isOpen() const -> bool;

Performance Parameters

ParameterDescription
readChunkBytesBytes to read each time
zlibBufferByteszlib decompression buffer size
maxBufferBytesMaximum buffer limit

FastqWriter

FASTQ file writer, supports plain text and gzip compressed output.

Construction and Usage

cpp
fq::io::FastqWriter writer("output.fastq.gz");

for (const auto& record : batch.records()) {
    writer.write(record);
}

Performance Parameters

ParameterDescription
zlibBufferBytesCompression buffer size
outputBufferBytesOutput buffer size

FastqBatchPool

Object pool based on ObjectPool<FastqBatch>, reducing frequent allocations in TBB pipeline.

cpp
auto pool = fq::io::createFastqBatchPool(initialSize, maxSize);
auto batch = pool->acquire();  // Acquire from pool
// shared_ptr destructor automatically returns to pool

MIT License © LessUp