FASTQ¶
Support reading and writing fastq files 🔗.
All classes/functions are available in the ivio::fastq
namespace.
Record and RecordView (record
, record_view
)¶
IVio provides the datastructures ivio::fastq::record
and ivio::fastq::record_view
. These are the typical input/output arguments of the readers and writers.
These datastructures convertible to each other.
The record_view
layout
struct record_view {
std::string_view id;
std::string_view seq;
std::string_view id2;
std::string_view qual;
};
record
layout
struct record {
std::string id;
std::string seq;
std::string id2;
std::string qual;
};
Reader (reader
, reader::config
)¶
The ivio::fastq::reader
accepts a ivio::fastq::reader::config
object for initialization. It initializes an object
that enables you to iterate over the records of a file. It is is for-range compatible, meaning it fulfills c++ concepts of range and LegacyInputIterator.
When looping over a reader it returns record_view
objects that are only valid until next record is being requested from the reader.
To get ownership of the data, it is required to create an object of type record
.
To configure the reader
one must fill the ivio::fastq::reader::config
struct which declares the input file and if gzip compression is expected.
struct ivio::fastq::reader::config {
// Source: file or stream
std::variant<std::filesystem::path, std::reference_wrapper<std::istream>> input;
// This is only relevant if a stream is being used
bool compressed{};
};
Overview of the member functions of ivio::fastq::reader
struct ivio::fastq::reader {
/*...*/
auto next() -> std::optional<record_view>; // reads the next record
void close() const; // closes the read file
};
Examples¶
Example - Reading record by record¶
In this example a file is being opened and print to command line
#include <iostream>
#include <ivio/ivio.h>
int main(int /*argc*/, char** argv) {
auto inputFile = std::filesystem::path{argv[1]};
auto reader = ivio::fastq::reader{{.input = inputFile}};
for (auto record_view : reader) {
std::cout << "id: " << record_view.id << "\n";
std::cout << "seq: " << record_view.seq << "\n";
std::cout << "id2: " << record_view.id2 << "\n";
std::cout << "qual: " << record_view.qual << "\n";
}
}
id: Seq1
seq: ACGT
id2:
qual: !!!!
id: Seq2
seq: NNNN
id2:
qual: !!!!