An update on the issue,
I was able to seek and tell the BAM file by using

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?

Claudio

On 04/12/2015 12:11, Claudio Alberti wrote:
Dear Samtools team,
I'm writing a BAM parser by integrating htslib and I need to be able to tell and seek a BAM file to read back and forth BAM records. I'm using bam_read1 to sequential read records but sometime I have to go back and continue from a previous position, so I'm looking for a tell/seek type API. I found htell and hseek in hfile.h, but they seem to be not working the way I expected.

I currently try this to record the cursor position and then come back to the same record

iCurPos = htell(htsInputFile->fp.bgzf->fp)

...some bam_read1 calls....

hseek(htsInputFile->fp.bgzf->fp, iCurPos, SEEK_SET)

After the hseek call the bam_read1 calls continue reading without going back to iCurPos.

What am I doing wrong?
Is there any other way to achieve this.
Thanks!
Kind regards,
Claudio

--
Claudio Alberti
----------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/samtools-help

--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/samtools-help

Reply via email to