Question: Samtools View: Only Forward Or Reverse Strand
11
gravatar for Gregor Rot
9.0 years ago by
Gregor Rot450
Zurich, Switzerland
Gregor Rot450 wrote:

Hello,

i would like to only get reads that aligned to the forward / reverse strand separately. I am using this for now:

samtools view -F 20 ... : forward strand
samtools view -f 0x10 ... : reverse strand

Is this correct? With -F 20 i also ignore the not aligned reads.

Tnx!

Gregor

samtools strand • 23k views
ADD COMMENTlink modified 5 months ago by brianpenghe50 • written 9.0 years ago by Gregor Rot450
5
gravatar for Pascal
9.0 years ago by
Pascal1.5k
Barcelona
Pascal1.5k wrote:

Gregor,

For me it makes sense because I just verified that the the sum of:

samtools view -c -F 16 [BAM_FILE]
+
samtools view -c -f 16 [BAM_FILE]

is equal to:

samtools view -c [BAM_FILE]

;-)

Pascal

ADD COMMENTlink written 9.0 years ago by Pascal1.5k

Hey there,

I want to subtract the reads from forward and reverse strand, from a BAM file of Histone ChiP-seq data, to get the net reads mapping on either forward/reverse strand, how to do that. Any suggestions will be appreciated.

ADD REPLYlink written 6.3 years ago by Chirag Nepal2.2k
3
gravatar for Chris Penkett
9.0 years ago by
Chris Penkett480
Cambridge, UK
Chris Penkett480 wrote:

0x20 is if your data is paired end and will filter based on the strand of the mate. You want 0x10 for the query. For standard NGS data, mostly your pairs should be on the opposite strands anyway - except for weird events like DNA translocations, e.g., inversions.

[There is a slide (Using NGS Data to find chromosomal rearrangements) in this [PDF][1] to explain how the pairs will behave for these events.]

so do this for forward:

samtools view -F 0x10

and this for reverse:

samtools view -f 0x10

Use the -X flag in "samtools view" to convert the flag column from a numeric bit field to letters (as described here) like this:

% samtools view -Xf 0x10 accepted_hits.bam | head -1
24_727_529_F3   r   chr1    2   0   50M *   0   0   ATCCAGCATCCAGCATCCAGCATCCAGCATCCAGCATCCAGCATCCAGCA  @@!!",>4CS/!!;UPB!(QB>=EH5/!>T>9?S^ZUQZaZVY\_]^bcc  NM:i:0  NH:i:31 CC:Z:=  CP:i:9
% samtools view -XF 0x10 accepted_hits.bam | head -1
2118_596_811_F3     chr1    5367    3   50M *   0   0   CAGTGCAATCGTTTATAGACACAAACACCTTTTCCGCTGTTGATGGTGGT  ___ZZHFZ\]PPRUb_ZNQUNOQYYP!!!#ROLPZSRNO@/GH2=NL;..  NM:i:0  NH:i:2  CC:Z:=  CP:i:2868239
ADD COMMENTlink modified 9.0 years ago • written 9.0 years ago by Chris Penkett480

Chris, I think that Gregor was right: observe he did say "20" and not "0x20" as you assumed in your response. 20 = 0x10 + 0x04.

ADD REPLYlink written 9.0 years ago by Pascal1.5k

True - it was confusing as he mixed hex and dec values.

ADD REPLYlink written 9.0 years ago by Chris Penkett480
6

I found for using single end reads it could be written also as

samtools view -F 20 ... : forward strand
samtools view -f 16 ... : reverse strand
samtools view -f 4 ... : unmapped

And since I don't see it mentioned on this particular page, I'll add that tool at https://broadinstitute.github.io/picard/explain-flags.html is particularly helpful for making and deciphering these commands. The fact that the flag 20 includes both unmapped and those mapped to the reverse strand was not obvious to me at first. Bitwise is a compact but not immediately obvious way to indicate these sets. Slides 28-31 of Pierre Lindenbaums's presentation, which he highlighted in this post SAM flags meaning  helped a lot.

ADD REPLYlink written 5.6 years ago by Wayne390
1

Thanks ! Specially, the URL from broadInstitute was very useful. 

ADD REPLYlink written 5.6 years ago by Chirag Nepal2.2k

The option "-h" is important to further use of bam files. Need to keep the SAM header which is mondatory : samtools view -F 20 -h ... : forward strand

ADD REPLYlink modified 4.4 years ago • written 4.4 years ago by Samad90

agree, it's not obvious at all.. wondering what would be the command for PE reads?

ADD REPLYlink written 4.3 years ago by epigene490

I also wonder the command for PE reads

ADD REPLYlink written 4.2 years ago by hxlei61390
0
gravatar for brianpenghe
5 months ago by
brianpenghe50
United States
brianpenghe50 wrote:

They forgot unmapped reads!!!! Please use these:

samtools view -c alignment.bam -F 16 -F 4

samtools view -c alignment.bam -f 16

ADD COMMENTlink modified 5 months ago • written 5 months ago by brianpenghe50
Please log in to add an answer.

Help
Access

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