dhtslib.htslib.sam

Undocumented in source.

Members

Aliases

bam_index_build
deprecated alias bam_index_build = sam_index_build

/#define bam_index_build(fn, min_shift) (sam_index_build((fn), (min_shift)))

bam_itr_destroy
deprecated alias bam_itr_destroy = hts_itr_destroy

/#define bam_itr_destroy(iter) hts_itr_destroy(iter)

bam_itr_queryi
deprecated alias bam_itr_queryi = sam_itr_queryi

/#define bam_itr_queryi(idx, tid, beg, end) sam_itr_queryi(idx, tid, beg, end)

bam_itr_querys
deprecated alias bam_itr_querys = sam_itr_querys

/#define bam_itr_querys(idx, hdr, region) sam_itr_querys(idx, hdr, region)

bam_mplp_t
alias bam_mplp_t = __bam_mplp_t*

typedef struct __bam_mplp_t *bam_mplp_t;

bam_plp_auto_f
alias bam_plp_auto_f = int* function(void* data, bam1_t* b)

typedef int (*bam_plp_auto_f)(void *data, bam1_t *b);

bam_plp_t
alias bam_plp_t = __bam_plp_t*

typedef struct __bam_plp_t *bam_plp_t;

samFile
alias samFile = htsFile
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
sam_close
alias sam_close = hts_close
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
sam_itr_destroy
alias sam_itr_destroy = hts_itr_destroy

/#define sam_itr_destroy(iter) hts_itr_destroy(iter)

sam_itr_multi_next
alias sam_itr_multi_next = hts_itr_multi_next

/#define sam_itr_multi_next(htsfp, itr, r) hts_itr_multi_next((htsfp), (itr), (r))

sam_open
alias sam_open = hts_open

** SAM I/O ***

sam_open_format
alias sam_open_format = hts_open_format
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Enums

BAM_CMATCH
anonymousenum BAM_CMATCH

** CIGAR related macros ***

Functions

bam_aux2A
char bam_aux2A(const(uint8_t)* s)

@param s Pointer to the tag data, as returned by bam_aux_get(). @return The value, or 0 if the tag was not a character ('A') type If the tag is not a character type, errno is set to EINVAL.

bam_aux2Z
char* bam_aux2Z(const(uint8_t)* s)

@param s Pointer to the tag data, as returned by bam_aux_get(). @return Pointer to the string, or NULL if the tag was not a string type If the tag is not a string type ('Z' or 'H'), errno is set to EINVAL.

bam_aux2f
double bam_aux2f(const(uint8_t)* s)

@param s Pointer to the tag data, as returned by bam_aux_get() @return The value, or 0 if the tag was not an integer type If the tag is not an numeric type, errno is set to EINVAL. The value of integer flags will be returned cast to a double.

bam_aux2i
int64_t bam_aux2i(const(uint8_t)* s)

@param s Pointer to the tag data, as returned by bam_aux_get() @return The value, or 0 if the tag was not an integer type If the tag is not an integer type, errno is set to EINVAL. This function will not return the value of floating-point tags.

bam_auxB2f
double bam_auxB2f(const(uint8_t)* s, uint32_t idx)

@param s Pointer to the tag data, as returned by bam_aux_get(). @param idx 0-based Index into the array @return The idx'th value, or 0.0 on error. If the array is not a numeric type, errno is set to EINVAL. This can only actually happen if the input record has an invalid type field. If idx is greater than or equal to the value returned by bam_auxB_len(s), errno is set to ERANGE. In both cases, 0.0 will be returned.

bam_auxB2i
int64_t bam_auxB2i(const(uint8_t)* s, uint32_t idx)

@param s Pointer to the tag data, as returned by bam_aux_get(). @param idx 0-based Index into the array @return The idx'th value, or 0 on error. If the array is not an integer type, errno is set to EINVAL. If idx is greater than or equal to the value returned by bam_auxB_len(s), errno is set to ERANGE. In both cases, 0 will be returned.

bam_auxB_len
uint32_t bam_auxB_len(const(uint8_t)* s)

