NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Macros | Typedefs | Functions
bgzf.h File Reference
#include <stdint.h>
#include <stdio.h>
#include <zlib.h>
#include <sys/types.h>

Go to the source code of this file.

Classes

struct  BGZF
 
struct  __kstring_t
 

Macros

#define BGZF_BLOCK_SIZE   0xff00
 
#define BGZF_MAX_BLOCK_SIZE   0x10000
 
#define BGZF_ERR_ZLIB   1
 
#define BGZF_ERR_HEADER   2
 
#define BGZF_ERR_IO   4
 
#define BGZF_ERR_MISUSE   8
 
#define HTS_BGZF_TYPEDEF
 
#define KSTRING_T   kstring_t
 
#define bgzf_fdopen(fd, mode)   bgzf_dopen((fd), (mode))
 
#define bgzf_tell(fp)   (((fp)->block_address << 16) | ((fp)->block_offset & 0xFFFF))
 

Typedefs

typedef struct __bgzidx_t bgzidx_t
 
typedef struct BGZF BGZF
 
typedef struct __kstring_t kstring_t
 

Functions

BGZFbgzf_dopen (int fd, const char *mode)
 
BGZFbgzf_open (const char *path, const char *mode)
 
BGZFbgzf_hopen (struct hFILE *fp, const char *mode)
 
int bgzf_close (BGZF *fp)
 
ssize_t bgzf_read (BGZF *fp, void *data, size_t length)
 
ssize_t bgzf_write (BGZF *fp, const void *data, size_t length)
 
ssize_t bgzf_raw_read (BGZF *fp, void *data, size_t length)
 
ssize_t bgzf_raw_write (BGZF *fp, const void *data, size_t length)
 
int bgzf_flush (BGZF *fp)
 
int64_t bgzf_seek (BGZF *fp, int64_t pos, int whence)
 
int bgzf_check_EOF (BGZF *fp)
 
int bgzf_is_bgzf (const char *fn)
 
void bgzf_set_cache_size (BGZF *fp, int size)
 
int bgzf_flush_try (BGZF *fp, ssize_t size)
 
int bgzf_getc (BGZF *fp)
 
int bgzf_getline (BGZF *fp, int delim, kstring_t *str)
 
int bgzf_read_block (BGZF *fp)
 
int bgzf_mt (BGZF *fp, int n_threads, int n_sub_blks)
 
int bgzf_useek (BGZF *fp, long uoffset, int where)
 
long bgzf_utell (BGZF *fp)
 
int bgzf_index_build_init (BGZF *fp)
 
int bgzf_index_load (BGZF *fp, const char *bname, const char *suffix)
 
int bgzf_index_dump (BGZF *fp, const char *bname, const char *suffix)
 

Macro Definition Documentation

#define BGZF_BLOCK_SIZE   0xff00

Definition at line 36 of file bgzf.h.

#define BGZF_ERR_HEADER   2

Definition at line 40 of file bgzf.h.

#define BGZF_ERR_IO   4

Definition at line 41 of file bgzf.h.

#define BGZF_ERR_MISUSE   8

Definition at line 42 of file bgzf.h.

#define BGZF_ERR_ZLIB   1

Definition at line 39 of file bgzf.h.

#define bgzf_fdopen (   fd,
  mode 
)    bgzf_dopen((fd), (mode))

Definition at line 96 of file bgzf.h.

#define BGZF_MAX_BLOCK_SIZE   0x10000

Definition at line 37 of file bgzf.h.

#define bgzf_tell (   fp)    (((fp)->block_address << 16) | ((fp)->block_offset & 0xFFFF))

Return a virtual file pointer to the current location in the file. No interpetation of the value should be made, other than a subsequent call to bgzf_seek can be used to position the file at the same point. Return value is non-negative on success.

Definition at line 172 of file bgzf.h.

#define HTS_BGZF_TYPEDEF

Definition at line 63 of file bgzf.h.

#define KSTRING_T   kstring_t

Definition at line 67 of file bgzf.h.

Typedef Documentation

typedef struct BGZF BGZF

Definition at line 62 of file bgzf.h.

typedef struct __bgzidx_t bgzidx_t

Definition at line 46 of file bgzf.h.

typedef struct __kstring_t kstring_t

Function Documentation

int bgzf_check_EOF ( BGZF fp)

Check if the BGZF end-of-file (EOF) marker is present

Parameters
fpBGZF file handler opened for reading
Returns
1 if the EOF marker is present and correct; 2 if it can't be checked, e.g., because fp isn't seekable; 0 if the EOF marker is absent; -1 (with errno set) on error

Definition at line 797 of file bgzf.c.

int bgzf_close ( BGZF fp)

Close the BGZF and free all associated resources.

Parameters
fpBGZF file handler
Returns
0 on success and -1 on error

Definition at line 760 of file bgzf.c.

BGZF* bgzf_dopen ( int  fd,
const char *  mode 
)

Open an existing file descriptor for reading or writing.

Parameters
fdfile descriptor
modemode matching /[rwa][u0-9]+/: 'r' for reading, 'w' for writing, or 'a' for appending, while a digit specifies the zlib compression level. Note that there is a distinction between 'u' and '0': the first yields plain uncompressed output whereas the latter outputs uncompressed data wrapped in the zlib format.
Returns
BGZF file handler; 0 on error

Definition at line 177 of file bgzf.c.

int bgzf_flush ( BGZF fp)

Write the data in the buffer to the file.

Definition at line 700 of file bgzf.c.

