Thanks James,
it seems that bgzf_seek and bgzf_tell work better even if I get a crash after about 43000 reads...
What I do now is

iPos = bgzf_tell()

some read_bam1 calls...

bgzf_seek(iPos)

Claudio

On 07/12/2015 16:33, James Bonfield wrote:
Hello Claudio,

On Mon, Dec 07, 2015 at 12:18:22PM +0100, Claudio Alberti wrote:
lOffset = hts_utell(htsInputFile);
hts_useek(htsInputFile, lOffset, SEEK_SET);

Now the problem is that after parsing a few records I get an assertion

bgzf_useek: Assertion `fp->block_offset <= fp->block_length' failed.

fp->block_offset is 66644 while block_length is 65498.
Any idea why this is happening and how to prevent it?
See also this thread:

http://sourceforge.net/p/samtools/mailman/message/34430632/

I'm less clear on the actual fix though, sorry for not realising this
earlier when I replied to you.  From reading that thread it appears:

- hts_seek / hts_tell (or useek/utell) aren't supported functions.
   They're not in public header files, so shouldn't be expected to work
   (and indeed don't in all cases as you've seen).  I'm not sure what's
   missing / broken though, perhaps just the purging of the read-ahead
   buffer after a seek.

- htell/hseek only work if all of your I/O is via the lower level
   hFILE object.  If you try to fix hts_file I/O with htell/hseek then
   the buffering breaks things.  (The analogy is lseek on a fileno(fp)
   for FILE* and then try using fread.)

I'm not sure the solution actually exists therefore apart from rolling
your own interface or avoid using the hts_file layer and do all BAM
reading via the lower level bgzf_open/bgzf_read layer. (And similarly
with a different code path for CRAM.)

Probably not the answer you wanted.

James


--
Claudio Alberti
----------------------------------------------
http://gramm.epfl.ch
EPFL SCI STI MM
ELG 140 (ELG Building)
Station 11
CH-1015 Lausanne - Switzerland
Tel. +41 21 6936869
----------------------------------------------

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
Samtools-help mailing list
Samtools-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/samtools-help

Reply via email to