@param s Pointer to the tag data, as returned by bam_aux_get(). @return The length of the array, or 0 if the tag is not an array type. If the tag is not an array type, errno is set to EINVAL.

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

Append tag data to a bam record

bam_aux_del
int bam_aux_del(bam1_t* b, uint8_t* s)

Delete tag data from a bam record

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

@param b Pointer to the bam record @param tag Desired aux tag @return Pointer to the tag data, or NULL if tag is not present or on error If the tag is not present, this function returns NULL and sets errno to ENOENT. If the bam record's aux data is corrupt (either a tag has an invalid type, or the last record is incomplete) then errno is set to EINVAL and NULL is returned.

bam_aux_update_array
int bam_aux_update_array(bam1_t* b, char[2] tag, uint8_t type, uint32_t items, void* data)

Update or add an array tag

bam_aux_update_float
int bam_aux_update_float(bam1_t* b, char[2] tag, float val)

Update or add a floating-point tag

bam_aux_update_int
int bam_aux_update_int(bam1_t* b, char[2] tag, int64_t val)

Update or add an integer tag

bam_aux_update_str
int bam_aux_update_str(bam1_t* b, char[2] tag, int len, const(char)* data)

Update or add a string-type tag

bam_cigar2qlen
int bam_cigar2qlen(int n_cigar, const(uint32_t)* cigar)

How much query is consumed by CIGAR op(s)?

bam_cigar2rlen
int bam_cigar2rlen(int n_cigar, const(uint32_t)* cigar)

How much reference is consumed by CIGAR op(s)?

bam_cigar_gen
auto bam_cigar_gen(uint l, uint o)

Generate CIGAR uint from length and operator

bam_cigar_op
auto bam_cigar_op(uint c)

CIGAR opcode for CIGAR uint (4 LSB)

bam_cigar_opchr
auto bam_cigar_opchr(uint c)

CIGAR opcode character for CIGAR uint

bam_cigar_oplen
auto bam_cigar_oplen(uint c)

CIGAR operation length for CIGAR uint (28 MSB >> 4)

bam_cigar_type
auto bam_cigar_type(uint o)

bam_cigar_type returns a bit flag with: bit 1 set if the cigar operation consumes the query bit 2 set if the cigar operation consumes the reference

bam_copy1
bam1_t* bam_copy1(bam1_t* bdst, const(bam1_t)* bsrc)

copy a BAM record from dst to src

bam_destroy1
void bam_destroy1(bam1_t* b)

destroy a BAM record

bam_dup1
bam1_t* bam_dup1(const(bam1_t)* bsrc)

duplicate a BAM record

bam_endpos
int32_t bam_endpos(const(bam1_t)* b)

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

bam_flag2str
char* bam_flag2str(int flag)

The string must be freed by the user

bam_get_aux
auto bam_get_aux(bam1_t* b)

! @function @abstract Get auxiliary data @param b pointer to an alignment @return pointer to the concatenated auxiliary data /#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)

bam_get_cigar
auto bam_get_cigar(bam1_t* b)

! @function @abstract Get the CIGAR array @param b pointer to an alignment @return pointer to the CIGAR array

bam_get_l_aux
auto bam_get_l_aux(bam1_t* b)

! @function @abstract Get length of auxiliary data @param b pointer to an alignment @return length of the concatenated auxiliary data /#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))

bam_get_qname
auto bam_get_qname(bam1_t* b)

! @function @abstract Get the name of the query @param b pointer to an alignment @return pointer to the name string, null terminated

bam_get_qual
auto bam_get_qual(bam1_t* b)

! @function @abstract Get query quality @param b pointer to an alignment @return pointer to quality string /#define bam_get_qual(b) ((b)->data + ((b)->core.n_cigar<<2) + (b)->core.l_qname + (((b)->core.l_qseq + 1)>>1))

bam_get_seq
auto bam_get_seq(bam1_t* b)

! @function @abstract Get query sequence @param b pointer to an alignment @return pointer to sequence

bam_hdr_destroy
void bam_hdr_destroy(bam_hdr_t* h)

destroy a BAM header

bam_hdr_dup
bam_hdr_t* bam_hdr_dup(const(bam_hdr_t)* h0)

