| 1 |
/* The MIT License |
| 2 |
|
| 3 |
Copyright (c) 2018- Dana-Farber Cancer Institute |
| 4 |
2009-2018 Broad Institute, Inc. |
| 5 |
2008-2009 Genome Research Ltd. (GRL) |
| 6 |
|
| 7 |
Permission is hereby granted, free of charge, to any person obtaining |
| 8 |
a copy of this software and associated documentation files (the |
| 9 |
"Software"), to deal in the Software without restriction, including |
| 10 |
without limitation the rights to use, copy, modify, merge, publish, |
| 11 |
distribute, sublicense, and/or sell copies of the Software, and to |
| 12 |
permit persons to whom the Software is furnished to do so, subject to |
| 13 |
the following conditions: |
| 14 |
|
| 15 |
The above copyright notice and this permission notice shall be |
| 16 |
included in all copies or substantial portions of the Software. |
| 17 |
|
| 18 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 22 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 23 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 |
SOFTWARE. |
| 26 |
*/ |
| 27 |
|
| 28 |
#ifndef BWT_BNTSEQ_H |
| 29 |
#define BWT_BNTSEQ_H |
| 30 |
|
| 31 |
#include <assert.h> |
| 32 |
#include <stdint.h> |
| 33 |
#include <stdio.h> |
| 34 |
#include <zlib.h> |
| 35 |
|
| 36 |
#ifndef BWA_UBYTE |
| 37 |
#define BWA_UBYTE |
| 38 |
typedef uint8_t ubyte_t; |
| 39 |
#endif |
| 40 |
|
| 41 |
typedef struct { |
| 42 |
int64_t offset; |
| 43 |
int32_t len; |
| 44 |
int32_t n_ambs; |
| 45 |
uint32_t gi; |
| 46 |
int32_t is_alt; |
| 47 |
char *name, *anno; |
| 48 |
} bntann1_t; |
| 49 |
|
| 50 |
typedef struct { |
| 51 |
int64_t offset; |
| 52 |
int32_t len; |
| 53 |
char amb; |
| 54 |
} bntamb1_t; |
| 55 |
|
| 56 |
typedef struct { |
| 57 |
int64_t l_pac; |
| 58 |
int32_t n_seqs; |
| 59 |
uint32_t seed; |
| 60 |
bntann1_t *anns; // n_seqs elements |
| 61 |
int32_t n_holes; |
| 62 |
bntamb1_t *ambs; // n_holes elements |
| 63 |
FILE *fp_pac; |
| 64 |
} bntseq_t; |
| 65 |
|
| 66 |
extern unsigned char nst_nt4_table[256]; |
| 67 |
|
| 68 |
#ifdef __cplusplus |
| 69 |
extern "C" { |
| 70 |
#endif |
| 71 |
|
| 72 |
void bns_dump(const bntseq_t *bns, const char *prefix); |
| 73 |
bntseq_t *bns_restore(const char *prefix); |
| 74 |
bntseq_t *bns_restore_core(const char *ann_filename, const char* amb_filename, const char* pac_filename); |
| 75 |
void bns_destroy(bntseq_t *bns); |
| 76 |
int64_t bns_fasta2bntseq(gzFile fp_fa, const char *prefix, int for_only); |
| 77 |
int bns_pos2rid(const bntseq_t *bns, int64_t pos_f); |
| 78 |
int bns_cnt_ambi(const bntseq_t *bns, int64_t pos_f, int len, int *ref_id); |
| 79 |
uint8_t *bns_get_seq(int64_t l_pac, const uint8_t *pac, int64_t beg, int64_t end, int64_t *len); |
| 80 |
uint8_t *bns_fetch_seq(const bntseq_t *bns, const uint8_t *pac, int64_t *beg, int64_t mid, int64_t *end, int *rid); |
| 81 |
int bns_intv2rid(const bntseq_t *bns, int64_t rb, int64_t re); |
| 82 |
|
| 83 |
#ifdef __cplusplus |
| 84 |
} |
| 85 |
#endif |
| 86 |
|
| 87 |
static inline int64_t bns_depos(const bntseq_t *bns, int64_t pos, int *is_rev) |
| 88 |
{ |
| 89 |
return (*is_rev = (pos >= bns->l_pac))? (bns->l_pac<<1) - 1 - pos : pos; |
| 90 |
} |
| 91 |
|
| 92 |
#endif |