SAM/BAM文件操作-samtools

1.several tool sets have been created to manipulate SAM/BAM files:

samtools , bamtools , picard  

2.how can I select from or filter data from BAM files?

2.1  clarify some wording:

 selecting means to keep alignments that match a condition

filter means to remove alignments that match a condition

-f   (flag) includes only alignments where the bits match the bits in the flag

-F  (flag) includes only alignments where the bits do not match the bits in the flag

2.2 recall what flag 4 means and how to use it :

samtools flags 4   #表示unmap reads

samtools view -f 4 file.bam | head   # select and view the unmapped reads

samtools view -f 4 file.bam | wc -l #count the unmapped reads

samtools view -c -f 4 file.bam  # count the unmapped reads

samtools view -c  -F 4 file.bam # count the mapped reads

samtools view -b -F 4 file.bam > file_mapped_reads # separate unmapped reads

samtools view -c -f 16 file.bam # reads that align to reverse strand

samtools view -c -F 4 -f 16 file.bam # reads that align to reverse stand and not unmapped.

samtools view -c -F 20 file.bam # reads that align to forwards strand and are not unmapped

samtools view -b -f 4 file.bam > file_mapped_reads # separate mapped reads

2.3 Get an overview of the alignments in a BAM file

samtools flagstat file.bam # produces a report on flags

samtools idxstats file.bam # produces a report on how many reads align to each chromosome

bamtools stats -in file.bam # produces a report on flags

2.4 how do I filter on mapping quality?

The mapping quality column contains a number that the aligner fillls in . This number is rarely an objection quantity , it rather reflects a subjective value designated by the tool developer.

smatools view -c -q 1 file.bam  #select uniquely mapped reads when these were a aligned with BWA

smatools view -c -q 1 -F 4 -F 16 file.bam # mapping quality over 1 and on the forward strand (file.bam by BWA)

2.5 how can I find out the depth of coverage ?

samtools depth file.bam  | head  # compute the depth of coverage, compute the number of reads that overlap each base .

samtools depth -a file.bam | head  # ask for all position and you can verify that it starts at 1

smatools depth file.bam | sort -k 3 -rn | head  # sort by depth 

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Introduction What is Bowtie 2? Bowtie 2 is an ultrafast a...
    wzz阅读 11,240评论 0 5
  • 是不是有时候睡不着时会幻想,幻想今后的生活,幻想自己今后会变成什么样的人,会遇到什么样的人。 脑海中幻想的一...
    白鲸jww阅读 1,000评论 0 0
  • 别人的事,不要去插嘴 不评论 不嘲笑 不指导 因为你并不了解对方的情况 这个时候大多数的推断猜想都是 错误的 盲目...
    智吾不言阅读 1,238评论 0 1
  • 最近,热炒的一件事就是酷骑单车退押金事件,作为共享单车一大品牌,也是我所在的酒泉市,酷骑是唯一和最早引进的共享单车...
    壹零零阅读 3,199评论 0 0

友情链接更多精彩内容