int bgzf_flush_try ( BGZF fp,
ssize_t  size 
)

Flush the file if the remaining buffer size is smaller than size

Returns
0 if flushing succeeded or was not needed; negative on error

Definition at line 726 of file bgzf.c.

int bgzf_getc ( BGZF fp)

Read one byte from a BGZF file. It is faster than bgzf_read()

Parameters
fpBGZF file handler
Returns
byte read; -1 on end-of-file or error

Definition at line 843 of file bgzf.c.

int bgzf_getline ( BGZF fp,
int  delim,
kstring_t str 
)

Read one line from a BGZF file. It is faster than bgzf_getc()

Parameters
fpBGZF file handler
delimdelimitor
strstring to write to; must be initialized
Returns
length of the string; 0 on end-of-file; negative on error

Definition at line 864 of file bgzf.c.

BGZF* bgzf_hopen ( struct hFILE fp,
const char *  mode 
)

Open an existing hFILE stream for reading or writing.

Definition at line 199 of file bgzf.c.

int bgzf_index_build_init ( BGZF fp)
Tell BGZF to build index while compressing.
Parameters
fpBGZF file handler; can be opened for reading or writing.

Returns 0 on success and -1 on error.

Definition at line 906 of file bgzf.c.

int bgzf_index_dump ( BGZF fp,
const char *  bname,
const char *  suffix 
)
Save BGZF index
Parameters
fpBGZF file handler
bnamebase name
suffixsuffix to add to bname (can be NULL)

Returns 0 on success and -1 on error.

Definition at line 930 of file bgzf.c.

int bgzf_index_load ( BGZF fp,
const char *  bname,
const char *  suffix 
)
Load BGZF index
Parameters
fpBGZF file handler
bnamebase name
suffixsuffix to add to bname (can be NULL)

Returns 0 on success and -1 on error.

Definition at line 980 of file bgzf.c.

int bgzf_is_bgzf ( const char *  fn)

Check if a file is in the BGZF format

Parameters
fnfile name
Returns
1 if fn is BGZF; 0 if not or on I/O error

Definition at line 831 of file bgzf.c.

int bgzf_mt ( BGZF fp,
int  n_threads,
int  n_sub_blks 
)

Enable multi-threading (only effective on writing and when the library was compiled with -DBGZF_MT)

Parameters
fpBGZF file handler; must be opened for writing
n_threads#threads used for writing
n_sub_blks#blocks processed by each thread; a value 64-256 is recommended

Definition at line 593 of file bgzf.c.

BGZF* bgzf_open ( const char *  path,
const char *  mode 
)

Open the specified file for reading or writing.

Definition at line 155 of file bgzf.c.

ssize_t bgzf_raw_read ( BGZF fp,
void *  data,
size_t  length 
)

Read up to length bytes directly from the underlying stream without decompressing. Bypasses BGZF blocking, so must be used with care in specialised circumstances only.

Parameters
fpBGZF file handler
datadata array to read into
lengthnumber of raw bytes to read
Returns
number of bytes actually read; 0 on end-of-file and -1 on error

Definition at line 540 of file bgzf.c.

ssize_t bgzf_raw_write ( BGZF fp,
const void *  data,
size_t  length 
)

Write length bytes directly to the underlying stream without compressing. Bypasses BGZF blocking, so must be used with care in specialised circumstances only.

Parameters
fpBGZF file handler
datadata array to write
lengthnumber of raw bytes to write
Returns
number of bytes actually written; -1 on error

Definition at line 755 of file bgzf.c.

ssize_t bgzf_read ( BGZF fp,
void *  data,
size_t  length 
)

Read up to length bytes from the file storing into data.

Parameters
fpBGZF file handler
datadata array to read into
lengthsize of data to read
Returns
number of bytes actually read; 0 on end-of-file and -1 on error

Definition at line 511 of file bgzf.c.

int bgzf_read_block ( BGZF fp)

Read the next BGZF block.

Definition at line 384 of file bgzf.c.

int64_t bgzf_seek ( BGZF fp,
int64_t  pos,
int  whence 
)

Set the file to read from the location specified by pos.

Parameters
fpBGZF file handler
posvirtual file offset returned by bgzf_tell()
whencemust be SEEK_SET
Returns
0 on success and -1 on error

Definition at line 810 of file bgzf.c.

void bgzf_set_cache_size ( BGZF fp,
int  size 
)

Set the cache size. Only effective when compiled with -DBGZF_CACHE.

Parameters
fpBGZF file handler
sizesize of cache in bytes; 0 to disable caching (default)

Definition at line 792 of file bgzf.c.

int bgzf_useek ( BGZF fp,
long  uoffset,
int  where 
)

Position BGZF at the uncompressed offset

Parameters
fpBGZF file handler; must be opened for reading
uoffsetfile offset in the uncompressed data
whereSEEK_SET supported atm

Returns 0 on success and -1 on error.

Definition at line 1031 of file bgzf.c.

long bgzf_utell ( BGZF fp)

Position in uncompressed BGZF

Parameters
fpBGZF file handler; must be opened for reading

Returns the current offset on success and -1 on error.

Definition at line 1082 of file bgzf.c.

ssize_t bgzf_write ( BGZF fp,
const void *  data,
size_t  length 
)

Write length bytes from data to the file. If no I/O errors occur, the complete length bytes will be written (or queued for writing).

Parameters
fpBGZF file handler
datadata array to write
lengthsize of data to write
Returns
number of bytes written (i.e., length); negative on error

Definition at line 732 of file bgzf.c.