61 #define CRAM_KEY(a,b) (((a)<<8)|((b)))
80 int itf8_get(
char *cp, int32_t *val_p);
95 #define itf8_get(c,v) (((uc)(c)[0]<0x80)?(*(v)=(uc)(c)[0],1):(((uc)(c)[0]<0xc0)?(*(v)=(((uc)(c)[0]<<8)|(uc)(c)[1])&0x3fff,2):(((uc)(c)[0]<0xe0)?(*(v)=(((uc)(c)[0]<<16)|((uc)(c)[1]<<8)|(uc)(c)[2])&0x1fffff,3):(((uc)(c)[0]<0xf0)?(*(v)=(((uc)(c)[0]<<24)|((uc)(c)[1]<<16)|((uc)(c)[2]<<8)|(uc)(c)[3])&0x0fffffff,4):(*(v)=(((uc)(c)[0]&0x0f)<<28)|((uc)(c)[1]<<20)|((uc)(c)[2]<<12)|((uc)(c)[3]<<4)|((uc)(c)[4]&0x0f),5)))))
97 #define itf8_put(c,v) ((!((v)&~0x7f))?((c)[0]=(v),1):(!((v)&~0x3fff))?((c)[0]=((v)>>8)|0x80,(c)[1]=(v)&0xff,2):(!((v)&~0x1fffff))?((c)[0]=((v)>>16)|0xc0,(c)[1]=((v)>>8)&0xff,(c)[2]=(v)&0xff,3):(!((v)&~0xfffffff))?((c)[0]=((v)>>24)|0xe0,(c)[1]=((v)>>16)&0xff,(c)[2]=((v)>>8)&0xff,(c)[3]=(v)&0xff,4):((c)[0]=0xf0|(((v)>>28)&0xff),(c)[1]=((v)>>20)&0xff,(c)[2]=((v)>>12)&0xff,(c)[3]=((v)>>4)&0xff,(c)[4]=(v)&0xf,5))
99 #define itf8_size(v) ((!((v)&~0x7f))?1:(!((v)&~0x3fff))?2:(!((v)&~0x1fffff))?3:(!((v)&~0xfffffff))?4:5)
182 int method,
int level);
191 #define BLOCK_SIZE(b) ((b)->byte)
192 #define BLOCK_DATA(b) ((b)->data)
195 #define BLOCK_END(b) (&(b)->data[(b)->byte])
198 #define BLOCK_RESIZE(b,l) \
200 while((b)->alloc <= (l)) { \
201 (b)->alloc = (b)->alloc ? (b)->alloc*1.5 : 1024; \
202 (b)->data = realloc((b)->data, (b)->alloc); \
207 #define BLOCK_GROW(b,l) BLOCK_RESIZE((b), BLOCK_SIZE((b)) + (l))
210 #define BLOCK_APPEND(b,s,l) \
212 BLOCK_GROW((b),(l)); \
213 memcpy(BLOCK_END((b)), (s), (l)); \
214 BLOCK_SIZE((b)) += (l); \
218 #define BLOCK_APPEND_CHAR(b,c) \
221 (b)->data[(b)->byte++] = (c); \
225 #define BLOCK_APPEND_UINT(b,i) \
228 BLOCK_GROW((b),11); \
229 cp = &(b)->data[(b)->byte]; \
230 (b)->byte += append_uint(cp, (i)) - cp; \
233 static inline unsigned char *append_uint(
unsigned char *cp, int32_t i) {
241 if (i < 100)
goto b1;
242 if (i < 10000)
goto b3;
243 if (i < 1000000)
goto b5;
244 if (i < 100000000)
goto b7;
246 if ((j = i / 1000000000)) {*cp++ = j +
'0'; i -= j*1000000000;
goto x8;}
247 if ((j = i / 100000000)) {*cp++ = j +
'0'; i -= j*100000000;
goto x7;}
248 b7:
if ((j = i / 10000000)) {*cp++ = j +
'0'; i -= j*10000000;
goto x6;}
249 if ((j = i / 1000000)) {*cp++ = j +
'0', i -= j*1000000;
goto x5;}
250 b5:
if ((j = i / 100000)) {*cp++ = j +
'0', i -= j*100000;
goto x4;}
251 if ((j = i / 10000)) {*cp++ = j +
'0', i -= j*10000;
goto x3;}
252 b3:
if ((j = i / 1000)) {*cp++ = j +
'0', i -= j*1000;
goto x2;}
253 if ((j = i / 100)) {*cp++ = j +
'0', i -= j*100;
goto x1;}
254 b1:
if ((j = i / 10)) {*cp++ = j +
'0', i -= j*10;
goto x0;}
255 if (i) *cp++ = i +
'0';
258 x8: *cp++ = i / 100000000 +
'0', i %= 100000000;
259 x7: *cp++ = i / 10000000 +
'0', i %= 10000000;
260 x6: *cp++ = i / 1000000 +
'0', i %= 1000000;
261 x5: *cp++ = i / 100000 +
'0', i %= 100000;
262 x4: *cp++ = i / 10000 +
'0', i %= 10000;
263 x3: *cp++ = i / 1000 +
'0', i %= 1000;
264 x2: *cp++ = i / 100 +
'0', i %= 100;
265 x1: *cp++ = i / 10 +
'0', i %= 10;
271 #define BLOCK_UPLEN(b) \
272 (b)->comp_size = (b)->uncomp_size = BLOCK_SIZE((b))
int cram_write_SAM_hdr(cram_fd *fd, SAM_hdr *hdr)
Definition: cram_io.c:3391
char * zlib_mem_inflate(char *cdata, size_t csize, size_t *size)
Definition: cram_io.c:528
cram_metrics * cram_new_metrics(void)
Definition: cram_io.c:1376
int cram_write_container(cram_fd *fd, cram_container *h)
Definition: cram_io.c:2697
void cram_free_container(cram_container *c)
Definition: cram_io.c:2518
int cram_write_block(cram_fd *fd, cram_block *b)
Definition: cram_io.c:840
int cram_flush(cram_fd *fd)
Definition: cram_io.c:3859
SAM_hdr * cram_read_SAM_hdr(cram_fd *fd)
Definition: cram_io.c:3263
#define itf8_get(c, v)
Definition: cram_io.h:95
int cram_compress_block(cram_fd *fd, cram_block *b, cram_metrics *metrics, int method, int level)
Definition: cram_io.c:1057
char * cram_get_ref(cram_fd *fd, int id, int start, int end)
Definition: cram_io.c:2237
#define itf8_put(c, v)
Definition: cram_io.h:97
cram_block * cram_read_block(cram_fd *fd)
Definition: cram_io.c:767
void cram_free_block(cram_block *b)
Definition: cram_io.c:884
cram_container * cram_new_container(int nrec, int nslice)
Definition: cram_io.c:2465
cram_block * cram_new_block(enum cram_content_type content_type, int content_id)
Definition: cram_io.c:744
cram_fd * cram_open(const char *filename, const char *mode)
Definition: cram_io.c:3686
cram_fd * cram_dopen(struct hFILE *fp, const char *filename, const char *mode)
Definition: cram_io.c:3711
Definition: sam_header.h:183
Definition: cram_structs.h:212
int cram_flush_container(cram_fd *fd, cram_container *c)
Definition: cram_io.c:2789
int cram_seek(cram_fd *fd, off_t offset, int whence)
Definition: cram_io.c:3830
cram_slice * cram_new_slice(enum cram_content_type type, int nrecs)
Definition: cram_io.c:3057
Definition: cram_structs.h:518
Definition: cram_structs.h:177
cram_block_method
Definition: cram_structs.h:189
int cram_set_header(cram_fd *fd, SAM_hdr *hdr)
Definition: cram_io.c:1804
char * cram_block_method2str(enum cram_block_method m)
Definition: cram_io.c:1389
void cram_free_compression_header(cram_block_compression_hdr *hdr)
Definition: cram_io.c:2904
Definition: cram_structs.h:270
Definition: cram_structs.h:596
int cram_uncompress_block(cram_block *b)
Definition: cram_io.c:895
int cram_write_file_def(cram_fd *fd, cram_file_def *def)
Definition: cram_io.c:3242
Definition: cram_structs.h:247
cram_block_compression_hdr * cram_new_compression_header(void)
Definition: cram_io.c:2878
int cram_flush_container_mt(cram_fd *fd, cram_container *c)
Definition: cram_io.c:2852
int itf8_decode(cram_fd *fd, int32_t *val)
Definition: cram_io.c:106
void cram_free_slice(cram_slice *s)
Definition: cram_io.c:2967
int itf8_put_blk(cram_block *blk, int val)
Definition: cram_io.c:459
Definition: cram_structs.h:342
char * cram_content_type2str(enum cram_content_type t)
Definition: cram_io.c:1403
cram_option
Definition: hts.h:140
cram_slice * cram_read_slice(cram_fd *fd)
Definition: cram_io.c:3120
Definition: cram_structs.h:317
int cram_close(cram_fd *fd)
Definition: cram_io.c:3878
int cram_set_voption(cram_fd *fd, enum cram_option opt, va_list args)
Definition: cram_io.c:4010
cram_container * cram_read_container(cram_fd *fd)
Definition: cram_io.c:2560
int cram_eof(cram_fd *fd)
Definition: cram_io.c:3980
int cram_load_reference(cram_fd *fd, char *fn)
Definition: cram_io.c:2430
void cram_ref_incr(refs_t *r, int id)
Definition: cram_io.c:2036
cram_file_def * cram_read_file_def(cram_fd *fd)
Definition: cram_io.c:3208
void cram_free_slice_header(cram_block_slice_hdr *hdr)
Definition: cram_io.c:2955
cram_content_type
Definition: cram_structs.h:201
Definition: cram_structs.h:655
int refs2id(refs_t *r, SAM_hdr *bfd)
Definition: cram_io.c:1711
void cram_ref_decr(refs_t *r, int id)
Definition: cram_io.c:2068
void cram_free_file_def(cram_file_def *def)
Definition: cram_io.c:3246
void refs_free(refs_t *r)
Definition: cram_io.c:1462
int cram_set_option(cram_fd *fd, enum cram_option opt,...)
Definition: cram_io.c:3992