This is a test version of Biostars. For the public version, visit https://www.biostars.org.
samtools sorts allocate memory for bam_mem issues

Hello everyone

I am trying to convert sam to bam

samtools sort -@ 8 -o UHR_Rep1.bam UHR_Rep1.sam

and I got this error

samtools sort: couldn't allocate memory for bam_mem

I check my disk memory and I see have enough space in my disk.How I can achieve this problem?

samtools rna-seq

Output of free -mh? Disk space != memory fyi

free -hw

              total        used        free      shared     buffers       cache   available
Mem:      3,7Gi       2,0Gi       277Mi       387Mi        99Mi       1,4Gi       1,2Gi

Swap:      2,0Gi   381Mi      1,6Gi

do you asked for it ? ı dont know how much it is need.

How ı can allocate mem properly for convert to sam to bam file via samtools

1 answer

Depending on the size of the BAM file you have you may not be able to do this on your machine. You have only 3.7 G of RAM out of which 1.2 G seems to be available when you ran the above command. Generally samtools will use temporary files to do the sort (and writes them to the directory you ran this from, I assume that is the disk where you have space).

I suggest that you try this sort with just one thread (i.e remove -@ 8) and see if following works. It may take a while to sort the file so be patient if the following starts running without the memory error.

samtools sort -o UHR_Rep1.bam UHR_Rep1.sam

yay it works.thank you very much GenoMax.

Yes, because each additional thread needs about 800MB of memory by default so that exceeded what you had when using 8 threads.

Log in to answer this question.