Imported Upstream version 0.5
[pysam.git] / pysam / ctabix.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   char *strtok_r(char *str, char *delim, char **saveptr)
8   char *strncpy(char *dest, char *src, size_t n)
9   void *memchr(void *s, int c, size_t n)
10
11 cdef extern from "stdlib.h":
12   void free(void *)
13   void *malloc(size_t)
14   void *calloc(size_t,size_t)
15   void *realloc(void *,size_t)
16   void qsort(void *base, size_t nmemb, size_t size,
17              int (*compar)(void *,void *))
18   int c_abs "abs" (int)
19   int atoi( char *nptr)
20   long atol( char *nptr)
21   double atof( char *nptr)
22
23 cdef extern from "stdio.h":
24   ctypedef struct FILE:
25     pass
26   FILE *fopen(char *,char *)
27   FILE *freopen(char *path, char *mode, FILE *stream)
28   int fileno(FILE *stream)
29   int dup2(int oldfd, int newfd)
30   int fflush(FILE *stream)
31
32   FILE * stderr
33   FILE * stdout
34   int fclose(FILE *)
35   int sscanf(char *str,char *fmt,...)
36   int printf(char *str,char *fmt,...)
37   int sprintf(char *str,char *fmt,...)
38   int fprintf(FILE *ifile,char *fmt,...)
39   char *fgets(char *str,int size,FILE *ifile)
40
41 cdef extern from "ctype.h":
42   int toupper(int c)
43   int tolower(int c)
44
45 cdef extern from "sys/types.h":
46   pass
47
48 cdef extern from "sys/stat.h":
49   pass
50
51 cdef extern from "fcntl.h":
52   int open(char *pathname, int flags)
53   
54 cdef extern from "unistd.h":
55   ctypedef int ssize_t
56   char *ttyname(int fd)
57   int isatty(int fd)  
58   ssize_t read(int fd, void *buf, size_t count)
59
60 cdef extern from "string.h":
61   int strcmp(char *s1, char *s2)
62   int strncmp(char *s1,char *s2,size_t len)
63   char *strcpy(char *dest,char *src)
64   char *strncpy(char *dest,char *src, size_t len)
65   char *strdup(char *)
66   char *strcat(char *,char *)
67   size_t strlen(char *s)
68   int memcmp( void * s1, void *s2, size_t len )
69
70 cdef extern from "stdint.h":
71   ctypedef int int64_t
72   ctypedef int int32_t
73   ctypedef int uint32_t
74   ctypedef int uint8_t
75   ctypedef int uint64_t
76
77 cdef extern from "Python.h":
78     ctypedef struct FILE
79     FILE* PyFile_AsFile(object)
80     char *fgets(char *str, int size, FILE *ifile)
81     int feof(FILE *stream)
82     size_t strlen(char *s)
83     size_t getline(char **lineptr, size_t *n, FILE *stream)
84     char *strstr(char *, char *)
85     char *strchr(char *string, int c)
86     int fileno(FILE *stream)
87
88 cdef extern from "bgzf.h":
89
90   ctypedef struct BGZF:
91     pass
92
93   int64_t bgzf_seek(BGZF* fp, int64_t pos, int where)
94
95   BGZF * bgzf_open(char * path, char * mode)
96
97   int bgzf_write(BGZF * fp, void* data, int length)
98
99   int bgzf_close(BGZF* fp)
100
101 # tabix support
102 cdef extern from "tabix.h":
103
104   ctypedef struct ti_conf_t:
105     int32_t preset
106     int32_t sc, bc, ec
107     int32_t meta_char, line_skip
108
109   ctypedef struct ti_index_t:
110      pass
111       
112   ctypedef struct tabix_t: 
113     BGZF *fp
114     ti_index_t *idx
115     char *fn
116     char *fnidx
117
118   ctypedef struct ti_iter_t:
119     pass
120
121   tabix_t *ti_open(char *fn, char *fnidx)
122
123   int ti_lazy_index_load(tabix_t *t)
124
125   void ti_close(tabix_t *t)
126
127   ti_iter_t ti_query(tabix_t *t, char *name, int beg, int end)
128   ti_iter_t ti_queryi(tabix_t *t, int tid, int beg, int end)
129   ti_iter_t ti_querys(tabix_t *t, char *reg)
130   char * ti_read(tabix_t *t, ti_iter_t iter, int *len)
131
132   # Get the list of sequence names. Each "char*" pointer points to a
133   #     internal member of the index, so DO NOT modify the returned
134   #      pointer; otherwise the index will be corrupted. The returned
135   #     pointer should be freed by a single free() call by the routine
136   #     calling this function. The number of sequences is returned at *n
137   char **ti_seqname(ti_index_t *idx, int *n)
138   
139   # Destroy the iterator
140   void ti_iter_destroy(ti_iter_t iter)
141
142   # Build the index for file <fn>. File <fn>.tbi will be generated
143   # and overwrite the file of the same name. Return -1 on failure. */
144   int ti_index_build(char *fn, ti_conf_t *conf)
145
146   #/* Load the index from file <fn>.tbi. If <fn> is a URL and the index
147   #   * file is not in the working directory, <fn>.tbi will be
148   #   * downloaded. Return NULL on failure. */
149   ti_index_t *ti_index_load( char *fn)
150
151   ti_index_t *ti_index_load_local(char *fnidx)
152
153   #/* Destroy the index */
154   void ti_index_destroy(ti_index_t *idx)
155
156   #/* Parse a region like: chr2, chr2:100, chr2:100-200. Return -1 on failure. */
157   int ti_parse_region( ti_index_t *idx,  char *str, int *tid, int *begin, int *end)
158
159   int ti_get_tid( ti_index_t *idx,  char *name)
160
161   #  /* Get the iterator pointing to the first record at the current file
162   #   * position. If the file is just openned, the iterator points to the
163   #   * first record in the file. */
164   ti_iter_t ti_iter_first()
165
166   #  /* Get the iterator pointing to the first record in region tid:beg-end */
167   ti_iter_t ti_iter_query( ti_index_t *idx, int tid, int beg, int end)
168
169   #  /* Get the data line pointed by the iterator and iterate to the next record. */
170   # char *ti_iter_read(BGZF *fp, ti_iter_t iter, int *len)
171
172 cdef class Tabixfile:
173     cdef char * filename
174
175     # pointer to tabixfile
176     cdef tabix_t * tabixfile
177      
178 cdef class Parser:
179      pass