Repository navigation
Expand file tree
/
Copy pathbwt.h
More file actions
92 lines (77 loc) · 2.95 KB
/
Copy pathbwt.h
File metadata and controls
92 lines (77 loc) · 2.95 KB
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
#ifndef MB_BWT_H
#define MB_BWT_H
#include <stdint.h>
#include <stddef.h>
#define MB_MAGIC "MBW\2"
typedef struct {
uint64_t x[2];
uint64_t size, info;
} mb_sai_t;
typedef struct {
uint64_t primary; // S^{-1}(0), or the primary index of BWT
uint64_t L2[5]; // C(), cumulative count
uint64_t seq_len; // sequence length
uint64_t data_len;
uint64_t *data; // BWT
uint32_t cnt_table[256];
uint32_t pre_len;
mb_sai_t *pre;
// suffix array
uint32_t sa_bit; // sample rate: 1/(1<<sa_bit)
uint64_t n_sa;
uint64_t *sa;
// mmap
void *mmap; // mmap pointer
size_t mmap_len; // mmap length (for munmap)
} mb_bwt_t;
typedef struct { size_t n, m; mb_sai_t *a; } mb_sai_v;
typedef struct {
// input before calling
int32_t min_len, min_occ;
int32_t st, en;
const uint8_t *q;
mb_sai_v *v; // output; v->n is not set to 0
// internal state
int32_t stage;
int32_t x, i;
uint32_t kmer; // for k-mer cache
mb_sai_t p;
} mb_smem_entry_t;
#ifdef __cplusplus
extern "C" {
#endif
extern int mb_verbose;
mb_bwt_t *mb_bwt_init(void);
void mb_bwt_destroy(mb_bwt_t *bwt);
mb_bwt_t *mb_bwt_load_raw(const char *fn); // from raw bwt_gen.c output
int mb_bwt_save(const char *fn, const mb_bwt_t *bwt);
mb_bwt_t *mb_bwt_load(const char *fn);
mb_bwt_t *mb_bwt_load_mmap(const char *fn, int preload);
mb_bwt_t *mb_bwt_init_from_raw(int is_byte, const void *raw_, uint64_t len, uint64_t primary);
mb_bwt_t *mb_bwt_init_from_inverted_sa(const uint8_t *a, int64_t len, int64_t primary, int n_thread);
#define MB_SA_MAGIC "MSA\1" /* 4 bytes: 'M','S','A',0x01 */
int mb_bwt_save_sa(const char *fn, const mb_bwt_t *bwt); /* write sidecar from bwt->sa/sa_bit/n_sa */
int mb_bwt_load_sa(mb_bwt_t *bwt, const char *fn); /* attach sidecar SA to a loaded BWT (0=ok) */
mb_bwt_t *mb_bwt_load_nosa(const char *fn); /* heap-load BWT only; sa_bit=-1, sa=NULL, n_sa=0 */
void mb_bwt_cache(mb_bwt_t *bwt, int32_t len);
uint64_t mb_bwt_rank11(const mb_bwt_t *bwt, uint64_t k, uint8_t c);
void mb_bwt_rank1a(const mb_bwt_t *bwt, uint64_t k, uint64_t cnt[4]);
void mb_bwt_rank2a(const mb_bwt_t *bwt, uint64_t k, uint64_t l, uint64_t cntk[4], uint64_t cntl[4]);
void mb_bwt_extend(const mb_bwt_t *bwt, const mb_sai_t *ik, mb_sai_t ok[4], int is_back);
void mb_bwt_count_kmer(const mb_bwt_t *bwt, int32_t depth, mb_sai_t *a);
int64_t mb_bwt_smem(const mb_bwt_t *f, uint32_t len, const uint8_t *q, int64_t x, int64_t min_len, int64_t min_occ, mb_sai_t *p);
void mb_bwt_smem_batch(void *km, const mb_bwt_t *bwt, int32_t n, mb_smem_entry_t *a);
void mb_bwt_gen_sa(mb_bwt_t *bwt, uint32_t sa_bit);
uint64_t mb_bwt_sa(const mb_bwt_t *bwt, uint64_t k);
void mb_bwt_sa_batch(void *km, const mb_bwt_t *bwt, int64_t n, uint64_t *x);
static inline void mb_bwt_set_intv(const mb_bwt_t *bwt, int c, mb_sai_t *ik)
{
ik->x[0] = bwt->L2[c] + 1; // +1 for the missing sentinel
ik->x[1] = bwt->L2[3-c] + 1;
ik->size = bwt->L2[c+1] - bwt->L2[c];
ik->info = 0;
}
#ifdef __cplusplus
}
#endif
#endif