btllib: include/btllib/seq_reader_gfa2_module.hpp Source File

btllib

Loading...
Searching...
No Matches
seq_reader_gfa2_module.hpp
1#ifndef BTLLIB_SEQ_READER_GFA2_MODULE_HPP
2#define BTLLIB_SEQ_READER_GFA2_MODULE_HPP
3
4#include "btllib/cstring.hpp"
5#include "btllib/status.hpp"
6
7#include <cstdlib>
8
9namespace btllib {
10
12class SeqReaderGfa2Module
13{
14
15private:
16 friend class SeqReader;
17
18 enum class Stage
19 {
20 HEADER,
21 SEQ,
22 SEP,
23 QUAL
24 };
25
26 Stage stage = Stage::HEADER;
27 CString tmp;
28
29 static bool buffer_valid(const char* buffer, size_t size);
30 template<typename ReaderType, typename RecordType>
31 bool read_buffer(ReaderType& reader, RecordType& record);
32 template<typename ReaderType, typename RecordType>
33 bool read_transition(ReaderType& reader, RecordType& record);
34 template<typename ReaderType, typename RecordType>
35 bool read_file(ReaderType& reader, RecordType& record);
36};
37
38// NOLINTNEXTLINE
39#define READ_GFA2(READLINE_SECTION, MIDEND_SECTION, END_SECTION) \
40 enum Column \
41 { \
42 S = 1, \
43 ID, \
44 LEN, \
45 SEQ \
46 }; \
47 for (;;) { \
48 READLINE_SECTION \
49 std::string tmp_string(tmp); \
50 if (tmp_string.length() > 0 && tmp_string[0] == 'S') { \
51 size_t pos = 0, pos2 = 0; \
52 pos2 = tmp_string.find('\t', 1); \
53 if (tmp_string.size() + 1 > record.header.s_cap) { \
54 record.header.change_cap(tmp_string.size() + 1); \
55 } \
56 record.header = tmp_string.substr(1, pos2 - 1); \
57 for (int i = 0; i < int(SEQ) - 1; i++) { \
58 pos = tmp_string.find('\t', pos + 1); \
59 } \
60 pos2 = tmp_string.find('\t', pos + 1); \
61 if (pos2 == std::string::npos) { \
62 pos2 = tmp_string.length(); \
63 } \
64 if (tmp_string.size() + 1 > record.seq.s_cap) { \
65 record.seq.change_cap(tmp_string.size() + 1); \
66 } \
67 record.seq = tmp_string.substr(pos + 1, pos2 - pos - 1); \
68 MIDEND_SECTION \
69 } \
70 tmp.clear(); \
71 END_SECTION \
72 }
73
74template<typename ReaderType, typename RecordType>
75inline bool
76SeqReaderGfa2Module::read_buffer(ReaderType& reader, RecordType& record)
77{
78 log_error("GFA2 files are unsupported right now.");
79 std::exit(EXIT_FAILURE); // NOLINT
80 (void)reader;
81 (void)record;
82 return false;
83 /*
84 READ_GFA2( // NOLINT
85 if (!reader.readline_buffer_append( // NOLINT
86 tmp)) { return false; }, // NOLINT
87 tmp.clear(); // NOLINT
88 return true; // NOLINT
89 , if (reader.buffer.start >= reader.buffer.end) { return false; }) // NOLINT
90 return false;
91 */
92}
93
94template<typename ReaderType, typename RecordType>
95inline bool
96SeqReaderGfa2Module::read_transition(ReaderType& reader, RecordType& record)
97{
98 (void)reader;
99 (void)record;
100 return false;
101 /*
102 READ_GFA2( // NOLINT
103 reader.readline_file_append(tmp); // NOLINT
104 , , if (bool(feof(reader.source))) { break; }) // NOLINT
105 */
106}
107
108template<typename ReaderType, typename RecordType>
109inline bool
110SeqReaderGfa2Module::read_file(ReaderType& reader, RecordType& record)
111{
112 (void)reader;
113 (void)record;
114 return false;
115 /*
116 READ_GFA2( // NOLINT
117 reader.readline_file(tmp); // NOLINT
118 , , if (bool(feof(reader.source))) { break; }) // NOLINT
119 */
120}
122
123} // namespace btllib
124
125#endif
btllib
Definition: aahash.hpp:15
btllib::log_error
void log_error(const std::string &msg)