Tutorial:How to select reads with specific flag using samtools
0
10
Entering edit mode
6.6 years ago
imlituan ▴ 110

In sam and bam files, flag is used to indicate the alignment state of the read, each flag has 11 positions when expressed as binary numbers, and each position indicates a specific attribute, which is shown below, 0x1 represents the first position, 0x400 represents the 11th position. At each position, 1 indicates the read has this attribute, 0 indicates the read lacks this attribute. For example, a flag 4 is 00000000100, indicates that this read is unmapped.

Bit Description

  1. 0x1 template having multiple segments in sequencing
  2. 0x2 each segment properly aligned according to the aligner
  3. 0x4 segment unmapped
  4. 0x8 next segment in the template unmapped
  5. 0x10 SEQ being reverse complemented
  6. 0x20 SEQ of the next segment in the template being reversed
  7. 0x40 the first segment in the template
  8. 0x80 the last segment in the template
  9. 0x100 secondary alignment
  10. 0x200 not passing quality controls
  11. 0x400 PCR or optical duplicates

samtools can select reads according to their flags.

-f INT    Only output alignments with all bits set in INT present in the FLAG field. INT can be specified in hex by beginning with `0x` (i.e. `/^0x[0-9A-F]+/`) or in octal by beginning with `0` (i.e. /`^0[0-7]+/`) [0].
-F INT    Do not output alignments with any bits set in INT present in the FLAG field. INT can be specified in hex by beginning with `0x` (i.e. `/^0x[0-9A-F]+/`) or in octal by beginning with `0` (i.e. `/^0[0-7]+/`) [0].
-G INT    Do not output alignments with all bits set in INT present in the FLAG field. This is the opposite of -f such that -f12 -G12 is the same as no filtering at all. INT can be specified in hex by beginning with `0x` (i.e. `/^0x[0-9A-F]+/`) or in octal by beginning with `0` (i.e. `/^0[0-7]+/`) [0]

When you want to select reads with a specific flag, none of this option only will get what you want. You can get what you want by combining -f and -F. For example, if you want a flag 67, which is 00001000011, the complement flag is 11110111100, which is 1980. Then samtools view -f 67 -F 1980 will get reads with flag exactly 67.

Example

next-gen-sequencing • 9.2k views
ADD COMMENT
0
Entering edit mode
ADD REPLY

Login before adding your answer.

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