Skip to content

Commit

Permalink
Release 1.1: various minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarshall committed Sep 23, 2014
2 parents f2af2ad + dcefe5b commit 5a0ee03
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 101 deletions.
12 changes: 7 additions & 5 deletions Makefile
Expand Up @@ -81,7 +81,7 @@ lib-shared: libhts.so
endif


PACKAGE_VERSION = 1.0
PACKAGE_VERSION = 1.1
LIBHTS_SOVERSION = 1


Expand Down Expand Up @@ -234,11 +234,13 @@ bgzip.o: bgzip.c $(htslib_bgzf_h) $(htslib_hts_h)
tabix.o: tabix.c $(htslib_tbx_h) $(htslib_sam_h) $(htslib_vcf_h) htslib/kseq.h $(htslib_bgzf_h) $(htslib_hts_h)


# For tests that might use it, set $REF_PATH explicitly to use only reference
# areas within the test suite (or set it to ':' to use no reference areas).
check test: $(BUILT_TEST_PROGRAMS)
test/fieldarith test/fieldarith.sam
test/hfile
test/sam
cd test && ./test_view.pl
cd test && REF_PATH=: ./test_view.pl
cd test && ./test.pl

test/fieldarith: test/fieldarith.o libhts.a
Expand Down Expand Up @@ -267,12 +269,12 @@ test/test-vcf-api.o: test/test-vcf-api.c $(htslib_hts_h) $(htslib_vcf_h) htslib/
test/test-vcf-sweep.o: test/test-vcf-sweep.c $(htslib_vcf_sweep_h)


