63 #define BAM_CREF_SKIP 3
64 #define BAM_CSOFT_CLIP 4
65 #define BAM_CHARD_CLIP 5
71 #define BAM_CIGAR_STR "MIDNSHP=XB"
72 #define BAM_CIGAR_SHIFT 4
73 #define BAM_CIGAR_MASK 0xf
74 #define BAM_CIGAR_TYPE 0x3C1A7
76 #define bam_cigar_op(c) ((c)&BAM_CIGAR_MASK)
77 #define bam_cigar_oplen(c) ((c)>>BAM_CIGAR_SHIFT)
78 #define bam_cigar_opchr(c) (BAM_CIGAR_STR[bam_cigar_op(c)])
79 #define bam_cigar_gen(l, o) ((l)<<BAM_CIGAR_SHIFT|(o))
100 #define bam_cigar_type(o) (BAM_CIGAR_TYPE>>((o)<<1)&3) // bit 1: consume query; bit 2: consume reference
103 #define BAM_FPAIRED 1
105 #define BAM_FPROPER_PAIR 2
109 #define BAM_FMUNMAP 8
111 #define BAM_FREVERSE 16
113 #define BAM_FMREVERSE 32
115 #define BAM_FREAD1 64
117 #define BAM_FREAD2 128
119 #define BAM_FSECONDARY 256
121 #define BAM_FQCFAIL 512
123 #define BAM_FDUP 1024
125 #define BAM_FSUPPLEMENTARY 2048
147 uint32_t bin:16, qual:8, l_qname:8;
148 uint32_t flag:16, n_cigar:16;
184 #define bam_is_rev(b) (((b)->core.flag&BAM_FREVERSE) != 0)
190 #define bam_is_mrev(b) (((b)->core.flag&BAM_FMREVERSE) != 0)
196 #define bam_get_qname(b) ((char*)(b)->data)
206 #define bam_get_cigar(b) ((uint32_t*)((b)->data + (b)->core.l_qname))
217 #define bam_get_seq(b) ((b)->data + ((b)->core.n_cigar<<2) + (b)->core.l_qname)
223 #define bam_get_qual(b) ((b)->data + ((b)->core.n_cigar<<2) + (b)->core.l_qname + (((b)->core.l_qseq + 1)>>1))
229 #define bam_get_aux(b) ((b)->data + ((b)->core.n_cigar<<2) + (b)->core.l_qname + (((b)->core.l_qseq + 1)>>1) + (b)->core.l_qseq)
235 #define bam_get_l_aux(b) ((b)->l_data - ((b)->core.n_cigar<<2) - (b)->core.l_qname - (b)->core.l_qseq - (((b)->core.l_qseq + 1)>>1))
242 #define bam_seqi(s, i) ((s)[(i)>>1] >> ((~(i)&1)<<2) & 0xf)
295 #define bam_itr_destroy(iter) hts_itr_destroy(iter)
296 #define bam_itr_queryi(idx, tid, beg, end) sam_itr_queryi(idx, tid, beg, end)
297 #define bam_itr_querys(idx, hdr, region) sam_itr_querys(idx, hdr, region)
298 #define bam_itr_next(htsfp, itr, r) hts_itr_next((htsfp)->fp.bgzf, (itr), (r), 0)
301 #define bam_index_load(fn) hts_idx_load((fn), HTS_FMT_BAI)
308 #define sam_itr_destroy(iter) hts_itr_destroy(iter)
311 #define sam_itr_next(htsfp, itr, r) hts_itr_next((htsfp)->fp.bgzf, (itr), (r), (htsfp))
317 #define sam_open(fn, mode) (hts_open((fn), (mode)))
318 #define sam_close(fp) hts_close(fp)
353 #if !defined(BAM_NO_PILEUP)
377 uint32_t is_del:1, is_head:1, is_tail:1, is_refskip:1, aux:28;
424 #endif // ~!defined(BAM_NO_PILEUP)
hts_itr_t * sam_itr_querys(const hts_idx_t *idx, bam_hdr_t *hdr, const char *region)
Definition: sam.c:579
uint32_t l_text
Definition: sam.h:48
char * bam_aux2Z(const uint8_t *s)
Definition: sam.c:1193
int32_t l_qseq
Definition: sam.h:149
bam_mplp_t bam_mplp_init(int n, bam_plp_auto_f func, void **data)
Definition: sam.c:1817
uint64_t id
Definition: sam.h:175
int bam_cigar2qlen(int n_cigar, const uint32_t *cigar)
Definition: sam.c:243
int32_t isize
Definition: sam.h:152
void * sdict
Definition: sam.h:53
void bam_aux_append(bam1_t *b, const char tag[2], char type, int len, uint8_t *data)
Definition: sam.c:1103
bam_hdr_t * bam_hdr_read(BGZF *fp)
Definition: sam.c:109
int n
Definition: sam.c:1810
int32_t mtid
Definition: sam.h:150
bam_plp_t * iter
Definition: sam.c:1812
int sam_read1(samFile *fp, bam_hdr_t *h, bam1_t *b)
Definition: sam.c:912
int bam_hdr_write(BGZF *fp, const bam_hdr_t *h)
Definition: sam.c:150
bam1_t * b
Definition: sam.h:374
int32_t mpos
Definition: sam.h:151
struct __bam_mplp_t * bam_mplp_t
Definition: sam.h:386
char * text
Definition: sam.h:52
void bam_destroy1(bam1_t *b)
Definition: sam.c:213
int32_t bam_endpos(const bam1_t *b)
Definition: sam.c:261
void bam_mplp_set_maxcnt(bam_mplp_t iter, int maxcnt)
Definition: sam.c:1842
bam_hdr_t * sam_hdr_read(samFile *fp)
Definition: sam.c:633
const bam_pileup1_t * bam_plp_auto(bam_plp_t iter, int *_tid, int *_pos, int *_n_plp)
Definition: sam.c:1761
int32_t pos
Definition: sam.h:146
int sam_parse1(kstring_t *s, bam_hdr_t *h, bam1_t *b)
Definition: sam.c:726
void bam_hdr_destroy(bam_hdr_t *h)
Definition: sam.c:51
int32_t tid
Definition: sam.h:145
uint8_t * bam_aux_get(const bam1_t *b, const char tag[2])
Definition: sam.c:1138
bam1_t * bam_dup1(const bam1_t *bsrc)
Definition: sam.c:235
hts_itr_t * sam_itr_queryi(const hts_idx_t *idx, int tid, int beg, int end)
Definition: sam.c:562
bam_hdr_t * bam_hdr_init(void)
int bam_mplp_auto(bam_mplp_t iter, int *_tid, int *_pos, int *n_plp, const bam_pileup1_t **plp)
Definition: sam.c:1857
double bam_aux2f(const uint8_t *s)
Definition: sam.c:1176
int bam_cigar2rlen(int n_cigar, const uint32_t *cigar)
Definition: sam.c:252
hts_idx_t * sam_index_load(htsFile *fp, const char *fn)
Definition: sam.c:501
char ** target_name
Definition: sam.h:51
int32_t qpos
Definition: sam.h:375
uint8_t * data
Definition: sam.h:173
int * n_plp
Definition: sam.c:1813
int m_data
Definition: sam.h:172
void bam_mplp_init_overlaps(bam_mplp_t iter)
Definition: sam.c:1835
int bam_write1(BGZF *fp, const bam1_t *b)
Definition: sam.c:360
htsFile samFile
Definition: sam.h:322
#define str(x)
Definition: sam.c:66
bam_hdr_t * bam_hdr_dup(const bam_hdr_t *h0)
Definition: sam.c:66
const bam_pileup1_t * bam_plp_next(bam_plp_t iter, int *_tid, int *_pos, int *_n_plp)
Definition: sam.c:1676
void bam_plp_destroy(bam_plp_t iter)
Definition: sam.c:1459
int32_t n_targets
Definition: sam.h:47
char * bam_flag2str(int flag)
Definition: sam.c:1248
struct __bam_plp_t * bam_plp_t
Definition: sam.h:383
int bam_str2flag(const char *str)
Definition: sam.c:1219
uint32_t * target_len
Definition: sam.h:49
bam1_t * bam_init1(void)
Definition: sam.c:208
void bam_plp_reset(bam_plp_t iter)
Definition: sam.c:1785
bam_plp_t bam_plp_init(bam_plp_auto_f func, void *data)
Definition: sam.c:1437
int sam_write1(samFile *fp, const bam_hdr_t *h, const bam1_t *b)
Definition: sam.c:1071
bam1_t * bam_copy1(bam1_t *bdst, const bam1_t *bsrc)
Definition: sam.c:219
int bam_aux_del(bam1_t *b, uint8_t *s)
Definition: sam.c:1152
int32_t bam_aux2i(const uint8_t *s)
Definition: sam.c:1164
char bam_aux2A(const uint8_t *s)
Definition: sam.c:1185
int bam_name2id(bam_hdr_t *h, const char *ref)
Definition: sam.c:187
int bam_read1(BGZF *fp, bam1_t *b)
Definition: sam.c:324
void bam_plp_set_maxcnt(bam_plp_t iter, int maxcnt)
Definition: sam.c:1800
int sam_hdr_write(samFile *fp, const bam_hdr_t *h)
Definition: sam.c:675
int sam_open_mode(char *mode, const char *fn, const char *format)
Definition: sam.c:1201
int(* bam_plp_auto_f)(void *data, bam1_t *b)
Definition: sam.h:380
int bam_index_build(const char *fn, int min_shift)
Definition: sam.c:428
int sam_format1(const bam_hdr_t *h, const bam1_t *b, kstring_t *str)
Definition: sam.c:950
void bam_mplp_destroy(bam_mplp_t iter)
Definition: sam.c:1849
const bam_pileup1_t ** plp
Definition: sam.c:1814
int bam_plp_push(bam_plp_t iter, const bam1_t *b)
Definition: sam.c:1722
bam1_core_t core
Definition: sam.h:171
int level
Definition: sam.h:376
bam_hdr_t * sam_hdr_parse(int l_text, const char *text)
Definition: sam.c:595
int8_t * cigar_tab
Definition: sam.h:50