cuSBF
Loading...
Searching...
No Matches
Public Member Functions | List of all members
cusbf::detail::FastxReader Class Reference

Streaming FASTA/FASTQ parser. More...

#include <Fastx.hpp>

Public Member Functions

 FastxReader (std::istream &input, std::string_view source_name="<stream>")
 Constructs a reader over an open input stream.
 
Result< boolnextRecord (FastxRecord &record)
 Reads the next FASTA/FASTQ record into record.
 

Detailed Description

Streaming FASTA/FASTQ parser.

Reads one record at a time via nextRecord. Errors reading the stream are returned as error results.

Definition at line 297 of file Fastx.hpp.

Constructor & Destructor Documentation

◆ FastxReader()

cusbf::detail::FastxReader::FastxReader ( std::istream &  input,
std::string_view  source_name = "<stream>" 
)
inlineexplicit

Constructs a reader over an open input stream.

Parameters
inputInput stream positioned at the first record.
source_nameLabel used in parse error messages.

Definition at line 305 of file Fastx.hpp.

306 : input_(input), source_name_(source_name) {}
consteval bool separatorPositionAlwaysEncodesInvalid(char *input, uint64_t separatorPosition, uint64_t index)
Recursively tests whether placing the separator byte at any position in an input of valid bytes alway...
Definition Alphabet.cuh:37

Member Function Documentation

◆ nextRecord()

Result< bool > cusbf::detail::FastxReader::nextRecord ( FastxRecord record)
inline

Reads the next FASTA/FASTQ record into record.

Parameters
recordOutput record, cleared before fill.
Returns
false at end-of-stream, true when a record was read, or an error.

Definition at line 314 of file Fastx.hpp.

314 {
315 record.header.clear();
316 record.sequence.clear();
317
318 const auto header = readHeaderLine();
319 if (!header) {
320 return Err(header.error());
321 }
322 if (header->empty()) {
323 return false;
324 }
325
326 const char headerTag = header->front();
327
328 if (format_ == FastxFormat::unknown) {
329 if (headerTag == '>') {
330 format_ = FastxFormat::fasta;
331 } else if (headerTag == '@') {
332 format_ = FastxFormat::fastq;
333 } else {
334 return Err(
335 parseError("expected FASTA or FASTQ header", fastx_column_at(*header, 0))
336 );
337 }
338 }
339
340 const char expectedHeader = format_ == FastxFormat::fasta ? '>' : '@';
341 if (headerTag != expectedHeader) {
342 return Err(parseError(
343 "mixed FASTA and FASTQ records are not supported", fastx_column_at(*header, 0)
344 ));
345 }
346
347 record.header.assign(header->substr(1));
348 if (format_ == FastxFormat::fasta) {
349 CUSBF_TRY(readFastaSequence(record.sequence));
350 } else {
351 CUSBF_TRY(readFastqSequence(record.sequence));
352 }
353 return true;
354 }
#define CUSBF_TRY(expr)
Propagates a cusbf::Result failure from the enclosing function (GNU statement expression).
Definition error.hpp:246
uint32_t fastx_column_at(std::string_view line, size_t byte_index)
1-based column at byte_index within line (clamped to the line end).
Definition Fastx.hpp:268
@ fasta
FASTA (> headers).
@ fastq
FASTQ (@ headers).
@ unknown
Format not yet determined from the first header.
cuda::std::unexpected< Error > Err(Error error)
Failure return; converts to any Result<T> via cuda::std::unexpected.
Definition error.hpp:219
Here is the call graph for this function:

The documentation for this class was generated from the following file: