NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Macros | Typedefs | Functions
sam.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <zlib.h>
#include "htslib/sam.h"
#include "htslib/bgzf.h"
#include "cram/cram.h"
#include "htslib/hfile.h"
#include "htslib/khash.h"
#include "htslib/kseq.h"
#include "htslib/kstring.h"
#include <assert.h>

Go to the source code of this file.

Classes

struct  hts_cram_idx_t
 
struct  cstate_t
 
struct  __linkbuf_t
 
struct  mempool_t
 
struct  __bam_mplp_t
 

Macros

#define _read_token(_p)   (_p); for (; *(_p) && *(_p) != '\t'; ++(_p)); if (*(_p) != '\t') goto err_ret; *(_p)++ = 0
 
#define _read_token_aux(_p)   (_p); for (; *(_p) && *(_p) != '\t'; ++(_p)); *(_p)++ = 0
 
#define _get_mem(type_t, _x, _s, _l)   ks_resize((_s), (_s)->l + (_l)); *(_x) = (type_t*)((_s)->s + (_s)->l); (_s)->l += (_l)
 
#define _parse_err(cond, msg)   do { if ((cond) && hts_verbose >= 1) { fprintf(stderr, "[E::%s] " msg "\n", __func__); goto err_ret; } } while (0)
 
#define _parse_warn(cond, msg)   if ((cond) && hts_verbose >= 2) fprintf(stderr, "[W::%s] " msg "\n", __func__)
 
#define STRNCMP(a, b, n)   (strncasecmp((a),(b),(n)) || strlen(a)!=(n))
 
#define _cop(c)   ((c)&BAM_CIGAR_MASK)
 
#define _cln(c)   ((c)>>BAM_CIGAR_SHIFT)
 

Typedefs

typedef struct hts_cram_idx_t hts_cram_idx_t
 
typedef struct __linkbuf_t lbnode_t
 

Functions

typedef khash_t (s2i)
 
void bam_hdr_destroy (bam_hdr_t *h)
 
bam_hdr_tbam_hdr_dup (const bam_hdr_t *h0)
 
bam_hdr_tbam_hdr_read (BGZF *fp)
 
int bam_hdr_write (BGZF *fp, const bam_hdr_t *h)
 
int bam_name2id (bam_hdr_t *h, const char *ref)
 
bam1_tbam_init1 ()
 
void bam_destroy1 (bam1_t *b)
 
bam1_tbam_copy1 (bam1_t *bdst, const bam1_t *bsrc)
 
bam1_tbam_dup1 (const bam1_t *bsrc)
 
int bam_cigar2qlen (int n_cigar, const uint32_t *cigar)
 
int bam_cigar2rlen (int n_cigar, const uint32_t *cigar)
 
int32_t bam_endpos (const bam1_t *b)
 
int bam_read1 (BGZF *fp, bam1_t *b)
 
int bam_write1 (BGZF *fp, const bam1_t *b)
 
int bam_index_build (const char *fn, int min_shift)
 
hts_idx_tsam_index_load (samFile *fp, const char *fn)
 
hts_itr_tsam_itr_queryi (const hts_idx_t *idx, int tid, int beg, int end)
 
hts_itr_tsam_itr_querys (const hts_idx_t *idx, bam_hdr_t *hdr, const char *region)
 
bam_hdr_tsam_hdr_parse (int l_text, const char *text)
 
bam_hdr_tsam_hdr_read (htsFile *fp)
 
int sam_hdr_write (htsFile *fp, const bam_hdr_t *h)
 
int sam_parse1 (kstring_t *s, bam_hdr_t *h, bam1_t *b)
 
int sam_read1 (htsFile *fp, bam_hdr_t *h, bam1_t *b)
 
int sam_format1 (const bam_hdr_t *h, const bam1_t *b, kstring_t *str)
 
int sam_write1 (htsFile *fp, const bam_hdr_t *h, const bam1_t *b)
 
void bam_aux_append (bam1_t *b, const char tag[2], char type, int len, uint8_t *data)
 
uint8_tbam_aux_get (const bam1_t *b, const char tag[2])
 
int bam_aux_del (bam1_t *b, uint8_t *s)
 
int32_t bam_aux2i (const uint8_t *s)
 
double bam_aux2f (const uint8_t *s)
 
char bam_aux2A (const uint8_t *s)
 
char * bam_aux2Z (const uint8_t *s)
 
int sam_open_mode (char *mode, const char *fn, const char *format)
 
int bam_str2flag (const char *str)
 
char * bam_flag2str (int flag)
 
typedef khash_t (olap_hash)
 
bam_plp_t bam_plp_init (bam_plp_auto_f func, void *data)
 
void bam_plp_init_overlaps (bam_plp_t iter)
 
void bam_plp_destroy (bam_plp_t iter)
 
const bam_pileup1_tbam_plp_next (bam_plp_t iter, int *_tid, int *_pos, int *_n_plp)
 
int bam_plp_push (bam_plp_t iter, const bam1_t *b)
 
const bam_pileup1_tbam_plp_auto (bam_plp_t iter, int *_tid, int *_pos, int *_n_plp)
 
void bam_plp_reset (bam_plp_t iter)
 
void bam_plp_set_maxcnt (bam_plp_t iter, int maxcnt)
 
bam_mplp_t bam_mplp_init (int n, bam_plp_auto_f func, void **data)
 
void bam_mplp_init_overlaps (bam_mplp_t iter)
 
void bam_mplp_set_maxcnt (bam_mplp_t iter, int maxcnt)
 
void bam_mplp_destroy (bam_mplp_t iter)
 
int bam_mplp_auto (bam_mplp_t iter, int *_tid, int *_pos, int *n_plp, const bam_pileup1_t **plp)
 

Macro Definition Documentation

#define _cln (   c)    ((c)>>BAM_CIGAR_SHIFT)
#define _cop (   c)    ((c)&BAM_CIGAR_MASK)
#define _get_mem (   type_t,
  _x,
  _s,
  _l 
)    ks_resize((_s), (_s)->l + (_l)); *(_x) = (type_t*)((_s)->s + (_s)->l); (_s)->l += (_l)
#define _parse_err (   cond,
  msg 
)    do { if ((cond) && hts_verbose >= 1) { fprintf(stderr, "[E::%s] " msg "\n", __func__); goto err_ret; } } while (0)
#define _parse_warn (   cond,
  msg 
)    if ((cond) && hts_verbose >= 2) fprintf(stderr, "[W::%s] " msg "\n", __func__)
#define _read_token (   _p)    (_p); for (; *(_p) && *(_p) != '\t'; ++(_p)); if (*(_p) != '\t') goto err_ret; *(_p)++ = 0
#define _read_token_aux (   _p)    (_p); for (; *(_p) && *(_p) != '\t'; ++(_p)); *(_p)++ = 0
#define STRNCMP (   a,
  b,
 
)    (strncasecmp((a),(b),(n)) || strlen(a)!=(n))

Definition at line 1133 of file sam.c.

Typedef Documentation

typedef struct __linkbuf_t lbnode_t

Function Documentation

char bam_aux2A ( const uint8_t s)

Definition at line 1100 of file sam.c.

double bam_aux2f ( const uint8_t s)

Definition at line 1091 of file sam.c.

int32_t bam_aux2i ( const uint8_t s)

Definition at line 1079 of file sam.c.

char* bam_aux2Z ( const uint8_t s)

Definition at line 1108 of file sam.c.

void bam_aux_append ( bam1_t b,
const char  tag[2],
char  type,
int  len,
uint8_t data 
)

Definition at line 1018 of file sam.c.

int bam_aux_del ( bam1_t b,
uint8_t s 
)

Definition at line 1067 of file sam.c.

uint8_t* bam_aux_get ( const bam1_t b,
const char  tag[2] 
)

Definition at line 1053 of file sam.c.

int bam_cigar2qlen ( int  n_cigar,
const uint32_t cigar 
)

Definition at line 218 of file sam.c.

int bam_cigar2rlen ( int  n_cigar,
const uint32_t cigar 
)

Definition at line 227 of file sam.c.

bam1_t* bam_copy1 ( bam1_t bdst,
const bam1_t bsrc 
)

Definition at line 194 of file sam.c.

void bam_destroy1 ( bam1_t b)

Definition at line 188 of file sam.c.

bam1_t* bam_dup1 ( const bam1_t bsrc)

Definition at line 210 of file sam.c.

int32_t bam_endpos ( const bam1_t b)

Calculate the rightmost base position of an alignment on the reference genome.

Parameters
bpointer to an alignment
Returns
the coordinate of the first base after the alignment, 0-based

For a mapped read, this is just b->core.pos + bam_cigar2rlen. For an unmapped read (either according to its flags or if it has no cigar string), we return b->core.pos + 1 by convention.

Definition at line 236 of file sam.c.

char* bam_flag2str ( int  flag)

returns negative value on error

Definition at line 1163 of file sam.c.

void bam_hdr_destroy ( bam_hdr_t h)

Definition at line 26 of file sam.c.

bam_hdr_t* bam_hdr_dup ( const bam_hdr_t h0)

Definition at line 41 of file sam.c.

bam_hdr_t* bam_hdr_read ( BGZF fp)

Definition at line 84 of file sam.c.

int bam_hdr_write ( BGZF fp,
const bam_hdr_t h 
)

