Filtering Multiple Flags With Samtools
2
2
Entering edit mode
12.0 years ago
dsbreak ▴ 170

I am trying to remove paired-end reads from a .SAM file where neither segment is mapped (i.e. having both 0x4 AND 0x8 set). When I try the command "samtools view -F 12" it appears to remove reads where either 0x4 OR 0x8 are set.

1) Am I correct in understanding the samtools help notes that -F performs a logical OR (and that -f performs a logical AND)?

2) If so, any thoughts on how to perform this aside from awk?

samtools • 13k views
ADD COMMENT
0
Entering edit mode
ADD REPLY
0
Entering edit mode

Serially filtering with -f 4 -F 264 and -f 8 -F 260, and then merge/sort -n did the trick. Thanks!

PS. Any way to flag this as an answer?

ADD REPLY
0
Entering edit mode

Copy and paste it into the answer field. I believe you can accept your own answer.

ADD REPLY
0
Entering edit mode

Hrmm... when I try and click the green check symbol, I get a "You may not vote on your own post"

ADD REPLY
1
Entering edit mode
12.0 years ago
Rm 8.3k

Here it is added as answer: Have a look at this: http://www.novocraft.com/documentation/novoalign-2/novoalign-ngs-quick-start-tutorial/1040-2/

ADD COMMENT
1
Entering edit mode
12.0 years ago
Andreas ★ 2.5k

For the sake of completeness, here the awk snippet which you were were asking for

samtools view your-bam-file | \
  awk 'BEGIN {FS="\t"; OFS="\t"} {
    if (/^@/ && substr($2, 3, 1)==":") {print}
    else if (and($2, 0x4) && and($2, 0x8)) {print}}

The first line makes sure to use tabs as input and output delimiters. The second makes sure to print the header The third does your requested filtering: 0x4 and 0x8 have to bet set.

Andreas

ADD COMMENT
0
Entering edit mode

Hi, I tried using this script. It prints the sam header, but not the rest of the file that matches the correct bits. It gives the error awk: "calling undefined function and input record number 4". There are only three lines of header.

Any ideas? Thanks!

ADD REPLY
0
Entering edit mode

Which awk version is this? I used gawk...

ADD REPLY

Login before adding your answer.

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