Imported Upstream version 0.2
[pysam.git] / pysam / pysam_util.h
1 #ifndef PYSAM_UTIL_H
2 #define PYSAM_UTIL_H
3
4 //////////////////////////////////////////////////////////////////
5 //////////////////////////////////////////////////////////////////
6 //////////////////////////////////////////////////////////////////
7 // code for iterator
8
9 /*! @typedef
10   @Structure for holding current state (current alignment etc.) for iterating through
11   alignments overlapping a specified region.
12   @field  b           pointer to the current alignment
13   @field  off         pointer to an array of chunk loci (each with beg/end positions)
14   @field  n_off       The number of chunks
15   @field  curr_off    The current file positon
16   @field  curr_chunk  The item in a list of chunk
17   @discussion See also bam_fetch_iterate
18 */
19 struct __bam_fetch_iterator_t;
20 typedef struct __bam_fetch_iterator_t bam_fetch_iterator_t;
21         
22 /*!
23   @abstract Retrieve the alignments that are overlapped with the
24   specified region.
25   
26   @discussion Returns iterator object to retrieve successive alignments ordered by
27   start position. 
28   @param  fp    BAM file handler
29   @param  idx   pointer to the alignment index
30   @param  tid   chromosome ID as is defined in the header
31   @param  beg   start coordinate, 0-based
32   @param  end   end coordinate, 0-based
33 */
34 bam_fetch_iterator_t * bam_init_fetch_iterator(bamFile fp, const bam_index_t *idx, int tid, int beg, int end);
35
36
37 /*!
38   @abstract Iterates through alignments overlapped the specified region.
39   @discussion Returns pointer to successive alignments ordered by start position.
40   Returns null pointer to signal the end of the iteration.
41   The alignment data is nested within the iterator to avoid unnecessary allocations.
42 */
43 bam1_t * bam_fetch_iterate(bam_fetch_iterator_t *iter);
44
45 bam_fetch_iterator_t* bam_init_fetchall_iterator(bamFile fp, const bam_index_t *idx);
46 bam1_t * bam_fetchall_iterate(bam_fetch_iterator_t *iter);
47
48 //////////////////////////////////////////////////////////////////
49 //////////////////////////////////////////////////////////////////
50 //////////////////////////////////////////////////////////////////
51 // various helper functions
52
53 int pysam_bam_plbuf_push(const bam1_t *b, bam_plbuf_t *buf, int cont);
54
55 // accessor functions - necessary as bam_plbuf_t is hidden
56 // among the implementation
57 int pysam_get_pos( const bam_plbuf_t *buf);
58 int pysam_get_tid( const bam_plbuf_t *buf);
59 bam_pileup1_t * pysam_get_pileup( const bam_plbuf_t *buf);
60
61 int pysam_dispatch(int argc, char *argv[] );
62
63 // stand-in for macro - not wrappable in pyrex
64 void pysam_bam_destroy1( bam1_t * b );
65
66 // stand-in for other samtools macros
67 uint32_t * pysam_bam1_cigar( const bam1_t * b);
68 char * pysam_bam1_qname( const bam1_t * b);
69 uint8_t * pysam_bam1_seq( const bam1_t * b);
70 uint8_t * pysam_bam1_qual( const bam1_t * b);
71 uint8_t * pysam_bam1_aux( const bam1_t * b);
72
73 /*!
74   @abstract Update the variable length data within a bam1_t entry
75
76   Old data is deleted and the data within b are re-arranged to 
77   make place for new data.
78   
79   @discussion Returns b
80
81   @param  b           bam1_t data
82   @param  nbytes_old  size of old data
83   @param  nbytes_new  size of new data
84   @param  pos         position of data
85 */
86 bam1_t * pysam_bam_update( bam1_t * b,
87                            const size_t nbytes_old,
88                            const size_t nbytes_new,
89                            uint8_t * pos );
90
91 // translate a nucleotide character to binary code
92 unsigned char pysam_translate_sequence( const unsigned char s );
93
94
95 #endif