This is a test version of Biostars. For the public version, visit https://www.biostars.org.
samtools BGZF block error

Hi all, I tried to run samtools depth on my bam file to generate average depth using

samtools depth input.bam | awk '{sum+=$3} END { print "Average = ",sum/NR}'

This gave me the following error

[E::bgzf_read_block] Failed to read BGZF block data at offset 46634025926 expected 12816 bytes; hread returned -1
[E::bgzf_read] Read block operation failed with error 4 after 0 of 4 bytes
Average =  34.0651

Not sure what is going on. Is the average output fine or should I be concerned with this error message? I tried googling this error and also tried this but appears there there were no issues

samtools quickcheck -qvvv inout.bam
verbosity set to 3
checking NA24695C.bam
opened NA24695C.bam
NA24695C.bam is sequence data
NA24695C.bam has 3366 targets in header.
NA24695C.bam has good EOF block.

I got a similar type of error running coverage on my bam file. It appears that the coverage is not calculated any other #rname other than chr1. They were all zeros. This error appears to be present irrespective of the input BAM file.

samtools coverage input.bam

#rname  startpos    endpos  numreads    covbases    coverage    meandepth   meanbaseq   meanmapq
[E::bgzf_read_block] Failed to read BGZF block data at offset 3724556367 expected 12617 bytes; hread returned -1
[E::bgzf_read] Read block operation failed with error 4 after 0 of 4 bytes
chr1    1   248956422   43909613    174013226   69.8971 26.2529 34.9    50.8
chr2    1   242193529   0   0   0   0   0   0
chr3    1   198295559   0   0   0   0   0   0
chr4    1   190214555   0   0   0   0   0   0
chr5    1   181538259   0   0   0   0   0   0
chr6    1   170805979   0   0   0   0   0   0
chr7    1   159345973   0   0   0   0   0   0
chr8    1   145138636   0   0   0   0   0   0
samtools

Update: I just discovered that the error message could be due to running samtools over VPN. There was no issue with the BAM as I was able to run the samtool command onsite without any error message.

1 answer

your file input.bam is broken/corrupted. There is nothing you can do but regenerating this file.

Pierre, thank you. When you say broken/corrupted does it mean I cannot use it in anyway? i was able to run samtools mpileup just this week on the same BAMs without any issues though?

I cannot use it in anyway?

you shouldn't. Run samtools view -c in.bam on this file, and you should get the same error if I'm not wrong

Log in to answer this question.