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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ realn.o realn.pico: realn.c config.h $(htslib_hts_h) $(htslib_sam_h)
textutils.o textutils.pico: textutils.c config.h $(htslib_hfile_h) $(htslib_kstring_h) $(htslib_sam_h) $(hts_internal_h)

cram/cram_codecs.o cram/cram_codecs.pico: cram/cram_codecs.c config.h $(fuzz_settings_h) $(htslib_hts_endian_h) $(htscodecs_varint_h) $(htscodecs_pack_h) $(htscodecs_rle_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_decode.o cram/cram_decode.pico: cram/cram_decode.c config.h $(cram_h) $(cram_os_h) $(htslib_hts_h) $(htslib_hfile_h)
cram/cram_encode.o cram/cram_encode.pico: cram/cram_encode.c config.h $(cram_h) $(cram_os_h) $(sam_internal_h) $(htslib_hts_h) $(htslib_hts_endian_h) $(textutils_internal_h)
cram/cram_external.o cram/cram_external.pico: cram/cram_external.c config.h $(htscodecs_rANS_static4x16_h) $(htslib_hfile_h) $(cram_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)
Expand Down
11 changes: 8 additions & 3 deletions cram/cram_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cram.h"
#include "os.h"
#include "../htslib/hts.h"
#include "../htslib/hfile.h"

//Whether CIGAR has just M or uses = and X to indicate match and mismatch
//#define USE_X
Expand Down Expand Up @@ -3287,14 +3288,18 @@ cram_slice *cram_next_slice(cram_fd *fd, cram_container **cp) {
break;
}

// before start of range; skip to next container
// Before start of range; skip to next container.
// Can't use cram_seek() here as it drops in-progress
// multi-threaded decode jobs, so call hseek() directly.
if (fd->range.refid != -1 &&
c_next->ref_seq_start + c_next->ref_seq_span-1 <
fd->range.start) {
c_next->curr_slice_mt = c_next->max_slice;
cram_seek(fd, c_next->length, SEEK_CUR);
off_t skip_length = c_next->length;
cram_free_container(c_next);
c_next = NULL;
fd->ooc = 0;
if (hseek(fd->fp, skip_length, SEEK_CUR) < 0)
return NULL;
continue;
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/index3.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@HD VN:1.6 SO:coordinate
@SQ SN:CHROMOSOME_I LN:1009800 M5:8ede36131e0dbf3417807e48f77f3ebd
@CO CRAM container skipping test - very long reads followed by short ones.
@CO Use option seqs_per_slice=2 when writing CRAM so that records are
@CO stored in multiple containers.
r0-1 0 CHROMOSOME_I 1 50 10000M * 0 0 * *
r0-2 0 CHROMOSOME_I 1 50 10000M * 0 0 * *
r1-1 0 CHROMOSOME_I 1000 50 100M * 0 0 * *
r1-2 0 CHROMOSOME_I 1000 50 100M * 0 0 * *
r2-1 0 CHROMOSOME_I 2000 50 100M * 0 0 * *
r2-2 0 CHROMOSOME_I 2000 50 100M * 0 0 * *
r3-1 0 CHROMOSOME_I 3000 50 100M * 0 0 * *
r3-2 0 CHROMOSOME_I 3000 50 100M * 0 0 * *
r4-1 0 CHROMOSOME_I 4000 50 100M * 0 0 * *
r4-2 0 CHROMOSOME_I 4000 50 100M * 0 0 * *
r5-1 0 CHROMOSOME_I 5000 50 100M * 0 0 * *
r5-2 0 CHROMOSOME_I 5000 50 100M * 0 0 * *
9 changes: 9 additions & 0 deletions test/index3_exp.sam
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@HD VN:1.6 SO:coordinate
@SQ SN:CHROMOSOME_I LN:1009800 M5:8ede36131e0dbf3417807e48f77f3ebd
@CO CRAM container skipping test - very long reads followed by short ones.
@CO Use option seqs_per_slice=2 when writing CRAM so that records are
@CO stored in multiple containers.
r0-1 0 CHROMOSOME_I 1 50 10000M * 0 0 * *
r0-2 0 CHROMOSOME_I 1 50 10000M * 0 0 * *
r5-1 0 CHROMOSOME_I 5000 50 100M * 0 0 * *
r5-2 0 CHROMOSOME_I 5000 50 100M * 0 0 * *
12 changes: 12 additions & 0 deletions test/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,18 @@ sub test_index
unlink("$$opts{tmp}/index.cram.crai");
test_compare($opts,"$$opts{path}/test_index $$opts{tmp}/index.cram", "$$opts{tmp}/index.cram.crai", "$$opts{path}/index.cram.crai", gz=>1);

# CRAM container skipping test
# Prepare a file with records split into multiple containers, the first two
# records spanning far enough to overlap the last two.
cmd("$$opts{path}/test_view $nthreads -C -p $$opts{tmp}/index3.cram -x $$opts{tmp}/index3.cram.crai -o seqs_per_slice=2 $$opts{path}/index3.sam");
# An index lookup for the last two records should return the first two
# as well.
test_compare($opts, "$$opts{path}/test_view $nthreads -p $$opts{tmp}/index3_rgn.sam $$opts{tmp}/index3.cram CHROMOSOME_I:5000-5100",
"$$opts{path}/index3_exp.sam", "$$opts{tmp}/index3_rgn.sam");
# Also check the multi-region iterator
test_compare($opts, "$$opts{path}/test_view $nthreads -M -p $$opts{tmp}/index3_rgnm.sam $$opts{tmp}/index3.cram CHROMOSOME_I:5000-5100",
"$$opts{path}/index3_exp.sam", "$$opts{tmp}/index3_rgnm.sam");

# BCF
test_compare($opts,"$$opts{path}/test_view $nthreads -l 0 -b -m 14 -x $$opts{tmp}/index.bcf.csi $$opts{path}/index.vcf > $$opts{tmp}/index.bcf", "$$opts{tmp}/index.bcf.csi", "$$opts{path}/index.bcf.csi", gz=>1);
unlink("$$opts{tmp}/index.bcf.csi");
Expand Down