Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Macros | Typedefs | Functions
bgzf.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <sys/types.h>
#include <inttypes.h>
#include "htslib/hts.h"
#include "htslib/bgzf.h"
#include "htslib/hfile.h"
#include "htslib/khash.h"

Classes

struct  cache_t
 
struct  bgzidx1_t
 
struct  __bgzidx_t
 
struct  worker_t
 
struct  bgzf_mtaux_t
 

Macros

#define BLOCK_HEADER_LENGTH   18
 
#define BLOCK_FOOTER_LENGTH   8
 

Typedefs

typedef struct bgzf_mtaux_t mtaux_t
 

Functions

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

Macro Definition Documentation

#define BLOCK_FOOTER_LENGTH   8
#define BLOCK_HEADER_LENGTH   18

Typedef Documentation

typedef struct bgzf_mtaux_t mtaux_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
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
BGZF* bgzf_dopen ( int  fd,
const char *  mode 
)

Open an existing file descriptor for reading or writing.

Parameters
fdfile descriptor
modemode matching /[rwag][u0-9]+/: 'r' for reading, 'w' for writing, 'a' for appending, 'g' for gzip rather than BGZF compression (with 'w' only), and 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
int bgzf_flush ( BGZF fp)

Write the data in the buffer to the file.

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
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
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
BGZF* bgzf_hopen ( struct hFILE fp,
const char *  mode 
)

Open an existing hFILE stream for reading or writing.

int bgzf_index_add_block ( BGZF fp)
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.

void bgzf_index_destroy ( BGZF fp)
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.

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.

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
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
BGZF* bgzf_open ( const char *  path,
const char *  mode 
)

Open the specified file for reading or writing.

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
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
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
int bgzf_read_block ( BGZF fp)

Read the next BGZF block.

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
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)
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.

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.

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