This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Remove Header from SAM - File

Hey there,

I need to remove a header from a SAM file that I generated from a BAM file. Can this removal be performed on the SAM file directly?

I am fairly new to bioinformatics, just started my PhD. If a solution employing samtools, bedtools or similar would be possible, I'd appreciate it.

Thanks a lot,

Cheers
Stefan

sequencing software-error next-gen

2 answers

In a SAM (not BAM) file, the header lines start with @. So a simple grep excluding that pattern would work:

grep -v '^@' your.sam > noheader.sam

But whatever you're doing, there is no really much interest in removing a SAM header. May be you're looking for

samtools reheader <in.header.sam> <in.bam>

hey thanks for the quick reply,

yeah I'm not sure about the header removal... I am trying to implement the SVdetect program for CNV detection and always get the error "illegal division in line 2883..." because the script works with the example files and example configuration file and also with my created config file and the example data sets, i figured the problem is my input sam files. The difference between my Sam files and the example sam files is the absence of the header i think...

cheers

It is highly unlikely that line 2883 is a part of the header. I am not saying it can't be but it is unusual. So removing the header should not solve your problems. Post the full error and also line number 2883 from your SAM file.

Check this link. In your case, you don't need header. So, do not use option -h.

Log in to answer this question.