生信软件13 - 基于sambamba 窗口reads计数和平均覆盖度统计

Sambamba是一个高性能,高度并行,健壮和快速的工具(和库),用D编程语言编写,用于处理SAM和BAM文件。与samtools相比,其优势在于并行BAM读和写。

conda安装

conda install sambamba -y

# github: https://github.com/biod/sambamba

基本用法

# 创建.bai index
samtools index sample.bam

# 计算窗口reads数和平均覆盖度
sambamba depth window -w 1000 sample.sorted.bam > /path/sample.bam_read_depths.txt

统计结果

窗口reads计数的Python封装

参数输入:bam文件绝对路径

调用命令

python reads_depth.py -b /path/Sample.sorted.bam

主程序

# reads_depth.py
import os
import optparse
from pathlib import Path

class ReadsDepth(object):
    def __init__(self, bam_path: str, window_size: int) -> None:
        path_obj = Path(bam_path)
        self.result_dir_path = path_obj.parent
        self.bam_path = bam_path
        self.window_size = window_size
        self.sample_name = str(path_obj.stem).split('.')[0]
        self.output_path = os.path.join(self.result_dir_path, self.sample_name + '.bam_reads_depths.txt')

        self.bam_index()
        
        self.reads_depth()

    def bam_index(self):
        if not os.path.exists(self.bam_path + '.bai'):
            os.system("samtools index {}".format(self.bam_path))
    
    def reads_depth(self):
        run_status = os.system("sambamba depth window -w {0} {1} > {2}".format(self.window_size, self.bam_path, self.output_path))
    

if __name__ == '__main__':
    parser = optparse.OptionParser(usage='"%prog"', version="%prog V1.0")
    parser.add_option("-b", "--bam-path", dest="bam_path", type=str, help="")
    parser.add_option("-w", "--window-size", dest="window_size", type=int, default=1000, help="bp")
    options, args = parser.parse_args()

    reads_depth = ReadsDepth(bam_path=options.bam_path, window_size=options.window_size)

生信软件文章推荐

生信软件1 - 测序下机文件比对结果可视化工具 visNano

生信软件2 - 下游比对数据的统计工具 picard

生信软件3 - mapping比对bam文件质量评估工具 qualimap

生信软件4 - 拷贝数变异CNV分析软件 WisecondorX

生信软件5 - RIdeogram包绘制染色体密度图

生信软件6 - bcftools查找指定区域的变异位点信息

生信软件7 - 多线程并行运行Linux效率工具Parallel

生信软件8 - bedtools进行窗口划分、窗口GC含量、窗口测序深度和窗口SNP统计

生信软件9 - 多公共数据库数据下载软件Kingfisher

生信软件10 - DNA/RNA/蛋白多序列比对图R包ggmsa

生信软件11 - 基于ACMG的CNV注释工具ClassifyCNV

生信软件12 - 基于Symbol和ENTREZID查询基因注释的R包(easyConvert )

更多内容请关注公众号【生信与基因组学】,定期更新生信算法和编程、基因组学、统计学、分子生物学、临床检测和深度学习等内容。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

生信与基因组学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值