python中的pylab_Python pylab 模块,semilogx() 实例源码 - 编程字典

本文介绍Python的pylab模块中semilogx函数的使用,并通过 Coverage 类来探讨如何计算确保基因组覆盖率的所需覆盖度。示例代码展示了如何绘制不同未覆盖基因组比例与所需覆盖度的关系图。
摘要由CSDN通过智能技术生成

def get_required_coverage(self, M=0.01):

"""Return the required coverage to ensure the genome is covered

A general question is what should be the coverage to make sure

that e.g. E=99% of the genome is covered by at least a read.

The answer is:

.. math:: \log^{-1/(E-1)}

This equation is correct but have a limitation due to floating precision.

If one provides E=0.99, the answer is 4.6 but we are limited to a

maximum coverage of about 36 when one provides E=0.9999999999999999

after which E is rounded to 1 on most computers. Besides, it is no

convenient to enter all those numbers. A scientific notation would be better but

requires to work with :math:`M=1-E` instead of :math:`E`.

.. math:: \log^{-1/ - M}

So instead of asking the question what is the

requested fold coverage to have 99% of the genome covered, we ask the question what

is the requested fold coverage to have 1% of the genome not covered.

This allows us to use :math:`M` values as low as 1e-300 that is a fold coverage

as high as 690.

:param float M: this is the fraction of the genome not covered by

any reads (e.g. 0.01 for 1%). See note above.

:return: the required fold coverage

.. plot::

import pylab

from sequana import Coverage

cover = Coverage()

misses = np.array([1e-1, 1e-2, 1e-3, 1e-4,1e-5,1e-6])

required_coverage = cover.get_required_coverage(misses)

pylab.semilogx(misses, required_coverage, 'o-')

pylab.ylabel("Required coverage", fontsize=16)

pylab.xlabel("Uncovered genome", fontsize=16)

pylab.grid()

# The inverse equation is required fold coverage = [log(-1/(E - 1))]

"""

# What should be the fold coverage to have 99% of the genome sequenced ?

# It is the same question as equating 1-e^{-(NL/G}) == 0.99, we need NL/G = 4.6

if isinstance(M, float) or isinstance(M, int):

assert M < 1

assert M >=0

else:

M = np.array(M)

# Here we do not use log(-1/(E-1)) but log(-1/(1-E-1)) to allow

# for using float down to 1e-300 since 0.999999999999999 == 1

return np.log(-1/(-M))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值