This is a test version of Biostars. For the public version, visit https://www.biostars.org.
What Is Practical Issues For Samtools Not Able To Sort The Sam File Directly?

I was just wondering why we always needs to convert .sam to .bam and the sort it and convert back to .sam Any programming bottle necks to handle .sam file directly for this?

samtools sort sam bam

If you convert a sorted .bam file to .sam file, are you sure the .sam file is sorted?

yes, the samtools view command output the records in the bam file in the order they are stored.

3 answers

Sorting is a resource consuming operation, the binary formats will sort much faster.

Why would you convert back to sam? Leave things in .bam as much as possible. You probably only need to eyeball exerpts of your .sam file. pipe samtools view into something else if you have to run awk or grep or something like that on a ,bam file

Or instead of using awk/grep on the output of samtools view, bamtools can be helpful to query bams directly.

I did all the piping and to get the sorted sam. I have methylation data (bismark generated sam file); Some of the R packages (say methylKit) need sorted SAM files only.

You could use Picard's SortSam tool to just sort the .sam file directly.

Log in to answer this question.