Reads BBTools DDL FASTA/FASTQ, including gzip and fused records, or exact DNA lines.
FASTX contributes every valid k-mer window; ambiguity and record boundaries reset it.
124 {
126
127 std::ifstream input(path);
129
130 input >> std::ws;
131 auto const first = input.peek();
132 if (first == '>' || first == '@' || first == 0x1f) {
134 if (!parsed)
return Err(parsed.error());
136 }
137 input.clear();
138 input.seekg(0);
139 std::vector<uint64_t>
keys;
140 std::string line;
141 size_t number = 0;
142
143 while (std::getline(input, line)) {
144 ++number;
145 if (!line.empty() && line.back() == '\r') line.pop_back();
146 if (line.empty()) continue;
147 if (line.size() != k) {
150 "invalid blacklist length at line " + std::to_string(number)
151 )
152 );
153 }
155 for (char base : line) {
157 if (code == 0xffU) {
160 "invalid blacklist base at line " + std::to_string(number)
161 )
162 );
163 }
165 }
167 }
168 if (!input.eof())
return Err(
Error::resource(
"cannot read blacklist: " + path.string()));
170 } catch (std::invalid_argument const& error) {
172 } catch (std::bad_alloc const& error) {
174 }
constexpr uint8_t encode_base(char base) noexcept
Maps one DNA byte to its 2-bit symbol (A=0, C=1, T=2, G=3) or 0xff when invalid.
Result< fasta_parse_result > parse_fasta_file(std::string const &path, uint32_t k, unsigned threads=std::thread::hardware_concurrency())
Parses a FASTA/FASTQ file's sequence bases into packed canonical k-mers of length k.
cuda::std::unexpected< Error > Err(Error error)
Failure return; converts to any Result<T> via cuda::std::unexpected.
static Error invalid_argument(std::string message)
static Error resource(std::string message)