bam.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:cellranger 作者: 10XGenomics 项目源码 文件源码
def downsample_bam(in_name, out_name, downsample_rate, restrict_chrom=None):
    """ Downsamples a bam.  Optionally also restricts the output to a single chromosome.
    """
    f = create_bam_infile(in_name)
    g, tids = create_bam_outfile(out_name, None, None, template=f)

    if restrict_chrom is None:
        bam_iter = f
    else:
        bam_iter = f.fetch(restrict_chrom)

    should_write = {}
    for r in bam_iter:
        if should_write.has_key(r.qname):
            if should_write[r.qname]:
                g.write(r)
        else:
            if random.random() < downsample_rate:
                should_write[r.qname] = True
                g.write(r)
            else:
                should_write[r.qname] = False
    g.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号