This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Question about SAMTOOLS command

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

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

Hi Geek_y, thank you for your comment.

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

Thank you thackl.

1 answer

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

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

Log in to answer this question.