SAM Format FLAG 설명, 추출, 분석 방법

FLAG란?

Sequence Alignment/Map (SAM) format에서 FLAG는 alignment section에서 2번째 column의 정보로, sequence가 alignment된 상태를 표현한다. FLAG는 총 12자리의 이진수를 십진수로 표현하며, 이진수의 각 자리가 0인지, 1인지에 따라 그 상태의 유무를 판단할 수 있다. 예를 들어, paired-end library로 시퀀싱된 read 두 쌍이 mapping되었으면 FLAG의 첫 번째 자리 수가 1이 된다. 만약 FLAG 첫 번째 자리수가 0이면 그 read는 쌍이 없다는 것이 된다.

FLAG는 bit로 표현된다

Bit 16진수 Description
1 0x1 template having multiple segments in sequencing
2 0x2 each segment properly aligned according to the aligner
4 0x4 segment unmapped. mapping이 안 된 것을 의미한다.
8 0x8 next segment in the template unmapped
16 0x10 SEQ being reverse complemented
32 0x20 SEQ of the next segment in the template being reverse complemented
64 0x40 Paired reads를 mapping했을 때, 첫 번째 read를 의미한다.
128 0x80 Paired reads를 mapping했을 때, 두 번째 read를 의미한다.
256 0x100 Secondary alignment. Primary alignment가 아님을 의미한다. 하나의 read가 여러 군데 mapping되었을 경우, 첫 번째로 mapping된 경우가 아닌 것을 의미한다.
512 0x200 not passing filters, such as platform/vendor quality controls
1024 0x400 PCR or optical duplicate.
2048 0x800 supplementary alignment. Chimeric alignment.

FLAG 예시

예를 들어, 아래 FLAG는 355 (256 + 64 + 32 + 2 + 1)이다. FLAG가 355인 alignment record는 쌍으로 매핑되고 (0x1), 두 read 모두 매핑되었고 (0x2), 첫 번째 read의 alignment (0x40)이며, 두 번째 alignment는 reverse complement (0x20)되었고, secondary alignment (0x100)인 것을 의미한다.

FLAG를 일일히 bit로 나누어 계산해보는 것은 복잡하다. Broad Institute에서 이를 쉽게 하도록 툴 (Decoding SAM Flags)을 개발해두었다.

특정 FLAG의 SAM record 추출

특정 FLAG의 alignment record를 추출하는 것은 samtools view를 이용하면 쉽게 할 수 있다. -f 옵션을 사용하면 포함하고 싶은 FLAG를, -F 옵션을 사용하면 제외하고 싶은 FLAG를 정할 수 있다. 만약 -f 3 옵션을 사용하면 0x1, 0x2를 포함한 모든 FLAG에 대한 alignment record를 출력한다.

예시

# Unmapped reads를 추출
samtools view -f 0x4 input.bam

# Paired reads만 추출 + Unmapped reads를 제외
samtools view -f 3 -F 0x4 input.bam

답글 남기기