[Biopython] [Samtools-help] SAM to BAM

Peter Cock p.j.a.cock at googlemail.com
Mon Oct 17 13:06:58 UTC 2011


On Mon, Oct 17, 2011 at 1:11 PM, Mic <mictadlo at gmail.com> wrote:
> Hello,
> Is there a way to convert SAM file to sorted BAM file and generate also BAI
> file with pysam?
> Thank you in advance.

With samtools at the command line,

samtools view -b -S example.sam | samtools sort - example
samtools index example.bam

I know you can easy call samtools from pysam, not sure if you
can do the pipe trick to avoid extra steps:

samtools view -b -S example.sam > example_unsorted
samtools sort example_unsorted.bam example
rm example_unsorted.bam
samtools index example.bam

Peter



More information about the Biopython mailing list