Major Study./Bioinformatics

SAM/BAM 포맷, 구조 분석

sosal 2014. 12. 12. 19:08
반응형


/*

 http://sosal.kr/
 * made by so_Sal
 */


NGS data analysis의 workflow를 공부하면서, SAM과 BAM format을 공부하게 되었습니다.


SAM 포맷의 간단한 예는 다음과 같습니다.



적당히 구글에 sam file example 정로로 검색하면 나오는 파일입니다.

정확한 URL은 다음과 같습니다.

https://code.google.com/p/bamseek/downloads/detail?name=ex1.sam



http://samtools.github.io/hts-specs/

링크에 들어가시면 다음과 같은 포맷들의 specification 문서가 나옵니다.




여기서 SAMv1 파일을 열람하여 SAM file의 구조를 공부하였습니다.



BAM과 SAM의 format 차이점은?


- http://genome.sph.umich.edu/wiki/BAM


The BAM Format is a binary format for storing sequence data.

The current definition of the format is at [BAM/SAM Specification].

The corresponding SAM Format can be used to store sequence data, both aligned as well as unaligned, in a human readable format.

BAM and SAM formats are designed to contain the same information. The SAM format is more human readable, and easier to process by conventional text based processing programs, such as awk, sed, python, cut and so on. The BAM format provides binary versions of most of the same data, and is designed to compress reasonably well.




http://trac.seqan.de/wiki/Tutorial/SamBamIO

Besides the fact that BAM is a compressed, binary format, the main difference to the plain-text format SAM is that BAM has additional header information: The binary header of BAM files contains a plain-text SAM header with the same information as a SAM file. However, BAM files contain an additional binary header section that stores all reference sequence names and their length.



적당히 요악하면 다음과 같습니다.

1. SAM과 BAM은 모두 sequence를 저장하며, 같은 정보를 가지고있다.

2. SAM은 text file로, string 형식으로 저장되어 있기 때문에 바로 열람할 수 있다.

3. BAM은 Binary 형식이기 때문에 바로 열람할 수 없다. 하지만 압축되어 있기 때문에 용량이 작다.

4. BAM 파일은 SAM파일과 동일하지만, reference sequence names, length들이 헤더에 포함되어있다.

 -> 프로그램으로 원하는 sequence를 빨리 찾기 위한 indexing 기법을 활용한 것 같습니다.


BAM 파일은 압축된 바이너리 파일이기 때문에, 바로 읽는것은 불가능 하고 프로그램을 사용하여 읽어야 합니다.

NGS 데이터 구조상 용량이 워낙 큰 데이터들이기에, 압축된 BAM 파일을 많이 사용한다고 합니다.




- SAM file format


하나하나 다 써서 설명드리긴 귀찮으니, 페이지 가장 위의 그림에 있는 sequence를 이용하여 예를 들어보겠습니다.



@HD VN:1.0 SO:coordinate

@SQ SN:seq1 LN:5000

@CO Example of SAM/BAM file format.

B7_591:4:96:693:509 73 seq1 1 99 36M * 0 0 CACTAGTGGCTCATTGTAAATGTGTGGTTTAACTCG <<<<<<<<<<<<<<<;<<<<<<<<<5<<<<<;:<;7 MF:i:18 Aq:i:73 NM:i:0 UQ:i:0 H0:i:1 H1:i:0



@로 시작되는 라인은 모두 헤더내용입니다.

따라서 위의 3줄은 Header section이겠죠?

VN: 버전은 1.0이며 SO:Sorting order of alignment는 그냥 cordinate네요.

seq1이라는 이름의 sequence이며, 길이는 5000bp (base pair) 입니다.



그 아래 이제 Alignment section 입니다.

이부분의 필수적인 필드는 11가지입니다.

QNAME B7_591:4:96:693:509

FLAG  73

RNAME seq1

POS 1

MAOQ 99

CIGAR 36M

RBEXT *

PNEXT 0

TLEN  0

SEQ   CACTAGTGGCTCATTGTAAATGTGTGGTTTAACTCG

QUAL <<<<<<<<<<<<<<<;<<<<<<<<<5<<<<<;:<;7

MF:i:18

Aq:i:73

NM:i:0

UQ:i:0

H0:i:1

H1:i:0


아래에 있는 6개의 내용들은 잘 모르겠네요.

Qname은 Unique한 sequence의 이름입니다. 하지만 chimeric alignment의 경우에는 하나의 linear alignment로 이루어진 녀석은 아니기 때문에, 중복되는 Qname이 존재합니다. 하지만 위치값 정도는 다르겠네요.


아래 SEQ는 FASTQ 데이터의 quality처럼 Phred score를 담는 태그입니다.