install: installdirs install-$(SHLIB_FLAVOUR) install-pkgconfig
install: libhts.a $(BUILT_PROGRAMS) installdirs install-$(SHLIB_FLAVOUR) install-pkgconfig
$(INSTALL_PROGRAM) $(BUILT_PROGRAMS) $(DESTDIR)$(bindir)
$(INSTALL_DATA) htslib/*.h $(DESTDIR)$(includedir)/htslib
$(INSTALL_DATA) libhts.a $(DESTDIR)$(libdir)/libhts.a
$(INSTALL_DATA) *.1 $(DESTDIR)$(man1dir)
$(INSTALL_DATA) *.5 $(DESTDIR)$(man5dir)
$(INSTALL_DATA) tabix.1 $(DESTDIR)$(man1dir)
$(INSTALL_DATA) faidx.5 sam.5 vcf.5 $(DESTDIR)$(man5dir)

installdirs:
$(INSTALL_DIR) $(DESTDIR)$(bindir) $(DESTDIR)$(includedir) $(DESTDIR)$(includedir)/htslib $(DESTDIR)$(libdir) $(DESTDIR)$(man1dir) $(DESTDIR)$(man5dir) $(DESTDIR)$(pkgconfigdir)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -12,6 +12,6 @@ This project also includes the popular tabix indexer, which indexes both `.tbi`
and `.csi` formats, and the bgzip compression utility.

[1]: http://samtools.github.io/hts-specs/
[2]: http://samtools.github.io/bcftools/
[3]: http://github.com/samtools/samtools
[2]: http://github.com/samtools/samtools
[3]: http://samtools.github.io/bcftools/
[4]: http://zlib.net/
33 changes: 31 additions & 2 deletions bgzf.c
Expand Up @@ -240,11 +240,39 @@ static int bgzf_compress(void *_dst, int *dlen, void *src, int slen, int level)
return 0;
}

static int bgzf_gzip_compress(BGZF *fp, void *_dst, int *dlen, void *src, int slen, int level)
{
uint8_t *dst = (uint8_t*)_dst;
z_stream *zs = fp->gz_stream;
if ( !zs )
{
zs = fp->gz_stream = (z_stream*)calloc(1,sizeof(z_stream));
zs->zalloc = NULL;
zs->zfree = NULL;
if ( deflateInit2(zs, level, Z_DEFLATED, 15|16, 8, Z_DEFAULT_STRATEGY)!=Z_OK ) return -1; // gzip output
}
int flush = slen ? Z_NO_FLUSH : Z_FINISH;
zs->next_in = (Bytef*)src;
zs->avail_in = slen;
zs->next_out = dst;
zs->avail_out = *dlen;
if ( deflate(zs, flush) == Z_STREAM_ERROR ) return -1;
*dlen = *dlen - zs->avail_out;
return 0;
}

// Deflate the block in fp->uncompressed_block into fp->compressed_block. Also adds an extra field that stores the compressed block length.
static int deflate_block(BGZF *fp, int block_length)
{
int comp_size = BGZF_MAX_BLOCK_SIZE;
if (bgzf_compress(fp->compressed_block, &comp_size, fp->uncompressed_block, block_length, fp->compress_level) != 0) {
int ret;
if ( !fp->is_gzip )
ret = bgzf_compress(fp->compressed_block, &comp_size, fp->uncompressed_block, block_length, fp->compress_level);
else
ret = bgzf_gzip_compress(fp, fp->compressed_block, &comp_size, fp->uncompressed_block, block_length, fp->compress_level);

if ( ret != 0 )
{
fp->errcode |= BGZF_ERR_ZLIB;
return -1;
}
Expand Down Expand Up @@ -778,7 +806,8 @@ int bgzf_close(BGZF* fp)
}
if ( fp->is_gzip )
{
(void)inflateEnd(fp->gz_stream);
if (!fp->is_write) (void)inflateEnd(fp->gz_stream);
else (void)deflateEnd(fp->gz_stream);
free(fp->gz_stream);
}
ret = hclose(fp->fp);
Expand Down
2 changes: 2 additions & 0 deletions cram/cram_index.c
Expand Up @@ -155,6 +155,8 @@ int cram_index_load(cram_fd *fd, const char *fn) {
}
kstr.s = s;
kstr.l = l;
kstr.m = l; // conservative estimate of the size allocated
kputsn("", 0, &kstr); // ensure kstr.s is NUL-terminated
}


Expand Down
2 changes: 1 addition & 1 deletion cram/cram_io.c
Expand Up @@ -1434,7 +1434,7 @@ static int cram_populate_ref(cram_fd *fd, int id, ref_entry *r) {
fprintf(stderr, "cram_populate_ref on fd %p, id %d\n", fd, id);

if (!ref_path || *ref_path == 0)
ref_path = "|http://www.ebi.ac.uk:80/ena/cram/md5/%s";
ref_path = "http://www.ebi.ac.uk:80/ena/cram/md5/%s";

if (!r->name)
return -1;
Expand Down
60 changes: 27 additions & 33 deletions cram/open_trace_file.c
Expand Up @@ -302,43 +302,37 @@ mFILE *open_path_mfile(char *file, char *path, char *relative_to) {
* special, otherwise we treat the element as a directory.
*/
for (ele = newsearch; *ele; ele += strlen(ele)+1) {
int i;
char *suffix[6] = {"", ".gz", ".bz2", ".sz", ".Z", ".bz2"};
for (i = 0; i < 6; i++) {
char file2[1024];
char *ele2;
int valid = 1;

/*
* '|' prefixing a path component indicates that we do not
* wish to perform the compression extension searching in that
* location.
*/
if (*ele == '|') {
ele2 = ele+1;
valid = (i == 0);
} else {
ele2 = ele;
}
char *ele2;

/*
* '|' prefixing a path component indicates that we do not
* wish to perform the compression extension searching in that
* location.
*
* NB: this has been removed from the htslib implementation.
*/
if (*ele == '|') {
ele2 = ele+1;
} else {
ele2 = ele;
}

sprintf(file2, "%s%s", file, suffix[i]);

if (0 == strncmp(ele2, "URL=", 4)) {
if (valid && (fp = find_file_url(file2, ele2+4))) {
free(newsearch);
return fp;
}
} else if (!strncmp(ele2, "http:", 5) || !strncmp(ele2, "ftp:", 4)) {
if (valid && (fp = find_file_url(file2, ele2))) {
free(newsearch);
return fp;
}
} else if (valid && (fp = find_file_dir(file2, ele2))) {
if (0 == strncmp(ele2, "URL=", 4)) {
if ((fp = find_file_url(file, ele2+4))) {
free(newsearch);
return fp;
}
}
}
} else if (!strncmp(ele2, "http:", 5) ||
!strncmp(ele2, "ftp:", 4)) {
if ((fp = find_file_url(file, ele2))) {
free(newsearch);
return fp;
}
} else if ((fp = find_file_dir(file, ele2))) {
free(newsearch);
return fp;
}
}

free(newsearch);

