Question: samtools view - F 4 removes sam header and truncates file??
gravatar for nash.claire
4.1 years ago by
nash.claire380 wrote:

Hi guys,

Question, I have a couple of sam files that I got from aligning with Bowtie2. I am trying to sort through them to remove the usual stuff (multi-mapping etc etc) after reading posts and guides etc etc. So far I've been successful in taking my sam files, running sed '/XS:/d' algn.sam > mappedonce.sam and getting rid of all those with an XS flag. When I then run the following :- 

samtools view -c -f 4 mappedonce.sam


samtools view -c -F 4 mappedonce.sam


I can see that I have 749598 reads that are unaligned which I want to remove. So I ran this as per posts on biostars

samtools view -F 4 -o mapped1_mapped.sam mappedonce.sam

However, when I then take this file after running the -F 4 filter, if I try and run anything else such as flagstat or even the samtools view -c -F 4 mappedonce.sam again, I get the following error:

[E::sam_parse1] missing SAM header

[W::sam_read1] parse error at line 1

[main_samview] truncated file.

So what is samtools doing to my file? Is there a reason why samtools would remove a header line and truncate my file? Am I doing something wrong? Consequently, if anyone has any non-samtools solutions to remove these 749598 reads I'd be open to that!

rna-seq alignment • 7.2k views
ADD COMMENTlink modified 4.1 years ago by abascalfederico1.1k • written 4.1 years ago by nash.claire380
gravatar for abascalfederico
4.1 years ago by
abascalfederico1.1k wrote:

You need the -h option in samtools view so the header is also printed out.

ADD COMMENTlink modified 6 weeks ago by RamRS25k • written 4.1 years ago by abascalfederico1.1k
Please log in to add an answer.


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