-
Notifications
You must be signed in to change notification settings - Fork 3
/
formats.h
215 lines (159 loc) · 6.58 KB
/
formats.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
Copyright (c) 2015 Genome Research Ltd.
Author: Jouni Siren <jouni.siren@iki.fi>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _BWTMERGE_FORMATS_H
#define _BWTMERGE_FORMATS_H
#include "support.h"
namespace bwtmerge
{
//------------------------------------------------------------------------------
enum AlphabeticOrder { AO_DEFAULT = 0, AO_SORTED = 1, AO_ANY = 254, AO_UNKNOWN = 255 };
Alphabet createAlphabet(AlphabeticOrder order);
AlphabeticOrder identifyAlphabet(const Alphabet& alpha);
std::string alphabetName(AlphabeticOrder order);
bool compatible(const Alphabet& alpha, AlphabeticOrder order);
//------------------------------------------------------------------------------
struct NativeHeader
{
uint32_t tag;
uint32_t flags;
uint64_t sequences;
uint64_t bases;
const static uint32_t DEFAULT_TAG = 0x54574221;
const static uint32_t ALPHABET_MASK = 0xFF;
NativeHeader();
size_type serialize(std::ostream& out, sdsl::structure_tree_node* v = nullptr, std::string name = "") const;
void load(std::istream& in);
bool check() const;
AlphabeticOrder order() const;
void setOrder(AlphabeticOrder ao);
};
std::ostream& operator<<(std::ostream& stream, const NativeHeader& header);
//------------------------------------------------------------------------------
/*
BWT file formats. Note that BWT formats are only compatible with those having the
same alphabetic order.
load() reads the BWT from 'in' and stores it in the native format in 'data'
write() writes the BWT stored in the native format in 'data' to 'out'
order() returns the alphabetic order
name meaningful name of the format
tag the name used for specifying the format
NativeFormat Native BWT format; any alphabetic order
PlainFormatD BWT as a character array; AO_DEFAULT
PlainFormatS BWT as a character array; AO_SORTED
RFMFormat BWT as int_vector<8> of comp values; AO_SORTED
SDSLFormat BWT as int_vector<8> of characters; AO_SORTED
RopeFormat RopeBWT; AO_DEFAULT
SGAFormat SGA assembler; AO_DEFAULT
*/
struct NativeFormat
{
inline static AlphabeticOrder order() { return AO_ANY; }
const static std::string name;
const static std::string tag;
};
struct PlainFormatD
{
static void read(std::ifstream& in, BlockArray& data, sdsl::int_vector<64>& counts);
static void write(std::ofstream& out, const BlockArray& data, const NativeHeader&);
inline static AlphabeticOrder order() { return AO_DEFAULT; }
const static std::string name;
const static std::string tag;
};
struct PlainFormatS
{
static void read(std::ifstream& in, BlockArray& data, sdsl::int_vector<64>& counts);
static void write(std::ofstream& out, const BlockArray& data, const NativeHeader&);
inline static AlphabeticOrder order() { return AO_SORTED; }
const static std::string name;
const static std::string tag;
};
struct RFMFormat
{
static void read(std::ifstream& in, BlockArray& data, sdsl::int_vector<64>& counts);
static void write(std::ofstream& out, const BlockArray& data, const NativeHeader& info);
inline static AlphabeticOrder order() { return AO_SORTED; }
const static std::string name;
const static std::string tag;
};
struct SDSLFormat
{
static void read(std::ifstream& in, BlockArray& data, sdsl::int_vector<64>& counts);
static void write(std::ofstream& out, const BlockArray& data, const NativeHeader& info);
inline static AlphabeticOrder order() { return AO_SORTED; }
const static std::string name;
const static std::string tag;
};
struct RopeFormat
{
static void read(std::ifstream& in, BlockArray& data, sdsl::int_vector<64>& counts);
static void write(std::ofstream& out, const BlockArray& data, const NativeHeader& info);
inline static AlphabeticOrder order() { return AO_DEFAULT; }
const static std::string name;
const static std::string tag;
};
struct SGAFormat
{
static void read(std::ifstream& in, BlockArray& data, sdsl::int_vector<64>& counts);
static void write(std::ofstream& out, const BlockArray& data, const NativeHeader& info);
inline static AlphabeticOrder order() { return AO_DEFAULT; }
const static std::string name;
const static std::string tag;
};
//------------------------------------------------------------------------------
bool formatExists(const std::string& format);
void printFormats(std::ostream& stream);
template<class Format>
void
printFormat(std::ostream& stream)
{
std::string padding;
if(Format::tag.length() < 15) { padding = std::string(15 - Format::tag.length(), ' '); }
stream << " " << Format::tag << padding << Format::name << std::endl;
}
//------------------------------------------------------------------------------
struct RopeHeader
{
uint32_t tag;
const static uint32_t DEFAULT_TAG = 0x06454C52;
const static size_type SIZE = 4;
RopeHeader();
size_type serialize(std::ostream& out, sdsl::structure_tree_node* v = nullptr, std::string name = "") const;
void load(std::istream& in);
bool check() const;
};
std::ostream& operator<<(std::ostream& stream, const RopeHeader& header);
struct SGAHeader
{
uint16_t tag;
uint64_t sequences;
uint64_t bases;
uint64_t bytes;
uint32_t flags;
const static uint16_t DEFAULT_TAG = 0xCACA;
const static uint32_t DEFAULT_FLAGS = 0;
SGAHeader();
size_type serialize(std::ostream& out, sdsl::structure_tree_node* v = nullptr, std::string name = "") const;
void load(std::istream& in);
bool check() const;
};
std::ostream& operator<<(std::ostream& stream, const SGAHeader& header);
//------------------------------------------------------------------------------
} // namespace bwtmerge
#endif // _BWTMERGE_FORMATS_H