This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how many files are generated after sorting of .bam file ?

I used the following command for the sorting of bam file (samtools sort eg2.bam -o eg2.sorted.bam) size of my sam file was 44.6GB and after conversion into bam it is 35GB. sorting of bam file is producing a large no. of temporary files in MB.

rna-seq alignment

either you can furnish a temporary directory for storing temporary files or wait till the process is over. Only one sorted bam file be output as per OP function. iqraishtiaq411

indexing of .bam file is giving this error . how it would be handle ?

samtools index my_sorted.bam
[E::hts_idx_push] Region 536938519..536938598 cannot be stored in a bai index. Try using a csi index with min_shift = 14, n_lvls >= 6
samtools index: failed to create index for "my_sorted.bam": Numerical result out of range

Check this

Are you using the latest version of samtools?

samtools 1.7 Using htslib 1.7-2 Copyright (C) 2018 Genome Research Ltd.

1 answer

SAMtools by default uses 768Mb memory per thread, so when sorting larger bams it will have to write a large amount of temporary files to disk. If you have RAM memory available, you can reduce disk writing (and execution time) by giving samtools more memory per thread:

-m INT     Set maximum memory per thread; suffix K/M/G recognized [768M]

As cpad0112 stated, when the sorting is finished, all temporary files are deleted and only the final sorted file should remain. If this is not the case, samtools sort did not finish successfully.

If memory is a problem, but CPUs aren't, consider sambamba sort because the memory specified with -m is the total memory (so not per thread), so you can get many CPUs working without worrying about memory.

Log in to answer this question.