Question about SAMTOOLS command
1
0
Entering edit mode
8.8 years ago
biolab ★ 1.4k

Hi everyone,

My sam files contains only three flag values:0, 4, 16. I want to filter out the flag values of 4 and 16, so I used a pipe as follows.

samtools view -Sh -F 4 in.sam | perl -F"\t" -ane 'print if /\@/; print if $F[1] == 0' | samtools view -Sb - > out.bam

After subsequent samtools sort out.bam out.sorted and samtools index out.sorted.bam steps, I run samtools tview, but see nothing there. Is my command wrong? Any of your comments will be much appreciated. THANKS!

samtools • 2.4k views
ADD COMMENT
0
Entering edit mode

Why don't you use -f or -F option of samtools to filter based on flag ?

ADD REPLY
0
Entering edit mode

Hi Geek_y, thank you for your comment.

ADD REPLY
1
Entering edit mode

samtools -F is definitely the way to go, but just for sake of completeness, one error in your perl snippet is /\@/, which should be /^@/.

ADD REPLY
0
Entering edit mode

Thank you thackl.

ADD REPLY
5
Entering edit mode
8.8 years ago

Why not just samtools view -SbF 20 in.sam > out.bam? Your perl command is probably mucking things up.

ADD COMMENT
0
Entering edit mode

Hi, Devon, thank you very much! Your command works well.

ADD REPLY
0
Entering edit mode

Fyi, have a look at http://broadinstitute.github.io/picard/explain-flags.html to get you numeric flag representations right, especially if you need to combine different flags.

ADD REPLY

Login before adding your answer.

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