-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstructs.h
196 lines (156 loc) · 5 KB
/
structs.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
// Metal - A fast methylation alignment and calling tool for WGBS data.
// Copyright (C) 2017 Jonas Fischer
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Jonas Fischer [email protected]
#ifndef STRUCTS_H
#define STRUCTS_H
#include <cstdint>
#include <type_traits>
// struct that holds information about id tags in buffer
// id tags start with '>'
struct idPos {
// pointer to id line
char* const id;
// pointer to next line after the id
char* const sec;
// flag if tag is primary assembly
const bool imp;
// Ctor for emplace_back
idPos(char* const idC, char* const secC, const bool impC) : id(idC), sec(secC), imp(impC) {}
};
struct CpG {
// chromosome on which CpG appears
uint8_t chrom;
// position where this CpG is present in genome
// convention: pos points to position of start of context of CpG (C position - READLEN + 2)
// or to position of C if the former is negative
uint32_t pos;
};
struct metaCpG {
// index of first CpG of this meta CpG
uint32_t start;
// start of this meta CpG is cpgTable[start].pos
// end of this meta CpG is cpgTable[start].pos + WINLEN
// if startmetaCpG .start is 0 and end is WINLEN
// index of last CpG in this meta CpG
uint32_t end;
};
struct metaWindow {
uint32_t startPos;
uint8_t chrom;
// index of first CpG of this meta CpG
// MyConst::CPGDUMMY if no CpG insige MetaCpG
uint32_t startInd;
// index of last CpG in this meta CpG
uint32_t endInd;
};
// test for POD types of structs
inline constexpr bool testPODs()
{
return (std::is_pod<struct CpG>::value && std::is_pod<struct metaCpG>::value);
}
namespace KMER {
// KMER DEFINITION
//
// 31 upper (more significant) bit hold metaCpG index, lower 32 bit hold offset inside metaCpG
// most significant bit holds flag that is 1 <=> points to start meta CpG
typedef uint64_t kmer;
// return the offset of given kmer inside its cpg
inline uint64_t getOffset(const KMER::kmer& k)
{
return k & 0x00000000ffffffffULL;
}
inline uint64_t getMetaCpG(const KMER::kmer& k)
{
return (k & 0x7fffffff00000000ULL) >> 32;
}
inline bool isStartCpG(const KMER::kmer& k)
{
return (k & 0x8000000000000000ULL);
}
inline uint32_t getCore(const KMER::kmer& k)
{
return k >> 32;
}
// constructs a kmer according to its definition
inline KMER::kmer constructKmer(uint64_t isStart, uint64_t metacpg, uint64_t off)
{
return (isStart << 63) | (metacpg << 32) | off;
}
} // end namespace KMER
namespace KMER_S {
typedef struct kmer
{
uint32_t meta;
uint32_t tmask;
} kmer;
inline uint32_t getMetaCpG(const KMER_S::kmer& k)
{
return (k.meta & 0x7fffffffUL);
}
inline bool isStartCpG(const KMER_S::kmer& k)
{
return (k.meta & 0x80000000UL);
}
inline uint32_t getMetaCpG(KMER_S::kmer&& k)
{
return (k.meta & 0x7fffffffUL);
}
inline bool isStartCpG(KMER_S::kmer&& k)
{
return (k.meta & 0x80000000UL);
}
inline kmer constructKmerS(uint32_t metaCpG, uint32_t tMask)
{
return {metaCpG, tMask};
}
} // end namespace KMER_S
namespace MATCH {
// MATCH DEFINITION
//
// 16 lower (least significant) bit hold offset where the match ends in the sequence
// 8 higher bits hold number of errors produced by this match
// next higher bit is strand flag
// even next higher bit is start flag
// 32 most significant bits hold meta CpGID
typedef uint64_t match;
// return the offset of given match
inline uint64_t getOffset(const MATCH::match m)
{
return m & 0x000000000000ffffULL;
}
inline uint64_t getErrNum(const MATCH::match m)
{
return (m & 0x0000000000ff0000ULL) >> 16;
}
inline bool isFwd(const MATCH::match m)
{
return (m & 0x0000000001000000ULL);
}
inline bool isStart(const MATCH::match m)
{
return (m & 0x0000000002000000ULL);
}
inline uint32_t getMetaID(const MATCH::match m)
{
return static_cast<uint32_t>(m >> 32);
}
inline MATCH::match constructMatch(uint16_t off, uint8_t errNum, uint64_t isFwd, uint64_t isStart, uint64_t metaID)
{
return (static_cast<uint64_t>(off)) | (static_cast<uint64_t>(errNum) << 16) | (isFwd << 24) | (isStart << 25) | (metaID << 32);
}
} // end namespace MATCH
#endif /* STRUCTS_H */