Imported Upstream version 0.2
[pysam.git] / pysam / csamtools.pxd
1
2 cdef extern from "string.h":
3   ctypedef int size_t
4   void *memcpy(void *dst,void *src,size_t len)
5   void *memmove(void *dst,void *src,size_t len)
6   void *memset(void *b,int c,size_t len)
7
8 cdef extern from "stdlib.h":
9   void free(void *)
10   void *malloc(size_t)
11   void *calloc(size_t,size_t)
12   void *realloc(void *,size_t)
13   int c_abs "abs" (int)
14   void qsort(void *base, size_t nmemb, size_t size,
15              int (*compar)(void *,void *))
16
17 cdef extern from "stdio.h":
18   ctypedef struct FILE:
19     pass
20   FILE *fopen(char *,char *)
21   FILE *freopen(char *path, char *mode, FILE *stream)
22   int fileno(FILE *stream)
23   int dup2(int oldfd, int newfd)
24   int fflush(FILE *stream)
25
26   FILE * stderr
27   FILE * stdout
28   int fclose(FILE *)
29   int sscanf(char *str,char *fmt,...)
30   int printf(char *str,char *fmt,...)
31   int sprintf(char *str,char *fmt,...)
32   int fprintf(FILE *ifile,char *fmt,...)
33   char *fgets(char *str,int size,FILE *ifile)
34
35 cdef extern from "ctype.h":
36   int toupper(int c)
37   int tolower(int c)
38   
39 cdef extern from "unistd.h":
40   char *ttyname(int fd)
41   int isatty(int fd)  
42
43 cdef extern from "string.h":
44   int strcmp(char *s1, char *s2)
45   int strncmp(char *s1,char *s2,size_t len)
46   char *strcpy(char *dest,char *src)
47   char *strncpy(char *dest,char *src, size_t len)
48   char *strdup(char *)
49   char *strcat(char *,char *)
50   size_t strlen(char *s)
51   int memcmp( void * s1, void *s2, size_t len )
52
53 cdef extern from "razf.h":
54   pass
55
56 cdef extern from "stdint.h":
57   ctypedef int int64_t
58   ctypedef int int32_t
59   ctypedef int uint32_t
60   ctypedef int uint8_t
61   ctypedef int uint64_t
62
63
64 cdef extern from "bam.h":
65
66   # IF _IOLIB=2, bamFile = BGZF, see bgzf.h
67   # samtools uses KNETFILE, check how this works
68
69   ctypedef struct tamFile:
70       pass
71
72   ctypedef struct bamFile:
73       pass
74
75   ctypedef struct bam1_core_t:
76       int32_t tid 
77       int32_t pos
78       uint32_t bin
79       uint32_t qual
80       uint32_t l_qname
81       uint32_t flag
82       uint32_t n_cigar
83       int32_t l_qseq
84       int32_t mtid 
85       int32_t mpos 
86       int32_t isize
87
88   ctypedef struct bam1_t:
89     bam1_core_t core
90     int l_aux
91     int data_len
92     int m_data
93     uint8_t *data
94
95   ctypedef struct bam_pileup1_t:
96       bam1_t *b 
97       int32_t qpos 
98       int indel
99       int level
100       uint32_t is_del
101       uint32_t is_head
102       uint32_t is_tail
103
104   ctypedef int (*bam_pileup_f)(uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *data)
105
106   ctypedef int (*bam_fetch_f)(bam1_t *b, void *data)
107
108   ctypedef struct bam_header_t:
109      int32_t n_targets
110      char **target_name
111      uint32_t *target_len
112      void *hash
113      void *rg2lib
114      int l_text
115      char *text
116
117   ctypedef struct bam_index_t:
118       pass
119
120   ctypedef struct bam_plbuf_t:
121       pass
122
123   bamFile razf_dopen(int data_fd, char *mode)
124
125   # removed - macros not found
126
127   # int64_t bam_seek( bamFile fp, uint64_t voffset, int where)
128   # int64_t bam_tell( bamFile fp )
129   # void bam_destroy1( bam1_t * b) 
130   # void bam_init_header_hash(bam_header_t *header)
131
132   bam1_t * bam_dup1( bam1_t *src ) 
133   
134   bam1_t * bam_copy1(bam1_t *bdst, bam1_t *bsrc)
135   bam_index_t *bam_index_load(char *f )
136
137   void bam_index_destroy(bam_index_t *idx)
138
139   int bam_parse_region(bam_header_t *header, char *str, int *ref_id, int *begin, int *end)
140
141   bam_plbuf_t *bam_plbuf_init(bam_pileup_f func, void *data)
142
143   int bam_fetch(bamFile fp, bam_index_t *idx, int tid, int beg, int end, void *data, bam_fetch_f func)
144
145   int bam_plbuf_push(bam1_t *b, bam_plbuf_t *buf)
146
147   void bam_plbuf_destroy(bam_plbuf_t *buf)
148
149   int bam_read1(bamFile fp, bam1_t *b)
150
151   int bam_write1( bamFile fp, bam1_t *b)
152
153   bam_header_t *bam_header_init()
154
155   int bam_header_write( bamFile fp, bam_header_t *header)
156
157   bam_header_t *bam_header_read( bamFile fp )
158
159   void bam_header_destroy(bam_header_t *header)
160
161   bam1_t * bam_dup1( bam1_t *src ) 
162   
163   bam1_t * bam_copy1(bam1_t *bdst, bam1_t *bsrc)
164
165   uint8_t *bam_aux_get(bam1_t *b,  char tag[2])
166
167   int bam_aux2i(uint8_t *s)
168   float bam_aux2f(uint8_t *s)
169   double bam_aux2d(uint8_t *s)
170   char bam_aux2A( uint8_t *s)
171   char *bam_aux2Z( uint8_t *s)
172   
173   int bam_reg2bin(uint32_t beg, uint32_t end)
174
175   uint32_t bam_calend(bam1_core_t *c, uint32_t *cigar)
176
177 cdef extern from "sam.h":
178
179   ctypedef struct samfile_t_un:
180     tamFile tamr
181     bamFile bam
182     FILE *tamw
183     
184   ctypedef struct samfile_t:
185      int type
186      samfile_t_un x
187      bam_header_t *header
188
189   samfile_t *samopen( char *fn, char * mode, void *aux)
190
191   int sampileup( samfile_t *fp, int mask, bam_pileup_f func, void *data)
192
193   void samclose(samfile_t *fp)
194
195   int samread(samfile_t *fp, bam1_t *b)
196
197   int samwrite(samfile_t *fp, bam1_t *b)
198
199 cdef extern from "faidx.h":
200
201    ctypedef struct faidx_t:
202       pass
203
204    int fai_build(char *fn)
205
206    void fai_destroy(faidx_t *fai)
207
208    faidx_t *fai_load(char *fn)
209
210    char *fai_fetch(faidx_t *fai, char *reg, int *len)
211
212 cdef extern from "pysam_util.h":
213
214     int pysam_bam_plbuf_push(bam1_t *b, bam_plbuf_t *buf, int cont)
215
216     int pysam_get_pos( bam_plbuf_t *buf)
217
218     int pysam_get_tid( bam_plbuf_t *buf)
219
220     bam_pileup1_t * pysam_get_pileup( bam_plbuf_t *buf)
221
222     int pysam_dispatch(int argc, char *argv[] )
223
224     # stand-in functions for samtools macros
225     void pysam_bam_destroy1( bam1_t * b) 
226
227     # add *nbytes* into the variable length data of *src* at *pos*
228     bam1_t * pysam_bam_update( bam1_t * b, 
229                                size_t nbytes_old,
230                                size_t nbytes_new,
231                                uint8_t * pos )
232
233     # translate char to unsigned char
234     unsigned char pysam_translate_sequence( char s )
235
236     # stand-ins for samtools macros
237     uint32_t * pysam_bam1_cigar( bam1_t * b)
238     char * pysam_bam1_qname( bam1_t * b)
239     uint8_t * pysam_bam1_seq( bam1_t * b)
240     uint8_t * pysam_bam1_qual( bam1_t * b)
241     uint8_t * pysam_bam1_aux( bam1_t * b)
242
243     # iterator implemenation
244     ctypedef struct bam_fetch_iterator_t:
245         pass
246   
247     bam_fetch_iterator_t* bam_init_fetch_iterator(bamFile fp, bam_index_t *idx, int tid, int beg, int end)
248   
249     bam1_t * bam_fetch_iterate(bam_fetch_iterator_t *iter)
250   
251     void bam_cleanup_fetch_iterator(bam_fetch_iterator_t *iter)