1 #ifndef HTSLIB_UTIL_H
2 #define HTSLIB_UTIL_H
3 
4 #include "htslib/sam.h"
5 #include "htslib/vcf.h"
6 #include "htslib/khash.h"
7 
8 int hts_set_verbosity(int verbosity);
9 int hts_get_verbosity(void);
10 
11 
12 KHASH_MAP_INIT_STR(vdict, bcf_idinfo_t)
13 typedef khash_t(vdict) vdict_t;
14 
15 KHASH_DECLARE(s2i, kh_cstr_t, int64_t)
16 typedef khash_t(s2i) s2i_t;
17 
18 //////////////////////////////////////////////////////////////////
19 //////////////////////////////////////////////////////////////////
20 //////////////////////////////////////////////////////////////////
21 // various helper functions
22 //
23 
24 /*!
25   @abstract Update the variable length data within a bam1_t entry
26 
27   Old data is deleted and the data within b are re-arranged to
28   make place for new data.
29 
30   @discussion Return NULL on error, otherwise b is returned.
31 
32   @param  b           bam1_t data
33   @param  nbytes_old  size of old data
34   @param  nbytes_new  size of new data
35   @param  pos         position of data
36 */
37 bam1_t * pysam_bam_update(bam1_t * b,
38 			  const size_t nbytes_old,
39 			  const size_t nbytes_new,
40 			  uint8_t * pos);
41 
42 // translate a nucleotide character to binary code
43 unsigned char pysam_translate_sequence(const unsigned char s);
44 
45 // return byte size of type
46 int aux_type2size(uint8_t type);
47 
48 
49 //-------------------------------------------------------
50 // Wrapping accessor macros in sam.h
pysam_bam_is_rev(bam1_t * b)51 static inline int pysam_bam_is_rev(bam1_t * b) {
52   return bam_is_rev(b);};
53 
pysam_bam_is_mrev(bam1_t * b)54 static inline int pysam_bam_is_mrev(bam1_t * b) {
55   return bam_is_mrev(b);}
56 
pysam_bam_get_qname(bam1_t * b)57 static inline char * pysam_bam_get_qname(bam1_t * b) {
58   return bam_get_qname(b);}
59 
pysam_bam_get_cigar(bam1_t * b)60 static inline uint32_t * pysam_bam_get_cigar(bam1_t * b) {
61   return bam_get_cigar(b);}
62 
pysam_bam_get_seq(bam1_t * b)63 static inline uint8_t * pysam_bam_get_seq(bam1_t * b) {
64   return bam_get_seq(b);}
65 
pysam_bam_get_qual(bam1_t * b)66 static inline uint8_t * pysam_bam_get_qual(bam1_t * b) {
67   return bam_get_qual(b);}
68 
pysam_bam_get_aux(bam1_t * b)69 static inline uint8_t * pysam_bam_get_aux(bam1_t * b) {
70   return bam_get_aux(b);}
71 
pysam_bam_get_l_aux(bam1_t * b)72 static inline int pysam_bam_get_l_aux(bam1_t * b) {
73   return bam_get_l_aux(b); }
74 
pysam_bam_seqi(uint8_t * s,int i)75 static inline char pysam_bam_seqi(uint8_t * s, int i) {
76   return bam_seqi(s,i);}
77 
pysam_get_qual(bam1_t * b)78 static inline uint8_t pysam_get_qual(bam1_t * b) {
79   return b->core.qual;}
80 
pysam_get_n_cigar(bam1_t * b)81 static inline uint32_t pysam_get_n_cigar(bam1_t * b) {
82   return b->core.n_cigar;}
83 
pysam_set_qual(bam1_t * b,uint8_t v)84 static inline void pysam_set_qual(bam1_t * b, uint8_t v) {
85   b->core.qual=v;}
86 
pysam_set_n_cigar(bam1_t * b,uint32_t v)87 static inline void pysam_set_n_cigar(bam1_t * b, uint32_t v) {
88   b->core.n_cigar=v;}
89 
pysam_update_flag(bam1_t * b,uint16_t v,uint16_t flag)90 static inline void pysam_update_flag(bam1_t * b, uint16_t v, uint16_t flag) {
91   if (v)
92     b->core.flag |= flag;
93   else
94     b->core.flag &= ~flag;
95 }
96 
97 #endif
98