Question: Samtools Adding Head reduces file size
1
gravatar for martijnkelder
2.7 years ago by
martijnkelder10 wrote:

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!

igv sam samtools bam python • 859 views
ADD COMMENTlink written 2.7 years ago by martijnkelder10
1

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

ADD REPLYlink written 2.7 years ago by John12k

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 REPLYlink written 2.7 years ago by martijnkelder10

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 REPLYlink written 2.7 years ago by Tonor420
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 817 users visited in the last hour