41 #ifndef VARIANTKEY_REGIONKEY_H 42 #define VARIANTKEY_REGIONKEY_H 47 #define RK_MAX_POS 0x000000000FFFFFFF 48 #define RKMASK_CHROM 0xF800000000000000 49 #define RKMASK_STARTPOS 0x07FFFFFF80000000 50 #define RKMASK_ENDPOS 0x000000007FFFFFF8 51 #define RKMASK_STRAND 0x0000000000000006 52 #define RKMASK_NOPOS 0xF800000000000007 53 #define RKSHIFT_CHROM 59 54 #define RKSHIFT_STARTPOS 31 55 #define RKSHIFT_ENDPOS 3 56 #define RKSHIFT_STRAND 1 58 #define RK_CHROM ((rk & RKMASK_CHROM) >> RKSHIFT_CHROM) 59 #define RK_STARTPOS ((rk & RKMASK_STARTPOS) >> RKSHIFT_STARTPOS) 60 #define RK_ENDPOS ((rk & RKMASK_ENDPOS) >> RKSHIFT_ENDPOS) 61 #define RK_STRAND ((rk & RKMASK_STRAND) >> RKSHIFT_STRAND) 94 static const uint8_t map[] = {2, 0, 1, 0};
95 return map[((uint8_t)(++strand) & 3)];
106 static const int8_t map[] = {0, 1, -1, 0};
107 return map[(strand & 3)];
219 startpos = ((size >=
startpos) ? 0 : (startpos - size));
283 static inline uint8_t
are_overlapping_regions(uint8_t a_chrom, uint32_t a_startpos, uint32_t a_endpos, uint8_t b_chrom, uint32_t b_startpos, uint32_t b_endpos)
285 return (uint8_t)((a_chrom == b_chrom) && (a_startpos < b_endpos) && (a_endpos > b_startpos));
339 #endif // VARIANTKEY_REGIONKEY_H #define RK_MAX_POS
Maximum position value (2^28 - 1)
Definition: regionkey.h:47
static uint64_t get_regionkey_chrom_endpos(uint64_t rk)
Get the CHROM + END POS encoding from RegionKey.
Definition: regionkey.h:267
struct regionkey_t regionkey_t
static uint8_t extract_variantkey_chrom(uint64_t vk)
Extract the CHROM code from VariantKey.
Definition: variantkey.h:451
static uint32_t extract_regionkey_endpos(uint64_t rk)
Extract the END POS code from RegionKey.
Definition: regionkey.h:152
static uint8_t are_overlapping_variantkey_regionkey(nrvk_cols_t nvc, uint64_t vk, uint64_t rk)
Check if variantkey and regionkey are overlapping.
Definition: regionkey.h:322
uint32_t endpos
Region end position (pos_start + region_length)
Definition: regionkey.h:82
static uint32_t extract_variantkey_pos(uint64_t vk)
Extract the POS code from VariantKey.
Definition: variantkey.h:462
struct regionkey_rev_t regionkey_rev_t
uint32_t startpos
Region start position (zero based)
Definition: regionkey.h:70
static uint64_t get_regionkey_chrom_startpos(uint64_t rk)
Get the CHROM + START POS encoding from RegionKey.
Definition: regionkey.h:256
static uint8_t are_overlapping_regions(uint8_t a_chrom, uint32_t a_startpos, uint32_t a_endpos, uint8_t b_chrom, uint32_t b_startpos, uint32_t b_endpos)
Check if two regions are overlapping.
Definition: regionkey.h:283
static size_t regionkey_hex(uint64_t rk, char *str)
Returns RegionKey hexadecimal string (16 characters).
Definition: regionkey.h:234
uint32_t endpos
Region end position (pos_start + region_length)
Definition: regionkey.h:71
#define RK_ENDPOS
Extract the END POS code from RegionKey.
Definition: regionkey.h:60
#define RKMASK_CHROM
RegionKey binary mask for CHROM [ 11111000 00000000 00000000 00000000 00000000 00000000 00000000 0000...
Definition: regionkey.h:48
static int8_t decode_region_strand(uint8_t strand)
Decode the strand direction code (0 > 0, 1 > +1, 2 > -1).
Definition: regionkey.h:104
static size_t decode_chrom(uint8_t code, char *chrom)
Decode the chromosome numerical code.
Definition: variantkey.h:145
#define RKMASK_NOPOS
RegionKey binary mask WITHOUT POS [ 11111000 00000000 00000000 00000000 00000000 00000000 00000000 00...
Definition: regionkey.h:52
#define RK_STARTPOS
Extract the START POS code from RegionKey.
Definition: regionkey.h:59
static uint8_t are_overlapping_regionkeys(uint64_t rka, uint64_t rkb)
Check if two regionkeys are overlapping.
Definition: regionkey.h:309
uint32_t startpos
Region start position (zero based)
Definition: regionkey.h:81
#define RKSHIFT_STARTPOS
START POS LSB position from the VariantKey LSB.
Definition: regionkey.h:54
static uint8_t are_overlapping_region_regionkey(uint8_t chrom, uint32_t startpos, uint32_t endpos, uint64_t rk)
Check if a region and a regionkey are overlapping.
Definition: regionkey.h:297
static uint64_t regionkey(const char *chrom, size_t sizechrom, uint32_t startpos, uint32_t endpos, int8_t strand)
Returns a 64 bit regionkey based on CHROM, START POS (0-based), END POS and STRAND.
Definition: regionkey.h:205
static uint64_t extend_regionkey(uint64_t rk, uint32_t size)
Extend a regionkey region by a fixed amount from the start and end position.
Definition: regionkey.h:215
static uint64_t encode_regionkey(uint8_t chrom, uint32_t startpos, uint32_t endpos, uint8_t strand)
Returns a 64 bit regionkey.
Definition: regionkey.h:119
static void reverse_regionkey(uint64_t rk, regionkey_rev_t *rev)
Definition: regionkey.h:187
static uint32_t get_variantkey_endpos(nrvk_cols_t nvc, uint64_t vk)
Definition: nrvk.h:198
uint8_t strand
Encoded region strand direction (0 > 0, 1 > +1, 2 > -1).
Definition: regionkey.h:72
static uint32_t extract_regionkey_startpos(uint64_t rk)
Extract the START POS code from RegionKey.
Definition: regionkey.h:141
static uint64_t variantkey_to_regionkey(nrvk_cols_t nvc, uint64_t vk)
Get RegionKey from VariantKey.
Definition: regionkey.h:334
Definition: regionkey.h:78
#define RK_STRAND
Extract the STRAND from RegionKey.
Definition: regionkey.h:61
Definition: regionkey.h:67
uint8_t chrom
Chromosome encoded number (only the LSB 5 bit are used)
Definition: regionkey.h:69
static uint8_t encode_chrom(const char *chrom, size_t size)
Returns chromosome numerical encoding.
Definition: variantkey.h:86
int8_t strand
Region strand direction (-1, 0, +1)
Definition: regionkey.h:83
static uint8_t encode_region_strand(int8_t strand)
Encode the strand direction (-1 > 2, 0 > 0, +1 > 1).
Definition: regionkey.h:92
static uint8_t extract_regionkey_strand(uint64_t rk)
Extract the STRAND from RegionKey.
Definition: regionkey.h:163
Functions to retrieve REF and ALT values by VariantKey from binary data file.
char chrom[3]
Chromosome.
Definition: regionkey.h:80
static uint64_t parse_regionkey_hex(const char *rs)
Parses a RegionKey hexadecimal string and returns the code.
Definition: regionkey.h:245
static void decode_regionkey(uint64_t code, regionkey_t *rk)
Decode a RegionKey code and returns the components as regionkey_t structure.
Definition: regionkey.h:173
static uint64_t parse_hex_uint64_t(const char *s)
Parses a 16 chars hexadecimal string and returns the code.
Definition: hex.h:67
static uint8_t extract_regionkey_chrom(uint64_t rk)
Extract the CHROM code from RegionKey.
Definition: regionkey.h:130
#define RK_CHROM
Extract the CHROM code from RegionKey.
Definition: regionkey.h:58
#define VKMASK_CHROMPOS
VariantKey binary mask for CHROM+POS [ 11111111 11111111 11111111 11111111 10000000 00000000 00000000...
Definition: variantkey.h:53
#define RKSHIFT_STRAND
STRAND LSB position from the VariantKey LSB.
Definition: regionkey.h:56
#define RKSHIFT_CHROM
CHROM LSB position from the VariantKey LSB.
Definition: regionkey.h:53
#define RKSHIFT_ENDPOS
END POS LSB position from the VariantKey LSB.
Definition: regionkey.h:55
static size_t hex_uint64_t(uint64_t n, char *str)
Returns uint64_t hexadecimal string (16 characters).
Definition: hex.h:56