duplicate a BAM header

bam_hdr_init
bam_hdr_t* bam_hdr_init()

** BAM I/O *** init a BAM header

bam_hdr_read
bam_hdr_t* bam_hdr_read(BGZF* fp)

read BAM header from fp

bam_hdr_write
int bam_hdr_write(BGZF* fp, const(bam_hdr_t)* h)

write BAM header to fp

bam_index_load
deprecated auto bam_index_load(const(char)* fn)

/#define bam_index_load(fn) hts_idx_load((fn), HTS_FMT_BAI)

bam_init1
bam1_t* bam_init1()

init a BAM record

bam_is_mrev
bool bam_is_mrev(bam1_t* b)

! @function @abstract Get whether the query's mate is on the reverse strand @param b pointer to an alignment @return boolean true if query's mate on the reverse strand

bam_is_rev
bool bam_is_rev(bam1_t* b)

! @function @abstract Get whether the query is on the reverse strand @param b pointer to an alignment @return boolean true if query is on the reverse strand

bam_itr_next
deprecated auto bam_itr_next(htsFile* htsfp, hts_itr_t* itr, void* r)

/#define bam_itr_next(htsfp, itr, r) hts_itr_next((htsfp)->fp.bgzf, (itr), (r), 0)

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

???

bam_mplp_constructor
void bam_mplp_constructor(bam_mplp_t iter, int function(void* data, const(bam1_t)* b, bam_pileup_cd* cd) func)

see bam_plp_constructor

bam_mplp_destroy
void bam_mplp_destroy(bam_mplp_t iter)

destroy mpileup iterator

bam_mplp_destructor
void bam_mplp_destructor(bam_mplp_t iter, int function(void* data, const(bam1_t)* b, bam_pileup_cd* cd) func)

see bam_plp_destructor

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

initialize new mpileup iterator

bam_mplp_init_overlaps
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.

bam_mplp_reset
void bam_mplp_reset(bam_mplp_t iter)

reset mpileup

bam_mplp_set_maxcnt
void bam_mplp_set_maxcnt(bam_mplp_t iter, int maxcnt)

set maximum mpileup records returned per subpileup (init default of each pileup in the mpileup is 8000)

bam_name2id
int bam_name2id(bam_hdr_t* h, const(char)* _ref)

Get contig tid

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

???

bam_plp_constructor
void bam_plp_constructor(bam_plp_t plp, int function(void* data, const(bam1_t)* b, bam_pileup_cd* cd) func)

bam_plp_constructor() - sets a callback to initialise any per-pileup1_t fields. @plp: The bam_plp_t initialised using bam_plp_init. @func: The callback function itself. When called, it is given the data argument (specified in bam_plp_init), the bam structure and a pointer to a locally allocated bam_pileup_cd union. This union will also be present in each bam_pileup1_t created.

bam_plp_destroy
void bam_plp_destroy(bam_plp_t iter)

destroy pileup iterator

bam_plp_destructor
void bam_plp_destructor(bam_plp_t plp, int function(void* data, const(bam1_t)* b, bam_pileup_cd* cd) func)

per-pileup1_t field destructor (may be needed if used bam_plp_constructor())

bam_plp_init
bam_plp_t bam_plp_init(bam_plp_auto_f func, void* data)

bam_plp_init() - sets an iterator over multiple @func: 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 @data: user data to pass to @func NB: maxcnt records default is 8000

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

Prepares next pileup position in bam records collected by bam_plp_auto -> user func -> bam_plp_push. Returns pointer to the piled records if next position is ready or NULL if there is not enough records in the buffer yet (the current position is still the maximum position across all buffered reads).

bam_plp_push
int bam_plp_push(bam_plp_t iter, const(bam1_t)* b)

add bam record to pileup iterator

bam_plp_reset
void bam_plp_reset(bam_plp_t iter)

reset pileup

bam_plp_set_maxcnt
void bam_plp_set_maxcnt(bam_plp_t iter, int maxcnt)

set maximum pileup records returned (init default is 8000)

bam_read1
int bam_read1(BGZF* fp, bam1_t* b)

read BAM record from fp

