Question: sambamba-sort: Error reading BGZF with BAM file
0
gravatar for marongiu.luigi
5 weeks ago by
Germany, Mannheim, UMM
marongiu.luigi510 wrote:

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

sambamba sort software error • 108 views
ADD COMMENTlink modified 5 weeks ago by ATpoint36k • written 5 weeks ago by marongiu.luigi510
1

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

ADD REPLYlink written 5 weeks ago by Pierre Lindenbaum129k
2
gravatar for ATpoint
5 weeks ago by
ATpoint36k
Germany
ATpoint36k wrote:

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 COMMENTlink modified 5 weeks ago • written 5 weeks ago by ATpoint36k

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 REPLYlink written 5 weeks ago by marongiu.luigi510

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 REPLYlink modified 5 weeks ago • written 5 weeks ago by ATpoint36k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 947 users visited in the last hour