I have few bam files and would like to get read counts using

samtools idxstats

[Data is aligned to hg19 transcriptome]. To use that command I need a sorted bam file. So to sort them I gave the following command.

samtools sort -T /tmp/input.sorted -o input.sorted.bam input.bam

This ended up showing:

[W::bam_hdr_read] EOF marker is absent. The input is probably truncated.
[E::bgzf_read] bgzf_read_block error -1 after 0 of 4 bytes
[bam_sort_core] truncated file. Aborting.

And the tmp dir has 6 input.sorted.nnnn.bam files.


The cause of the error is that your input file is truncated or /tmp is running out of space. If you can do samtools view -H input.bam without error (reading the header also checks for the magic number at the end of the file) then it's like the that /tmp is filling up.

| improve this answer | |
  • $\begingroup$ I did "samtools view -H input.bam" there is no error. It ended up showing all the header things which I asked here [bioinformatics.stackexchange.com/questions/3080/… $\endgroup$ – stack_learner Dec 14 '17 at 14:17
  • $\begingroup$ Then either /tmp is full or otherwise one of the files there is somehow corrupt (you can test them with samtools view -H too). $\endgroup$ – Devon Ryan Dec 14 '17 at 14:29
  • $\begingroup$ Ok. looks like that file is corrupt. And I tried with other bam file and showed - [bam_sort_core] merging from 24 files... and I see a sorted.bam file. I used "samtools idxstats sorted.bam" - This is what I see - [bam_idxstats] fail to load the index. $\endgroup$ – stack_learner Dec 14 '17 at 15:21
  • $\begingroup$ Don't forget to samtools index sorted.bam $\endgroup$ – Devon Ryan Dec 14 '17 at 15:21
  • $\begingroup$ Ok. So, after the indexing I used idxstats and it showed 4 columns without any headers. NR_039978 984 38 0 NM_130786 1766 1 0 NM_138932 9293 37 0 NM_033110 2678 2 0 NM_000014 4678 4 0 NM_144670 5192 18 0 NR_040112 1201 2 0 NM_017436 2106 76 0 NM_016161 1771 0 0 $\endgroup$ – stack_learner Dec 14 '17 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.