1 cdef extern from "string.h":
3 void *memcpy(void *dst,void *src,size_t len)
4 void *memmove(void *dst,void *src,size_t len)
5 void *memset(void *b,int c,size_t len)
7 cdef extern from "stdlib.h":
10 void *calloc(size_t,size_t)
11 void *realloc(void *,size_t)
13 void qsort(void *base, size_t nmemb, size_t size,
14 int (*compar)(void *,void *))
16 cdef extern from "math.h":
19 cdef extern from "stdio.h":
22 FILE *fopen(char *,char *)
23 FILE *freopen(char *path, char *mode, FILE *stream)
24 int fileno(FILE *stream)
25 int dup2(int oldfd, int newfd)
26 int fflush(FILE *stream)
31 int sscanf(char *str,char *fmt,...)
32 int printf(char *fmt,...)
33 int sprintf(char *str,char *fmt,...)
34 int fprintf(FILE *ifile,char *fmt,...)
35 char *fgets(char *str,int size,FILE *ifile)
37 cdef extern from "ctype.h":
41 cdef extern from "unistd.h":
45 cdef extern from "string.h":
46 int strcmp(char *s1, char *s2)
47 int strncmp(char *s1,char *s2,size_t len)
48 char *strcpy(char *dest,char *src)
49 char *strncpy(char *dest,char *src, size_t len)
51 char *strcat(char *,char *)
52 size_t strlen(char *s)
53 int memcmp( void * s1, void *s2, size_t len )
55 cdef extern from "Python.h":
56 long _Py_HashPointer(void*)
57 FILE* PyFile_AsFile(object)
59 cdef extern from "fileobject.h":
60 ctypedef class __builtin__.file [object PyFileObject]:
63 cdef extern from "razf.h":
66 cdef extern from "stdint.h":
73 cdef extern from "bam.h":
77 # IF _IOLIB=2, bamFile = BGZF, see bgzf.h
78 # samtools uses KNETFILE, check how this works
80 ctypedef struct tamFile:
83 ctypedef struct bamFile:
86 ctypedef struct bam1_core_t:
99 ctypedef struct bam1_t:
106 ctypedef struct bam_pileup1_t:
115 ctypedef int (*bam_pileup_f)(uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *data)
117 ctypedef int (*bam_fetch_f)(bam1_t *b, void *data)
119 ctypedef struct bam_header_t:
128 ctypedef struct bam_index_t:
131 ctypedef struct bam_plbuf_t:
134 ctypedef struct pair64_t:
137 ctypedef struct bam_iter_t:
139 int tid, beg, end, n_off, i, finished
143 # ctypedef __bam_iter_t * bam_iter_t
146 void bam_destroy1(bam1_t *)
148 bamFile razf_dopen(int data_fd, char *mode)
150 int64_t bam_seek( bamFile fp, uint64_t voffset, int where)
151 int64_t bam_tell( bamFile fp )
153 # void bam_init_header_hash(bam_header_t *header)
155 ###############################################
156 # stand-ins for samtools macros
157 uint32_t * bam1_cigar( bam1_t * b)
158 char * bam1_qname( bam1_t * b)
159 uint8_t * bam1_seq( bam1_t * b)
160 uint8_t * bam1_qual( bam1_t * b)
161 uint8_t * bam1_aux( bam1_t * b)
163 ###############################################
164 # bam iterator interface
165 bam_iter_t bam_iter_query( bam_index_t *idx, int tid, int beg, int end)
167 int bam_iter_read(bamFile fp, bam_iter_t iter, bam1_t *b)
169 void bam_iter_destroy(bam_iter_t iter)
171 ###############################################
173 bam1_t * bam_dup1( bam1_t *src )
175 bam1_t * bam_copy1(bam1_t *bdst, bam1_t *bsrc)
176 bam_index_t *bam_index_load(char *f )
178 void bam_index_destroy(bam_index_t *idx)
180 int bam_parse_region(bam_header_t *header, char *str, int *ref_id, int *begin, int *end)
182 ###############################################
183 bam_plbuf_t *bam_plbuf_init(bam_pileup_f func, void *data)
185 int bam_fetch(bamFile fp, bam_index_t *idx, int tid, int beg, int end, void *data, bam_fetch_f func)
187 int bam_plbuf_push(bam1_t *b, bam_plbuf_t *buf)
189 void bam_plbuf_destroy(bam_plbuf_t *buf)
190 ########################################
191 # pileup iterator interface
192 ctypedef struct bam_plp_t:
195 ctypedef bam_pileup1_t * const_bam_pileup1_t_ptr "const bam_pileup1_t *"
197 ctypedef int (*bam_plp_auto_f)(void *data, bam1_t *b)
199 bam_plp_t bam_plp_init( bam_plp_auto_f func, void *data)
200 int bam_plp_push( bam_plp_t iter, bam1_t *b)
201 bam_pileup1_t * bam_plp_next( bam_plp_t iter, int *_tid, int *_pos, int *_n_plp)
202 bam_pileup1_t * bam_plp_auto( bam_plp_t iter, int *_tid, int *_pos, int *_n_plp)
203 void bam_plp_set_mask(bam_plp_t iter, int mask)
204 void bam_plp_reset(bam_plp_t iter)
205 void bam_plp_destroy(bam_plp_t iter)
207 ##################################################
209 int bam_read1( bamFile fp, bam1_t *b)
210 int bam_validate1( bam_header_t *header, bam1_t *b)
211 int bam_write1( bamFile fp, bam1_t *b)
213 bam_header_t *bam_header_init()
215 int bam_header_write( bamFile fp, bam_header_t *header)
217 bam_header_t *bam_header_read( bamFile fp )
219 void bam_header_destroy(bam_header_t *header)
221 bam1_t * bam_dup1( bam1_t *src )
223 bam1_t * bam_copy1(bam1_t *bdst, bam1_t *bsrc)
225 uint8_t *bam_aux_get(bam1_t *b, char tag[2])
227 int32_t bam_aux2i(uint8_t *s)
228 float bam_aux2f(uint8_t *s)
229 double bam_aux2d(uint8_t *s)
230 char bam_aux2A( uint8_t *s)
231 char *bam_aux2Z( uint8_t *s)
233 int bam_reg2bin(uint32_t beg, uint32_t end)
235 uint32_t bam_calend(bam1_core_t *c, uint32_t *cigar)
238 ctypedef char* const_char_ptr "const char*"
240 cdef extern from "sam.h":
242 ctypedef struct samfile_t_un:
247 ctypedef struct samfile_t:
252 samfile_t *samopen( const_char_ptr fn, char * mode, void *aux)
254 int sampileup( samfile_t *fp, int mask, bam_pileup_f func, void *data)
256 void samclose(samfile_t *fp)
258 int samread(samfile_t *fp, bam1_t *b)
260 int samwrite(samfile_t *fp, bam1_t *b)
262 int bam_prob_realn(bam1_t *b, char *ref)
263 int bam_cap_mapQ(bam1_t *b, char *ref, int thres)
266 cdef extern from "glf.h":
267 ctypedef struct glf1_t:
270 cdef extern from "bam_maqcns.h":
272 ctypedef struct bam_maqcns_t:
273 float het_rate, theta
274 int n_hap, cap_mapQ, errmod, min_baseQ
280 glf1_t *bam_maqcns_glfgen(int n,
285 ctypedef struct bam_maqindel_opt_t:
289 int mm_penalty, indel_err, ambi_thres
291 uint32_t bam_maqcns_call(int n, bam_pileup1_t *pl, bam_maqcns_t *bm)
292 bam_maqcns_t * bam_maqcns_init()
293 void bam_maqcns_destroy(bam_maqcns_t *bm)
294 void bam_maqcns_prepare(bam_maqcns_t *bm)
296 uint32_t glf2cns(glf1_t *g, int q_r)
302 ctypedef struct bam_maqindel_ret_t:
316 void bam_maqindel_ret_destroy( bam_maqindel_ret_t * )
318 bam_maqindel_opt_t *bam_maqindel_opt_init()
320 bam_maqindel_ret_t * bam_maqindel(int n,
322 bam_maqindel_opt_t * mi,
329 cdef extern from "faidx.h":
331 ctypedef struct faidx_t:
334 int fai_build(char *fn)
336 void fai_destroy(faidx_t *fai)
338 faidx_t *fai_load(char *fn)
340 char *fai_fetch(faidx_t *fai, char *reg, int *len)
342 int faidx_fetch_nseq(faidx_t *fai)
344 char *faidx_fetch_seq(faidx_t *fai, char *c_name,
345 int p_beg_i, int p_end_i, int *len)
348 cdef extern from "pysam_util.h":
350 int pysam_pileup_next(bam1_t *b,
352 bam_pileup1_t ** plp,
358 int pysam_dispatch(int argc, char *argv[] )
360 # stand-in functions for samtools macros
361 void pysam_bam_destroy1( bam1_t * b)
363 # add *nbytes* into the variable length data of *src* at *pos*
364 bam1_t * pysam_bam_update( bam1_t * b,
369 # translate char to unsigned char
370 unsigned char pysam_translate_sequence( char s )
372 unsigned char * bam_nt16_table
374 int pysam_reference2tid( bam_header_t *header, char * s )
376 void pysam_set_stderr( FILE * file )
378 uint32_t pysam_glf_depth( glf1_t * g )
380 void pysam_dump_glf( glf1_t * g, bam_maqcns_t * c )
382 # need to declare all C fields and methods here
383 cdef class AlignedRead:
385 # object that this AlignedRead represents
386 cdef bam1_t * _delegate
389 cdef char * _filename
391 cdef samfile_t * samfile
393 cdef bam_index_t *index
394 # true if file is a bam file
396 # true if file is not on the local filesystem
398 # current read within iteration
403 cdef bam_header_t * _buildHeader( self, new_header )
404 cdef bam1_t * getCurrent( self )
407 # write an aligned read
408 cpdef int write( self, AlignedRead read )
410 cdef char * _getrname( self, int tid )