sambamba-sort: Error reading BGZF with BAM file
1
0
Entering edit mode
3.9 years ago

I have aligned a file with BWA MEM but since the file is big (1 Tb) I could not sort it with samtools due to memory limits. I tried with sambamba but I got an error:

$ bwa mem -t 12 <ref.fa> <input_1.fq.gz> <input_2.fq.gz> > <output>.bam 
$ sambamba sort -o <output>_AlnSrt.bam <output>.bam 
sambamba-sort: Error reading BGZF block starting from offset 0: wrong BGZF magic

What is this error about?

Thank you

software error sort sambamba • 4.0k views
ADD COMMENT
1
Entering edit mode

the output of bwa-mem is an unsorted SAM file, not a BAM file.

ADD REPLY
2
Entering edit mode
3.9 years ago
ATpoint 82k

Unlike samtools the sambamba sort function does only accept BAM files whereas bwa outputs SAM, therefore:

bwa mem (...) \
| sambamba view -f bam -S -l 0 /dev/stdout /dev/stdin \
| sambamba sort -o output_AlnSrt.bam /dev/stdin

or use samtools. These days they are equally fast afaik. By the way, samtools sort does not have a memory limit. It has an option -m that decides how much RAM is used to keep temporary data in memory before spilling them to disk as tmp files. You can sort your file with it. It is recommended though that you do not store SAM files due to the size. You can directly store as BAM having a notably reduced file size.

bwa mem (...) | samtools view -o out.bam
ADD COMMENT
0
Entering edit mode

Thanks, I overlooked the conversion -- that's why the file was so large. Usually, I pipe everything including samtool sort. Is there a better tool to sort a large bam file?

ADD REPLY
0
Entering edit mode

No afaik, I think samtools and sambamba are as good as it gets. For large files it will take time though unless you have a lot of memory so you can keep larger chunks in RAM. But yes, piping is definitely desirable to avoid large intermediate files that you eventually are going to delete anyway.

ADD REPLY

Login before adding your answer.

Traffic: 1849 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6