Expand Down
12 changes: 11 additions & 1 deletion faidx.c
Expand Up @@ -409,10 +409,20 @@ char *fai_fetch(const faidx_t *fai, const char *str, int *len)
return s;
}

int faidx_fetch_nseq(const faidx_t *fai)
int faidx_nseq(const faidx_t *fai)
{
return fai->n;
}
const char *faidx_iseq(const faidx_t *fai, int i)
{
return fai->name[i];
}
int faidx_seq_len(const faidx_t *fai, const char *seq)
{
khint_t k = kh_get(s, fai->hash, seq);
if ( k == kh_end(fai->hash) ) return -1;
return kh_val(fai->hash, k).len;
}

char *faidx_fetch_seq(const faidx_t *fai, const char *c_name, int p_beg_i, int p_end_i, int *len)
{
Expand Down
4 changes: 0 additions & 4 deletions hts.c
Expand Up @@ -708,10 +708,6 @@ int hts_idx_push(hts_idx_t *idx, int tid, int beg, int end, uint64_t offset, int
idx->z.save_off = idx->z.last_off;
idx->z.save_bin = idx->z.last_bin = bin;
idx->z.save_tid = tid;
if (tid < 0) { // come to the end of the records having coordinates
hts_idx_finish(idx, offset);
return 0;
}
}
if (is_mapped) ++idx->z.n_mapped;
else ++idx->z.n_unmapped;
Expand Down
15 changes: 15 additions & 0 deletions htslib/faidx.h
Expand Up @@ -113,6 +113,21 @@ extern "C" {
*/
int faidx_has_seq(const faidx_t *fai, const char *seq);

/*!
@abstract Return number of sequences in fai index
*/
int faidx_nseq(const faidx_t *fai);

/*!
@abstract Return name of i-th sequence
*/
const char *faidx_iseq(const faidx_t *fai, int i);

/*!
@abstract Return sequence length, -1 if not present
*/
int faidx_seq_len(const faidx_t *fai, const char *seq);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 4 additions & 2 deletions htslib/khash_str2int.h
Expand Up @@ -90,7 +90,8 @@ static inline int khash_str2int_get(void *_hash, const char *str, int *value)
/*
* Add a new string to the dictionary, auto-incrementing the value.
* On success returns the newly inserted integer id, on error -1
* is returned.
* is returned. Note that the key must continue to exist throughout
* the whole life of _hash.
*/
static inline int khash_str2int_inc(void *_hash, const char *str)
{
Expand All @@ -106,7 +107,8 @@ static inline int khash_str2int_inc(void *_hash, const char *str)

/*
* Set a new key,value pair. On success returns the bin index, on
* error -1 is returned.
* error -1 is returned. Note that the key must contnue to exist
* throughout the whole life of _hash.
*/
static inline int khash_str2int_set(void *_hash, const char *str, int value)
{
Expand Down
11 changes: 11 additions & 0 deletions htslib/vcf.h
Expand Up @@ -590,6 +590,17 @@ extern "C" {
bcf_fmt_t *bcf_get_fmt(const bcf_hdr_t *hdr, bcf1_t *line, const char *key);
bcf_info_t *bcf_get_info(const bcf_hdr_t *hdr, bcf1_t *line, const char *key);

/**
* bcf_get_*_id() - returns pointer to FORMAT/INFO field data given the header index instead of the string ID
* @line: VCF line obtained from vcf_parse1
* @id: The header index for the tag, obtained from bcf_hdr_id2int()
*
* Returns bcf_fmt_t* / bcf_info_t*. These functions do not check if the index is valid
* as their goal is to avoid the header lookup.
*/
bcf_fmt_t *bcf_get_fmt_id(bcf1_t *line, const int id);
bcf_info_t *bcf_get_info_id(bcf1_t *line, const int id);

/**
* bcf_get_info_*() - get INFO values, integers or floats
* @hdr: BCF header
Expand Down
2 changes: 1 addition & 1 deletion tabix.1
@@ -1,4 +1,4 @@
.TH tabix 1 "15 August 2014" "tabix-1.0" "Bioinformatics tools"
.TH tabix 1 "23 September 2014" "htslib-1.1" "Bioinformatics tools"
.SH NAME
.PP
bgzip - Block compression/decompression utility
Expand Down

0 comments on commit 5a0ee03

Please sign in to comment.