Definition at line 125 of file sam.c.

int bam_index_build ( const char *  fn,
int  min_shift 
)

Definition at line 403 of file sam.c.

bam1_t* bam_init1 ( void  )

Definition at line 183 of file sam.c.

int bam_mplp_auto ( bam_mplp_t  iter,
int *  _tid,
int *  _pos,
int *  n_plp,
const bam_pileup1_t **  plp 
)

Definition at line 1772 of file sam.c.

void bam_mplp_destroy ( bam_mplp_t  iter)

Definition at line 1764 of file sam.c.

bam_mplp_t bam_mplp_init ( int  n,
bam_plp_auto_f  func,
void **  data 
)

Definition at line 1732 of file sam.c.

void bam_mplp_init_overlaps ( bam_mplp_t  iter)

bam_mplp_init_overlaps() - if called, mpileup will detect overlapping read pairs and for each base pair set the base quality of the lower-quality base to zero, thus effectively discarding it from calling. If the two bases are identical, the quality of the other base is increased to the sum of their qualities (capped at 200), otherwise it is multiplied by 0.8.

Definition at line 1750 of file sam.c.

void bam_mplp_set_maxcnt ( bam_mplp_t  iter,
int  maxcnt 
)

Definition at line 1757 of file sam.c.

int bam_name2id ( bam_hdr_t h,
const char *  ref 
)

Definition at line 162 of file sam.c.

const bam_pileup1_t* bam_plp_auto ( bam_plp_t  iter,
int *  _tid,
int *  _pos,
int *  _n_plp 
)

Definition at line 1676 of file sam.c.

void bam_plp_destroy ( bam_plp_t  iter)

Definition at line 1374 of file sam.c.

bam_plp_t bam_plp_init ( bam_plp_auto_f  func,
void *  data 
)

bam_plp_init() - sets an iterator over multiple : see mplp_func in bam_plcmd.c in samtools for an example. Expected return status: 0 on success, -1 on end, < -1 on non-recoverable errors : user data to pass to

Definition at line 1352 of file sam.c.

void bam_plp_init_overlaps ( bam_plp_t  iter)

Definition at line 1369 of file sam.c.

const bam_pileup1_t* bam_plp_next ( bam_plp_t  iter,
int *  _tid,
int *  _pos,
int *  _n_plp 
)

Definition at line 1591 of file sam.c.

int bam_plp_push ( bam_plp_t  iter,
const bam1_t b 
)

Definition at line 1637 of file sam.c.

void bam_plp_reset ( bam_plp_t  iter)

Definition at line 1700 of file sam.c.

void bam_plp_set_maxcnt ( bam_plp_t  iter,
int  maxcnt 
)

Definition at line 1715 of file sam.c.

int bam_read1 ( BGZF fp,
bam1_t b 
)

Definition at line 299 of file sam.c.

int bam_str2flag ( const char *  str)

Definition at line 1134 of file sam.c.

int bam_write1 ( BGZF fp,
const bam1_t b 
)

Definition at line 335 of file sam.c.

typedef khash_t ( s2i  )

Definition at line 15 of file sam.c.

typedef khash_t ( olap_hash  )

Definition at line 1336 of file sam.c.

int sam_format1 ( const bam_hdr_t h,
const bam1_t b,
kstring_t str 
)

Definition at line 879 of file sam.c.

bam_hdr_t* sam_hdr_parse ( int  l_text,
const char *  text 
)

Definition at line 558 of file sam.c.

bam_hdr_t* sam_hdr_read ( htsFile fp)

Definition at line 596 of file sam.c.

int sam_hdr_write ( htsFile fp,
const bam_hdr_t h 
)

Definition at line 631 of file sam.c.

hts_idx_t* sam_index_load ( samFile fp,
const char *  fn 
)

Definition at line 470 of file sam.c.

hts_itr_t* sam_itr_queryi ( const hts_idx_t idx,
int  tid,
int  beg,
int  end 
)

Definition at line 525 of file sam.c.

hts_itr_t* sam_itr_querys ( const hts_idx_t idx,
bam_hdr_t hdr,
const char *  region 
)

Definition at line 542 of file sam.c.

int sam_open_mode ( char *  mode,
const char *  fn,
const char *  format 
)

Definition at line 1116 of file sam.c.

int sam_parse1 ( kstring_t s,
bam_hdr_t h,
bam1_t b 
)

Definition at line 663 of file sam.c.

int sam_read1 ( htsFile fp,
bam_hdr_t h,
bam1_t b 
)

Definition at line 849 of file sam.c.

int sam_write1 ( htsFile fp,
const bam_hdr_t h,
const bam1_t b 
)

Definition at line 1000 of file sam.c.