bam_seqi
auto bam_seqi(ubyte* s, uint i)

! @function @abstract Get a base on read @param s Query sequence returned by bam_get_seq() @param i The i-th position, 0-based @return 4-bit integer representing the base. /#define bam_seqi(s, i) ((s)[(i)>>1] >> ((~(i)&1)<<2) & 0xf)

bam_str2flag
int bam_str2flag(const(char)* str)

returns negative value on error

bam_write1
int bam_write1(BGZF* fp, const(bam1_t)* b)

write BAM record to fp

sam_cap_mapq
int sam_cap_mapq(bam1_t* b, const(char)* _ref, int ref_len, int thres)

BAQ calculation and realignment *

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

emit text SAM line

sam_hdr_change_HD
int sam_hdr_change_HD(bam_hdr_t* h, const(char)* key, const(char)* val)

edit SAM/BAM/CRAM header @HD line by key/value (see SAM specs section 1.3)

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

parse SAM/BAM/CRAM header from text

sam_hdr_read
bam_hdr_t* sam_hdr_read(samFile* fp)

read SAM/BAM/CRAM header frpm fp

sam_hdr_write
int sam_hdr_write(samFile* fp, const(bam_hdr_t)* h)

write SAM/BAM/CRAM header to fp

sam_index_build
int sam_index_build(const(char)* fn, int min_shift)

@param fn Input BAM/etc filename, to which .csi/etc will be added @param min_shift Positive to generate CSI, or 0 to generate BAI @return 0 if successful, or negative if an error occurred (usually -1; or -2: opening fn failed; -3: format not indexable; -4: failed to create and/or save the index)

sam_index_build2
int sam_index_build2(const(char)* fn, const(char)* fnidx, int min_shift)
sam_index_build3
int sam_index_build3(const(char)* fn, const(char)* fnidx, int min_shift, int nthreads)

@param fn Input BAM/CRAM/etc filename @param fnidx Output filename, or NULL to add .bai/.csi/etc to @a fn @param min_shift Positive to generate CSI, or 0 to generate BAI @return 0 if successful, or negative if an error occurred (see sam_index_build for error codes)

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

@param fp File handle of the data file whose index is being opened @param fn BAM/CRAM/etc filename to search alongside for the index file @return The index, or NULL if an error occurred.

sam_index_load2
hts_idx_t* sam_index_load2(htsFile* fp, const(char)* fn, const(char)* fnidx)

@param fp File handle of the data file whose index is being opened @param fn BAM/CRAM/etc data file filename @param fnidx Index filename, or NULL to search alongside @a fn @return The index, or NULL if an error occurred.

sam_itr_next
auto sam_itr_next(htsFile* htsfp, hts_itr_t* itr, void* r)

/#define sam_itr_next(htsfp, itr, r) hts_itr_next((htsfp)->fp.bgzf, (itr), (r), (htsfp))

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

SAM/BAM/CRAM iterator query by integer tid/start/end

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

SAM/BAM/CRAM iterator query by string ("chr:start-end")

sam_itr_regions
hts_itr_multi_t* sam_itr_regions(const(hts_idx_t)* idx, bam_hdr_t* hdr, hts_reglist_t* reglist, uint regcount)

SAM/BAM/CRAM iterator query by region list

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

open SAM/BAM/CRAM

sam_open_mode_opts
char* sam_open_mode_opts(const(char)* fn, const(char)* mode, const(char)* format)

A version of sam_open_mode that can handle ,key=value options. The format string is allocated and returned, to be freed by the caller. Prefix should be "r" or "w",

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

parse text SAM line

sam_prob_realn
int sam_prob_realn(bam1_t* b, const(char)* _ref, int ref_len, int flag)

@param b BAM record @param ref Reference sequence @param ref_len Reference sequence length @param flag Flags, see description @return 0 on success \n -1 if the read was unmapped, zero length, had no quality values, did not have at least one M, X or = CIGAR operator, or included a reference skip. \n -3 if BAQ alignment has already been done and does not need to be applied, or has already been applied. \n -4 if alignment failed (most likely due to running out of memory)

