FASTA/FASTQ parser over a contiguous in-memory buffer.
More...
#include <fastx_buffer_reader.hpp>
FASTA/FASTQ parser over a contiguous in-memory buffer.
Definition at line 112 of file fastx_buffer_reader.hpp.
◆ FastxBufferReader()
| cusbf::detail::FastxBufferReader::FastxBufferReader |
( |
std::string_view |
data, |
|
|
std::string_view |
source_name = "<buffer>" |
|
) |
| |
|
inlineexplicit |
Constructs a reader over a contiguous in-memory FASTA/FASTQ buffer.
- Parameters
-
| data | Entire file or chunk payload. |
| source_name | Label used in parse error messages. |
Definition at line 120 of file fastx_buffer_reader.hpp.
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...
◆ appendNextRecord()
| Result< std::optional< RecordRange > > cusbf::detail::FastxBufferReader::appendNextRecord |
( |
FastxRecord & |
record, |
|
|
std::string & |
sequence, |
|
|
std::string_view & |
buffer |
|
) |
| |
|
inline |
Parses one record with optional zero-copy sequence views for single-line FASTA.
When the sequence fits one mmap line, returns a RecordRange into buffer instead of appending to sequence. Otherwise appends sequence bytes to sequence and returns an owned range offset.
- Parameters
-
| record | Output header (sequence may stay empty on zero-copy path). |
| sequence | Growing buffer for multi-line or owned FASTA sequence data. |
| buffer | Set to the full mmap view on first zero-copy record. |
- Returns
- Record byte range,
std::nullopt at end-of-buffer, or an error.
Definition at line 188 of file fastx_buffer_reader.hpp.
188 {
191
192 const auto header = readHeaderLine();
193 if (!header) {
194 return Err(header.error());
195 }
196 if (header->empty()) {
197 return std::nullopt;
198 }
199
206 } else {
208 parseError(
"expected FASTA or FASTQ header",
fastx_column_at(*header, 0))
209 );
210 }
211 }
212
215 return Err(parseError(
216 "mixed FASTA and FASTQ records are not supported",
fastx_column_at(*header, 0)
217 ));
218 }
219
220 record.header.assign(header->substr(1));
223 const std::string_view line = readLine();
224 if (line.empty()) {
226 }
227 if (!line.empty() && line.front() == '>') {
229 }
230
231 if (position_ < data_.size() && data_[position_] != '>') {
233 sequence.append(line.data(), line.size());
235 return RecordRange{
238 };
239 }
240
243 }
245 }
246
248 CUSBF_TRY(readFastqSequence(sequence, sequence.size()));
249 return RecordRange{
252 };
253 }
std::string_view buffer() const noexcept
Entire mmap or owned buffer backing this reader.
#define CUSBF_TRY(expr)
Propagates a cusbf::Result failure from the enclosing function (GNU statement expression).
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).
@ 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.
◆ buffer()
| std::string_view cusbf::detail::FastxBufferReader::buffer |
( |
| ) |
const |
|
inlinenoexcept |
Entire mmap or owned buffer backing this reader.
Definition at line 171 of file fastx_buffer_reader.hpp.
171 {
172 return data_;
173 }
◆ nextRecord()
Reads the next record into record.
- Parameters
-
| record | Output record, cleared before fill. |
- Returns
false at end-of-buffer, true when a record was read, or an error.
Definition at line 129 of file fastx_buffer_reader.hpp.
129 {
132
133 const auto header = readHeaderLine();
134 if (!header) {
135 return Err(header.error());
136 }
137 if (header->empty()) {
138 return false;
139 }
140
147 } else {
149 parseError(
"expected FASTA or FASTQ header",
fastx_column_at(*header, 0))
150 );
151 }
152 }
153
156 return Err(parseError(
157 "mixed FASTA and FASTQ records are not supported",
fastx_column_at(*header, 0)
158 ));
159 }
160
161 record.header.assign(header->substr(1));
164 } else {
166 }
167 return true;
168 }
The documentation for this class was generated from the following file: