1 #ifndef BTLLIB_SEQ_WRITER_HPP
2 #define BTLLIB_SEQ_WRITER_HPP
4 #include "data_stream.hpp"
25 Format format = FASTA,
30 void write(
const std::string& name,
31 const std::string& comment,
32 const std::string& seq,
33 const std::string& qual);
36 const std::string sink_path;
44 inline SeqWriter::SeqWriter(
const std::string& sink_path,
47 : sink_path(sink_path)
48 , sink(sink_path, append)
51 , headerchar(format == FASTA ?
'>' :
'@')
64 SeqWriter::write(
const std::string& name,
65 const std::string& comment,
66 const std::string& seq,
67 const std::string& qual)
69 check_error(seq.empty(),
"Attempted to write empty sequence.");
70 for (
const auto& c : seq) {
71 if (!
bool(COMPLEMENTS[
unsigned(c)])) {
72 log_error(std::string(
"A sequence contains invalid IUPAC character: ") +
74 std::exit(EXIT_FAILURE);
79 output.reserve(1 + name.size() + 1 + comment.size() + 1 + seq.size() + 3 +
85 if (!comment.empty()) {
94 if (format == FASTQ) {
95 check_error(seq.size() != qual.size(),
96 "Quality must be the same length as sequence.");
103 std::unique_lock<std::mutex> lock(mutex);
104 fwrite(output.c_str(), 1, output.size(), sink);