sam_read1
int sam_read1(samFile* fp, bam_hdr_t* h, bam1_t* b)

! @return >= 0 on successfully reading a new record, -1 on end of stream, < -1 on error

sam_write1
int sam_write1(samFile* fp, const(bam_hdr_t)* h, const(bam1_t)* b)

Return >= 0 on successfully writing a new record; <= -1 on error

Structs

__bam_mplp_t
struct __bam_mplp_t

opaque mpileup data defined in sam.c

__bam_plp_t
struct __bam_plp_t

opaque pileup data defined in sam.c

bam1_core_t
struct bam1_core_t

! @typedef @abstract Structure for core alignment information. @field tid chromosome ID, defined by bam_hdr_t @field pos 0-based leftmost coordinate @field bin bin calculated by bam_reg2bin() @field qual mapping quality @field l_qname length of the query name @field flag bitwise flag @field l_extranul length of extra NULs between qname & cigar (for alignment) @field n_cigar number of CIGAR operations @field l_qseq length of the query sequence (read) @field mtid chromosome ID of next read in template, defined by bam_hdr_t @field mpos 0-based leftmost coordinate of next read in template

bam1_t
struct bam1_t

! @typedef @abstract Structure for one alignment. @field core core information about the alignment @field l_data current length of bam1_t::data @field m_data maximum length of bam1_t::data @field data all variable-length data, concatenated; structure: qname-cigar-seq-qual-aux

bam_hdr_t
struct bam_hdr_t

! @typedef @abstract Structure for the alignment header. @field n_targets number of reference sequences @field l_text length of the plain text in the header @field target_len lengths of the reference sequences @field target_name names of the reference sequences @field text plain text @field sdict header dictionary

bam_pileup1_t
struct bam_pileup1_t

! @typedef @abstract Structure for one alignment covering the pileup position. @field b pointer to the alignment @field qpos position of the read base at the pileup site, 0-based @field indel indel length; 0 for no indel, positive for ins and negative for del @field level the level of the read in the "viewer" mode @field is_del 1 iff the base on the padded read is a deletion @field is_head ??? @field is_tail ??? @field is_refskip ??? @field aux ???

Unions

bam_pileup_cd
union bam_pileup_cd

** Pileup and Mpileup ***

Variables

BAM_CIGAR_MASK
enum int BAM_CIGAR_MASK;

internal

BAM_CIGAR_SHIFT
enum int BAM_CIGAR_SHIFT;

internal

BAM_CIGAR_STR
auto BAM_CIGAR_STR;

internal

BAM_CIGAR_TYPE
enum int BAM_CIGAR_TYPE;

internal magic const for bam_cigar_type()

BAM_FDUP
enum int BAM_FDUP;

! @abstract optical or PCR duplicate

BAM_FMREVERSE
enum int BAM_FMREVERSE;

! @abstract the mate is mapped to the reverse strand

BAM_FMUNMAP
enum int BAM_FMUNMAP;

! @abstract the mate is unmapped

BAM_FPAIRED
enum int BAM_FPAIRED;

! @abstract the read is paired in sequencing, no matter whether it is mapped in a pair

BAM_FPROPER_PAIR
enum int BAM_FPROPER_PAIR;

! @abstract the read is mapped in a proper pair

BAM_FQCFAIL
enum int BAM_FQCFAIL;

! @abstract QC failure

BAM_FREAD1
enum int BAM_FREAD1;

! @abstract this is read1

BAM_FREAD2
enum int BAM_FREAD2;

! @abstract this is read2

BAM_FREVERSE
enum int BAM_FREVERSE;

! @abstract the read is mapped to the reverse strand

BAM_FSECONDARY
enum int BAM_FSECONDARY;

! @abstract not primary alignment

BAM_FSUPPLEMENTARY
enum int BAM_FSUPPLEMENTARY;

! @abstract supplementary alignment

BAM_FUNMAP
enum int BAM_FUNMAP;

! @abstract the read itself is unmapped; conflictive with BAM_FPROPER_PAIR

SAM_FORMAT_VERSION
auto SAM_FORMAT_VERSION;

Highest SAM format version supported by this library

Meta