This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Sam To Bam

I sequenced a mito genome using paired end method on the mi-seq I mapped all the reads back to reference gnome using BWA and got output of a Sam file I want to convert to BAM format but I am getting errors. This first line of my sam file is "@SQ SN:TAC111F LN:16753" all my following lines do not have the @ sign. This is the out put I get [samopen] SAM header is present: 1 sequences. Im using this comand $ samtools view -bT reference.fa test.sam > test.bam can any one help me

sam bam bwa alignment

There might be several issues going on here. For the sam > bam step use the -bS flag. This tells samtools you are inputing a SAM file and want a BAM file.

1 answer

Read the samtools manual carefully. Your command usage shows that you haven't done your homework properly before asking the question.

FIrst of all there is no "-T" (capital T) parameter that I know of. The "-t" (small t) parameter is used when your aligner hasn't generated header for sam file. But as you have used BWA, header should be present in the SAM file. All you need is: samtools view -bhS your.sam > your.bam

Since at least version 0.1.12a, there is a -T option, it's just the manual page on the website is out of date.

-T FILE  reference sequence file (force -S) [null]

This forces the -S flag (making it assume sam input), meaning that that the command should work.

What is the error? SAM header is present is not an error message; it's just an informational status. Maybe it's working fine?

Thanks for the information. Yes may be there is no error.

When I try to ope the Bam file in text wrangler its just symbols with no useful information

You can't open BAM file using a text editor. It is a binary version of SAM file. If you to view the bam file, you need samtools. Try this command : samtools view input.bam | more

Log in to answer this question.