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:
132 ctypedef struct bam_plbuf_t:
135 ctypedef struct pair64_t:
138 ctypedef struct bam_iter_t:
140 int tid, beg, end, n_off, i, finished
144 # ctypedef __bam_iter_t * bam_iter_t
147 void bam_destroy1(bam1_t *)
149 bamFile razf_dopen(int data_fd, char *mode)
151 int64_t bam_seek( bamFile fp, uint64_t voffset, int where)
152 int64_t bam_tell( bamFile fp )
154 # void bam_init_header_hash(bam_header_t *header)
156 ###############################################
157 # stand-ins for samtools macros
158 uint32_t * bam1_cigar( bam1_t * b)
159 char * bam1_qname( bam1_t * b)
160 uint8_t * bam1_seq( bam1_t * b)
161 uint8_t * bam1_qual( bam1_t * b)
162 uint8_t * bam1_aux( bam1_t * b)
164 ###############################################
165 # bam iterator interface
166 bam_iter_t bam_iter_query( bam_index_t *idx, int tid, int beg, int end)
168 int bam_iter_read(bamFile fp, bam_iter_t iter, bam1_t *b)
170 void bam_iter_destroy(bam_iter_t iter)
172 ###############################################
174 bam1_t * bam_dup1( bam1_t *src )
176 bam1_t * bam_copy1(bam1_t *bdst, bam1_t *bsrc)
177 bam_index_t *bam_index_load(char *f )
179 void bam_index_destroy(bam_index_t *idx)
181 int bam_parse_region(bam_header_t *header, char *str, int *ref_id, int *begin, int *end)
183 ###############################################
184 bam_plbuf_t *bam_plbuf_init(bam_pileup_f func, void *data)
186 int bam_fetch(bamFile fp, bam_index_t *idx, int tid, int beg, int end, void *data, bam_fetch_f func)
188 int bam_plbuf_push(bam1_t *b, bam_plbuf_t *buf)
190 void bam_plbuf_destroy(bam_plbuf_t *buf)
191 ########################################
192 # pileup iterator interface
193 ctypedef struct bam_plp_t:
196 ctypedef bam_pileup1_t * const_bam_pileup1_t_ptr "const bam_pileup1_t *"
198 ctypedef int (*bam_plp_auto_f)(void *data, bam1_t *b)
200 bam_plp_t bam_plp_init( bam_plp_auto_f func, void *data)
201 int bam_plp_push( bam_plp_t iter, bam1_t *b)
202 bam_pileup1_t * bam_plp_next( bam_plp_t iter, int *_tid, int *_pos, int *_n_plp)
203 bam_pileup1_t * bam_plp_auto( bam_plp_t iter, int *_tid, int *_pos, int *_n_plp)
204 void bam_plp_set_mask(bam_plp_t iter, int mask)
205 void bam_plp_reset(bam_plp_t iter)
206 void bam_plp_destroy(bam_plp_t iter)
207 void bam_plp_set_maxcnt(bam_plp_t iter, int maxcnt)
209 ##################################################
211 int bam_read1( bamFile fp, bam1_t *b)
212 int bam_validate1( bam_header_t *header, bam1_t *b)
213 int bam_write1( bamFile fp, bam1_t *b)
215 bam_header_t *bam_header_init()
217 int bam_header_write( bamFile fp, bam_header_t *header)
219 bam_header_t *bam_header_read( bamFile fp )
221 void bam_header_destroy(bam_header_t *header)
223 bam1_t * bam_dup1( bam1_t *src )
225 bam1_t * bam_copy1(bam1_t *bdst, bam1_t *bsrc)
227 uint8_t *bam_aux_get(bam1_t *b, char tag[2])
229 int32_t bam_aux2i(uint8_t *s)
230 float bam_aux2f(uint8_t *s)
231 double bam_aux2d(uint8_t *s)
232 char bam_aux2A( uint8_t *s)
233 char *bam_aux2Z( uint8_t *s)
235 int bam_reg2bin(uint32_t beg, uint32_t end)
237 uint32_t bam_calend(bam1_core_t *c, uint32_t *cigar)
240 ctypedef char* const_char_ptr "const char*"
242 cdef extern from "sam.h":
244 ctypedef struct samfile_t_un:
249 ctypedef struct samfile_t:
254 samfile_t *samopen( const_char_ptr fn, char * mode, void *aux)
256 int sampileup( samfile_t *fp, int mask, bam_pileup_f func, void *data)
258 void samclose(samfile_t *fp)
260 int samread(samfile_t *fp, bam1_t *b)
262 int samwrite(samfile_t *fp, bam1_t *b)
264 int bam_prob_realn(bam1_t *b, char *ref)
265 int bam_cap_mapQ(bam1_t *b, char *ref, int thres)
268 #cdef extern from "glf.h":
269 # ctypedef struct glf1_t:
272 #cdef extern from "bam_maqcns.h":
274 # ctypedef struct bam_maqcns_t:
275 # float het_rate, theta
276 # int n_hap, cap_mapQ, errmod, min_baseQ
282 # glf1_t *bam_maqcns_glfgen(int n,
287 # ctypedef struct bam_maqindel_opt_t:
291 # int mm_penalty, indel_err, ambi_thres
293 # uint32_t bam_maqcns_call(int n, bam_pileup1_t *pl, bam_maqcns_t *bm)
294 # bam_maqcns_t * bam_maqcns_init()
295 # void bam_maqcns_destroy(bam_maqcns_t *bm)
296 # void bam_maqcns_prepare(bam_maqcns_t *bm)
298 # uint32_t glf2cns(glf1_t *g, int q_r)
300 # int BAM_ERRMOD_MAQ2
302 # int BAM_ERRMOD_SOAP
304 # ctypedef struct bam_maqindel_ret_t:
318 # void bam_maqindel_ret_destroy( bam_maqindel_ret_t * )
320 # bam_maqindel_opt_t *bam_maqindel_opt_init()
322 # bam_maqindel_ret_t * bam_maqindel(int n,
324 # bam_maqindel_opt_t * mi,
325 # bam_pileup1_t * pl,
331 cdef extern from "faidx.h":
333 ctypedef struct faidx_t:
336 int fai_build(char *fn)
338 void fai_destroy(faidx_t *fai)
340 faidx_t *fai_load(char *fn)
342 char *fai_fetch(faidx_t *fai, char *reg, int *len)
344 int faidx_fetch_nseq(faidx_t *fai)
346 char *faidx_fetch_seq(faidx_t *fai, char *c_name,
347 int p_beg_i, int p_end_i, int *len)
350 cdef extern from "pysam_util.h":
352 int pysam_pileup_next(bam1_t *b,
354 bam_pileup1_t ** plp,
360 int pysam_dispatch(int argc, char *argv[] )
362 # stand-in functions for samtools macros
363 void pysam_bam_destroy1( bam1_t * b)
365 # add *nbytes* into the variable length data of *src* at *pos*
366 bam1_t * pysam_bam_update( bam1_t * b,
371 # translate char to unsigned char
372 unsigned char pysam_translate_sequence( char s )
374 unsigned char * bam_nt16_table
376 int pysam_reference2tid( bam_header_t *header, char * s )
378 void pysam_set_stderr( FILE * file )
380 # return mapped/unmapped reads on tid
381 uint32_t pysam_get_mapped( bam_index_t *idx, int tid )
382 uint32_t pysam_get_unmapped( bam_index_t *idx, int tid )
384 # uint32_t pysam_glf_depth( glf1_t * g )
386 # void pysam_dump_glf( glf1_t * g, bam_maqcns_t * c )
388 # need to declare all C fields and methods here
389 cdef class AlignedRead:
391 # object that this AlignedRead represents
392 cdef bam1_t * _delegate
395 cdef char * _filename
397 cdef samfile_t * samfile
399 cdef bam_index_t *index
400 # true if file is a bam file
402 # true if not a file but a stream
404 # true if file is not on the local filesystem
406 # current read within iteration
411 # beginning of read section
412 cdef int64_t start_offset
414 cdef bam_header_t * _buildHeader( self, new_header )
415 cdef bam1_t * getCurrent( self )
418 # write an aligned read
419 cpdef int write( self, AlignedRead read )
421 cdef char * _getrname( self, int tid )
423 cdef class IteratorRow:
426 cdef class IteratorRowAll(IteratorRow):
429 # true if samfile belongs to this object
430 cdef int owns_samfile
432 cdef bam1_t * getCurrent( self )