#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"
Go to the source code of this file.
|
void | bgzf_index_destroy (BGZF *fp) |
|
int | bgzf_index_add_block (BGZF *fp) |
|
BGZF * | bgzf_open (const char *path, const char *mode) |
|
BGZF * | bgzf_dopen (int fd, const char *mode) |
|
BGZF * | bgzf_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) |
|
#define BLOCK_FOOTER_LENGTH 8 |
#define BLOCK_HEADER_LENGTH 18 |
int bgzf_check_EOF |
( |
BGZF * |
fp) | |
|
Check if the BGZF end-of-file (EOF) marker is present
- Parameters
-
fp | BGZF 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
-
- 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
-
fd | file descriptor |
mode | mode 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
-
- Returns
- byte read; -1 on end-of-file or error
Definition at line 843 of file bgzf.c.
Read one line from a BGZF file. It is faster than bgzf_getc()
- Parameters
-
fp | BGZF file handler |
delim | delimitor |
str | string 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.
Open an existing hFILE stream for reading or writing.
Definition at line 199 of file bgzf.c.
int bgzf_index_add_block |
( |
BGZF * |
fp) | |
|
int bgzf_index_build_init |
( |
BGZF * |
fp) | |
|
Tell BGZF to build index while compressing.
- Parameters
-
fp | BGZF 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.
void bgzf_index_destroy |
( |
BGZF * |
fp) | |
|
int bgzf_index_dump |
( |
BGZF * |
fp, |
|
|
const char * |
bname, |
|
|
const char * |
suffix |
|
) |
| |
Save BGZF index
- Parameters
-
fp | BGZF file handler |
bname | base name |
suffix | suffix 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
-
fp | BGZF file handler |
bname | base name |
suffix | suffix 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
-
- 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
-
fp | BGZF 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.
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
-
fp | BGZF file handler |
data | data array to read into |
length | number 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
-
fp | BGZF file handler |
data | data array to write |
length | number 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
-
fp | BGZF file handler |
data | data array to read into |
length | size 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) | |
|
Set the file to read from the location specified by pos.
- Parameters
-
fp | BGZF file handler |
pos | virtual file offset returned by bgzf_tell() |
whence | must 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
-
fp | BGZF file handler |
size | size 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
-
fp | BGZF file handler; must be opened for reading |
uoffset | file offset in the uncompressed data |
where | SEEK_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
-
fp | BGZF 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
-
fp | BGZF file handler |
data | data array to write |
length | size of data to write |
- Returns
- number of bytes written (i.e., length); negative on error
Definition at line 732 of file bgzf.c.