]> git.donarmstrong.com Git - samtools.git/blob - sam.h
* samtools-0.1.5-17 (r416)
[samtools.git] / sam.h
1 #ifndef BAM_SAM_H
2 #define BAM_SAM_H
3
4 #include "bam.h"
5
6 /*!
7   @header
8
9   This file provides higher level of I/O routines and unifies the APIs
10   for SAM and BAM formats. These APIs are more convenient and
11   recommended.
12
13   @copyright Genome Research Ltd.
14  */
15
16 /*! @typedef
17   @abstract SAM/BAM file handler
18   @field  type    type of the handler; bit 1 for BAM, 2 for reading and bit 3-4 for flag format
19   @field  bam   BAM file handler; valid if (type&1) == 1
20   @field  tamr  SAM file handler for reading; valid if type == 2
21   @field  tamw  SAM file handler for writing; valid if type == 0
22   @field  header  header struct
23  */
24 typedef struct {
25         int type;
26         union {
27                 tamFile tamr;
28                 bamFile bam;
29                 FILE *tamw;
30         } x;
31         bam_header_t *header;
32 } samfile_t;
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38         /*!
39           @abstract     Open a SAM/BAM file
40
41           @param fn SAM/BAM file name; "-" is recognized as stdin (for
42           reading) or stdout (for writing).
43
44           @param mode open mode /[rw](b?)(u?)(h?)([xX]?)/: 'r' for reading,
45           'w' for writing, 'b' for BAM I/O, 'u' for uncompressed BAM output,
46           'h' for outputing header in SAM, 'x' for HEX flag and 'X' for
47           string flag. If 'b' present, it must immediately follow 'r' or
48           'w'. Valid modes are "r", "w", "wh", "wx", "whx", "wX", "whX",
49           "rb", "wb" and "wbu" exclusively.
50
51           @param aux auxiliary data; if mode[0]=='w', aux points to
52           bam_header_t; if strcmp(mode, "rb")!=0 and @SQ header lines in SAM
53           are absent, aux points the file name of the list of the reference;
54           aux is not used otherwise.
55
56           @return       SAM/BAM file handler
57          */
58         samfile_t *samopen(const char *fn, const char *mode, const void *aux);
59
60         /*!
61           @abstract     Close a SAM/BAM handler
62           @param  fp    file handler to be closed
63          */
64         void samclose(samfile_t *fp);
65
66         /*!
67           @abstract     Read one alignment
68           @param  fp    file handler
69           @param  b     alignment
70           @return       bytes read
71          */
72         int samread(samfile_t *fp, bam1_t *b);
73
74         /*!
75           @abstract     Write one alignment
76           @param  fp    file handler
77           @param  b     alignment
78           @return       bytes written
79          */
80         int samwrite(samfile_t *fp, const bam1_t *b);
81
82         /*!
83           @abstract     Get the pileup for a whole alignment file
84           @param  fp    file handler
85           @param  mask  mask transferred to bam_plbuf_set_mask()
86           @param  func  user defined function called in the pileup process
87           #param  data  user provided data for func()
88          */
89         int sampileup(samfile_t *fp, int mask, bam_pileup_f func, void *data);
90
91 #ifdef __cplusplus
92 }
93 #endif
94
95 #endif