0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

samtools を用いた BAM file から Unique mapped reads の抽出 ~bowtie2 のアライメントファイルから~

Posted at

samtools##

samtools は NGS のリードのアライメント後の出力ファイルである sam/bam file を編集できるツールです。
今回は、samtools でソートしてしまった bam file から unique mapped reads の抽出を行いましたので、書き置きします。
samtools のマニュアルページはこちら

sam file であれば、テキスト形式なので、grep 等を使って unique mapped reads を抽出できます。一方で、bam file はバイナリの形式なので、単に grep を咬ませるだけでは抽出できません。
そこで、今回は single-end reads と paired-end reads を bowtie2 でアライメント後、bam file から unique mapped reads を抽出したいと思います。

bowtie2 の sam/bam file には、それぞれのリードにタグ情報が付与されています。
今回は、複数回アライメントされたリードに付く XS タグを除くことで、unique mapped reads を抽出します。

# grep -v : ある文字を持った列を取り除く

# Single-end
# -h : Header のみの出力にしない, -@ : Thread number, -b : bam 形式で出力
$ samtools view -@ 8 -h ./MappedReads.bam | grep -v "XS:" | samtools view -@ 8 -h -b > ./UniqueMappedReads.bam

# Paired-end
# -f 0x2 : ペアでアライメントされたリードを表示
$ samtools view -@ 8 -h -f 0x2 ./MappedReads.bam | grep -v "XS:" | samtools view -@ 8 -h -b > ./UniqueMappedReads.bam

以下参考
samtools のマニュアルページ
bowtie2 のマニュアルページ (タグに関しても含む)
grep の使い方とオプション

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?