RNA-seq流程学习笔记(8)-使用SAMtools将SAM文件转换为BAM文件、排序、建立索引

参考文章:
RNA-seq(5):序列比对
RNA-seq练习 第二部分
转录组入门(5): 序列比对

1. 进行格式转换的原因

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.
为什么要转换格式?为了让计算机好处理。SAM(sequence Alignment/mapping)数据格式是目前高通量测序中存放比对数据的标准格式。bam是sam的二进制格式,减少了sam文件的储存量。

2. SAMTools的主要功能

目前处理SAM格式的工具主要是SAMTools,这是Heng Li大神写的,除了C语言版本,还有Java的Picard,Python的Pysam,Common lisp的cl-sam等其他版本。软件对应各命令如下:

  • view: BAM-SAM/SAM-BAM 转换和提取部分比对
  • sort: 比对排序 merge: 聚合多个排序比对
  • index:索引排序比对
  • faidx: 建立FASTA索引,提取部分序列
  • tview: 文本格式查看序列
  • pileup: 产生基于位置的结果和 consensus/indel calling

3. SAMtools的使用

最常用的三板斧就是格式转换,排序,索引。而进阶教程就是看文档提高。
1. 格式转换(view命令)

# samtools view 使用说明:
Usage: samtools view [options] <in.bam>|<in.sam>|<in.cram> [region ...]
Options:
  -b       output BAM
  -C       output CRAM (requires -T)
  -1       use fast BAM compression (implies -b)
  -o FILE  output file name [stdout]
  -S       ignored (input format is auto-detected)
      --input-fmt-option OPT[=VAL]
               Specify a single input file format option in the form
               of OPTION or OPTION=VALUE
   -@, --threads INT
               Number of additional threads to use [0]
# 范例一:利用的是samtools的view选项,参数-S 输入sam文件;参数-b 指定输出的文件为bam;最后重定向写入>bam文件
$ cd mnt/f/rna_seq/aligned
$ for ((i=56;i<=62;i++));do samtools view -S SRR35899${i}.sam -b > SRR35899${i}.bam;done
# 操作记录:
(base) zexing@DNA:~/projects/zhaoxiujuan/aligned$ ls
m3108.sam  m3110_1.sam  m3110.sam  m3111.sam  m3112.sam  m3113.sam  m3114.sam  m3122.sam  msh1.sam  msh2.sam  Scr.sam
#使用参数-S;-b;-@;输出选用>进行重定向写入,也可以使用-o Filename 指定输入文件名称
(base) zexing@DNA:~/projects/zhaoxiujuan/aligned$ samtools view -@ 8 -S Scr.sam -b > Scr.bam
(base) zexing@DNA:~/projects/zhaoxiujuan/aligned$ ll
total 256G
-rw-rw-r-- 1 zexing zexing 4.3G 6月   3 12:22 Scr.bam
-rw-rw-r-- 1 zexing zexing  23G 6月   2 15:08 
  • 16
    点赞
  • 68
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值