annotate pyPRADA_1.2/tools/samtools-0.1.16/razf.h @ 0:acc2ca1a3ba4

Uploaded
author siyuan
date Thu, 20 Feb 2014 00:44:58 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
1 /*-
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
2 * RAZF : Random Access compressed(Z) File
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
3 * Version: 1.0
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
4 * Release Date: 2008-10-27
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
5 *
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
6 * Copyright 2008, Jue Ruan <ruanjue@gmail.com>, Heng Li <lh3@sanger.ac.uk>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
7 *
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
8 * All rights reserved.
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
9 *
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
10 * Redistribution and use in source and binary forms, with or without
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
11 * modification, are permitted provided that the following conditions
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
12 * are met:
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
13 * 1. Redistributions of source code must retain the above copyright
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
14 * notice, this list of conditions and the following disclaimer.
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
15 * 2. Redistributions in binary form must reproduce the above copyright
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
16 * notice, this list of conditions and the following disclaimer in the
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
17 * documentation and/or other materials provided with the distribution.
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
18 *
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
29 * SUCH DAMAGE.
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
30 */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
31
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
32
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
33 #ifndef __RAZF_RJ_H
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
34 #define __RAZF_RJ_H
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
35
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
36 #include <stdint.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
37 #include <stdio.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
38 #include "zlib.h"
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
39
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
40 #ifdef _USE_KNETFILE
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
41 #include "knetfile.h"
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
42 #endif
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
43
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
44 #if ZLIB_VERNUM < 0x1221
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
45 #define _RZ_READONLY
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
46 struct _gz_header_s;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
47 typedef struct _gz_header_s _gz_header;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
48 #define gz_header _gz_header
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
49 #endif
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
50
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
51 #define WINDOW_BITS 15
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
52
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
53 #ifndef RZ_BLOCK_SIZE
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
54 #define RZ_BLOCK_SIZE (1<<WINDOW_BITS)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
55 #endif
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
56
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
57 #ifndef RZ_BUFFER_SIZE
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
58 #define RZ_BUFFER_SIZE 4096
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
59 #endif
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
60
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
61 #ifndef RZ_COMPRESS_LEVEL
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
62 #define RZ_COMPRESS_LEVEL 6
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
63 #endif
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
64
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
65 #define RZ_BIN_SIZE ((1LLU << 32) / RZ_BLOCK_SIZE)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
66
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
67 typedef struct {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
68 uint32_t *cell_offsets; // i
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
69 int64_t *bin_offsets; // i / BIN_SIZE
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
70 int size;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
71 int cap;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
72 } ZBlockIndex;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
73 /* When storing index, output bytes in Big-Endian everywhere */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
74
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
75 #define FILE_TYPE_RZ 1
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
76 #define FILE_TYPE_PLAIN 2
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
77 #define FILE_TYPE_GZ 3
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
78
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
79 typedef struct RandomAccessZFile {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
80 char mode; /* 'w' : write mode; 'r' : read mode */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
81 int file_type;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
82 /* plain file or rz file, razf_read support plain file as input too, in this case, razf_read work as buffered fread */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
83 #ifdef _USE_KNETFILE
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
84 union {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
85 knetFile *fpr;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
86 int fpw;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
87 } x;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
88 #else
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
89 int filedes; /* the file descriptor */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
90 #endif
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
91 z_stream *stream;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
92 ZBlockIndex *index;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
93 int64_t in, out, end, src_end;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
94 /* in: n bytes total in; out: n bytes total out; */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
95 /* end: the end of all data blocks, while the start of index; src_end: the true end position in uncompressed file */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
96 int buf_flush; // buffer should be flush, suspend inflate util buffer is empty
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
97 int64_t block_pos, block_off, next_block_pos;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
98 /* block_pos: the start postiion of current block in compressed file */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
99 /* block_off: tell how many bytes have been read from current block */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
100 void *inbuf, *outbuf;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
101 int header_size;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
102 gz_header *header;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
103 /* header is used to transfer inflate_state->mode from HEAD to TYPE after call inflateReset */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
104 int buf_off, buf_len;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
105 int z_err, z_eof;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
106 int seekable;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
107 /* Indice where the source is seekable */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
108 int load_index;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
109 /* set has_index to 0 in mode 'w', then index will be discarded */
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
110 } RAZF;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
111
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
112 #ifdef __cplusplus
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
113 extern "C" {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
114 #endif
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
115
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
116 RAZF* razf_dopen(int data_fd, const char *mode);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
117 RAZF *razf_open(const char *fn, const char *mode);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
118 int razf_write(RAZF* rz, const void *data, int size);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
119 int razf_read(RAZF* rz, void *data, int size);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
120 int64_t razf_seek(RAZF* rz, int64_t pos, int where);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
121 void razf_close(RAZF* rz);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
122
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
123 #define razf_tell(rz) ((rz)->out)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
124
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
125 RAZF* razf_open2(const char *filename, const char *mode);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
126 RAZF* razf_dopen2(int fd, const char *mode);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
127 uint64_t razf_tell2(RAZF *rz);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
128 int64_t razf_seek2(RAZF *rz, uint64_t voffset, int where);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
129
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
130 #ifdef __cplusplus
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
131 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
132 #endif
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
133
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
134 #endif