sam.h


Includes: "bam.h"
Discussion



This file provides higher level of I/O routines and unifies the APIs for SAM and BAM formats. These APIs are more convenient and recommended.



Functions

samopen
Open a SAM/BAM file
samclose
Close a SAM/BAM handler
samread
Read one alignment
samwrite
Write one alignment
sampileup
Get the pileup for a whole alignment file

samopen


Open a SAM/BAM file

samfile_t *samopen(
    const char *fn,
    const char *mode,
    const void *aux);  
Parameters
fn
SAM/BAM file name; "-" is recognized as stdin (for reading) or stdout (for writing).

mode
open mode /[rw](b?)(u?)(h?)/: 'r' for reading, 'w' for writing, 'b' for BAM I/O, 'u' for uncompressed BAM output and 'h' for outputing header in SAM. If 'b' present, it must immediately follow 'r' or 'w'. Valid modes are "r", "w", "wh", "rb", "wb" and "wbu" exclusively.

aux
auxiliary data; if mode[0]=='w', aux points to bam_header_t; if strcmp(mode, "rb")==0 and @SQ header lines in SAM are absent, aux points the file name of the list of the reference; aux is not used otherwise.

Return Value

SAM/BAM file handler


samclose


Close a SAM/BAM handler

void samclose(
    samfile_t *fp);  
Parameters
fp
file handler to be closed


samread


Read one alignment

int samread(
    samfile_t *fp,
    bam1_t *b);  
Parameters
fp
file handler
b
alignment
Return Value

bytes read


samwrite


Write one alignment

int samwrite(
    samfile_t *fp,
    const bam1_t *b);  
Parameters
fp
file handler
b
alignment
Return Value

bytes written


sampileup


Get the pileup for a whole alignment file

int sampileup(
    samfile_t *fp,
    int mask,
    bam_pileup_f func,
    void *data);  
Parameters
fp
file handler
mask
mask transferred to bam_plbuf_set_mask()
func
user defined function called in the pileup process #param data user provided data for func()

Typedefs


samfile_t


SAM/BAM file handler

typedef struct { 
    int type; 
    union { 
        tamFile tamr; 
        bamFile bam; 
        FILE *tamw; 
        } x; 
    bam_header_t *header; 
} samfile_t;  
Fields
type
type of the handler; bit 1 for BAM and bit 2 for reading
bam
BAM file handler; valid if (type&1) == 1
tamr
SAM file handler for reading; valid if type == 2
tamw
SAM file handler for writing; valid if type == 0
header
header struct

© Genome Research Ltd. Last Updated: Saturday, June 13, 2009