samtools view - F 4 removes sam header and truncates file??
1
2
Entering edit mode
8.2 years ago
nash.claire ▴ 490

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
749598

samtools view -c -F 4 mappedonce.sam
12116420

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 • 13k views
ADD COMMENT
6
Entering edit mode
8.2 years ago
abascalfederico ★ 1.2k

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

ADD COMMENT

Login before adding your answer.

Traffic: 1972 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