Samtools Adding Head reduces file size
0
1
Entering edit mode
8.2 years ago

Hi all,

I'm trying to convert my SAM to BAM files using samtools, to subsequently view them in IGV. When I do

samtools faidx reference.fasta

samtools view -bt reference.fasta.fai file1.sam > file1.bam

I get the error

[E::sam_parse1] missing SAM header 
[W::sam_read1] parse error at line 1

However, when I'm trying to add the header using the following code, my bam file size reduces massively (from 127mb to 27mb).

samtools view -bt reference.fasta.fai file1.sam > file1.bam

What's going on here and can someone give me a hint on what to do?

Many thanks guys!

samtools bam sam python igv • 1.8k views
ADD COMMENT
1
Entering edit mode

You mean a 127Mb SAM to a 27Mb BAM? BAM is a gzipped (compressed) SAM file. More or less.

ADD REPLY
0
Entering edit mode

IF I dont add '-bt reference.fasta.fai' my BAM file becomes 127mb (similar to SAM), whereas it becomes 27mb when adding that option.

ADD REPLY
0
Entering edit mode

You need the -b option to output a BAM file - hence when you have -b you are getting a compressed binary file of only 27MB.

When you do not have the -b option you are basically outputting in the SAM standard text format, which is uncompressed and gives you the 127MB.

This will correctly give you a SAM to BAM conversion

samtools view -bt reference.fasta.fai file1.sam > file1.bam

This will create a file called file1.bam but will be in SAM format not BAM format (just because you call a file .bam doesn't make it a BAM file)

samtools view file1.sam > file1.bam
ADD REPLY

Login before adding your answer.

Traffic: 1683 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6