# sorting BAM file error using samtools

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.
[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.
• Then either /tmp is full or otherwise one of the files there is somehow corrupt (you can test them with samtools view -H too). – Devon Ryan Dec 14 '17 at 14:29
• Don't forget to samtools index sorted.bam – Devon Ryan Dec 14 '17 at 15:21