Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ LIBHTS_OBJS = \
cram/rANS_static.o \
cram/sam_header.o \
cram/string_alloc.o \
cram/vlen.o \
cram/zfio.o
cram/vlen.o

PLUGIN_EXT =
PLUGIN_OBJS =
Expand Down Expand Up @@ -320,7 +319,7 @@ cram/cram_codecs.o cram/cram_codecs.pico: cram/cram_codecs.c config.h $(cram_h)
cram/cram_decode.o cram/cram_decode.pico: cram/cram_decode.c config.h $(cram_h) $(cram_os_h) $(htslib_hts_h)
cram/cram_encode.o cram/cram_encode.pico: cram/cram_encode.c config.h $(cram_h) $(cram_os_h) $(htslib_hts_h) $(htslib_hts_endian_h)
cram/cram_external.o cram/cram_external.pico: cram/cram_external.c config.h $(htslib_hfile_h) $(cram_h)
cram/cram_index.o cram/cram_index.pico: cram/cram_index.c config.h $(htslib_hfile_h) $(hts_internal_h) $(cram_h) $(cram_os_h) cram/zfio.h
cram/cram_index.o cram/cram_index.pico: cram/cram_index.c config.h $(htslib_bgzf_h) $(htslib_hfile_h) $(hts_internal_h) $(cram_h) $(cram_os_h)
cram/cram_io.o cram/cram_io.pico: cram/cram_io.c config.h $(cram_h) $(cram_os_h) $(htslib_hts_h) $(cram_open_trace_file_h) cram/rANS_static.h $(htslib_hfile_h) $(htslib_bgzf_h) $(htslib_faidx_h) $(hts_internal_h)
cram/cram_samtools.o cram/cram_samtools.pico: cram/cram_samtools.c config.h $(cram_h) $(htslib_sam_h)
cram/cram_stats.o cram/cram_stats.pico: cram/cram_stats.c config.h $(cram_h) $(cram_os_h)
Expand All @@ -333,7 +332,6 @@ cram/sam_header.o cram/sam_header.pico: cram/sam_header.c config.h $(cram_sam_he
cram/string_alloc.o cram/string_alloc.pico: cram/string_alloc.c config.h cram/string_alloc.h
thread_pool.o thread_pool.pico: thread_pool.c config.h $(thread_pool_internal_h)
cram/vlen.o cram/vlen.pico: cram/vlen.c config.h cram/vlen.h $(cram_os_h)
cram/zfio.o cram/zfio.pico: cram/zfio.c config.h $(cram_os_h) cram/zfio.h


bgzip: bgzip.o libhts.a
Expand Down
37 changes: 22 additions & 15 deletions cram/cram_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sys/stat.h>
#include <math.h>

#include "htslib/bgzf.h"
#include "htslib/hfile.h"
#include "hts_internal.h"
#include "cram/cram.h"
#include "cram/os.h"
#include "cram/zfio.h"

#if 0
static void dump_index_(cram_index *e, int level) {
Expand Down Expand Up @@ -450,12 +450,13 @@ int cram_seek_to_refpos(cram_fd *fd, cram_range *r) {
* decode the slice to look at the RI data series instead.
*
* Returns 0 on success
* -1 on failure
* -1 on read failure
* -4 on write failure
*/
static int cram_index_build_multiref(cram_fd *fd,
cram_container *c,
cram_slice *s,
zfp *fp,
BGZF *fp,
off_t cpos,
int32_t landmark,
int sz) {
Expand All @@ -477,7 +478,8 @@ static int cram_index_build_multiref(cram_fd *fd,
sprintf(buf, "%d\t%d\t%d\t%"PRId64"\t%d\t%d\n",
ref, ref_start, ref_end - ref_start + 1,
(int64_t)cpos, landmark, sz);
zfputs(buf, fp);
if (bgzf_write(fp, buf, strlen(buf)) < 0)
return -4;
}

ref = s->crecs[i].ref_id;
Expand All @@ -489,7 +491,8 @@ static int cram_index_build_multiref(cram_fd *fd,
sprintf(buf, "%d\t%d\t%d\t%"PRId64"\t%d\t%d\n",
ref, ref_start, ref_end - ref_start + 1,
(int64_t)cpos, landmark, sz);
zfputs(buf, fp);
if (bgzf_write(fp, buf, strlen(buf)) < 0)
return -4;
}

return 0;
Expand All @@ -509,7 +512,7 @@ static int cram_index_build_multiref(cram_fd *fd,
int cram_index_build(cram_fd *fd, const char *fn_base, const char *fn_idx) {
cram_container *c;
off_t cpos, spos, hpos;
zfp *fp;
BGZF *fp;
kstring_t fn_idx_str = {0};

if (! fn_idx) {
Expand All @@ -518,7 +521,7 @@ int cram_index_build(cram_fd *fd, const char *fn_base, const char *fn_idx) {
fn_idx = fn_idx_str.s;
}

if (!(fp = zfopen(fn_idx, "wz"))) {
if (!(fp = bgzf_open(fn_idx, "wg"))) {
perror(fn_idx);
free(fn_idx_str.s);
return -4;
Expand Down Expand Up @@ -549,30 +552,35 @@ int cram_index_build(cram_fd *fd, const char *fn_base, const char *fn_idx) {
for (j = 0; j < c->num_landmarks; j++) {
char buf[1024];
cram_slice *s;
int sz;
int sz, ret;

spos = htell(fd->fp);
assert(spos - cpos - c->offset == c->landmark[j]);

if (!(s = cram_read_slice(fd))) {
zfclose(fp);
bgzf_close(fp);
return -1;
}

sz = (int)(htell(fd->fp) - spos);

if (s->hdr->ref_seq_id == -2) {
cram_index_build_multiref(fd, c, s, fp,
cpos, c->landmark[j], sz);
ret = cram_index_build_multiref(fd, c, s, fp,
cpos, c->landmark[j], sz);
} else {
sprintf(buf, "%d\t%d\t%d\t%"PRId64"\t%d\t%d\n",
s->hdr->ref_seq_id, s->hdr->ref_seq_start,
s->hdr->ref_seq_span, (int64_t)cpos,
c->landmark[j], sz);
zfputs(buf, fp);
ret = (bgzf_write(fp, buf, strlen(buf)) >= 0)? 0 : -4;
}

cram_free_slice(s);

if (ret < 0) {
bgzf_close(fp);
return ret;
}
}

cpos = htell(fd->fp);
Expand All @@ -581,10 +589,9 @@ int cram_index_build(cram_fd *fd, const char *fn_base, const char *fn_idx) {
cram_free_container(c);
}
if (fd->err) {
zfclose(fp);
bgzf_close(fp);
return -1;
}


return (zfclose(fp) >= 0)? 0 : -4;
return (bgzf_close(fp) >= 0)? 0 : -4;
}
154 changes: 0 additions & 154 deletions cram/zfio.c

This file was deleted.

62 changes: 0 additions & 62 deletions cram/zfio.h

This file was deleted.

4 changes: 1 addition & 3 deletions htslib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ HTSLIB_ALL = \
$(HTSDIR)/cram/string_alloc.c \
$(HTSDIR)/cram/string_alloc.h \
$(HTSDIR)/cram/vlen.c \
$(HTSDIR)/cram/vlen.h \
$(HTSDIR)/cram/zfio.c \
$(HTSDIR)/cram/zfio.h
$(HTSDIR)/cram/vlen.h

$(HTSDIR)/config.h:
+cd $(HTSDIR) && $(MAKE) config.h
Expand Down