cython+htslib快速vcf解析

cyvcf2的Python项目详细描述


cyvcf2

Docs

如果您使用cyvcf2,请引用paper

快速python(2和3)分析vcf和bcf,包括区域查询。

Build Status

cyvcf2是围绕htslib构建的cython包装器,用于快速解析Variant Call Format(vcf)文件。

variant.gt_ref_depths这样的属性直接返回一个numpy数组,以便它们可以立即供下游使用。 注意数组由底层c数据支持,因此,一旦variant超出范围。数组将包含无意义的内容。 要保存副本,请使用:cpy = np.array(variant.gt_ref_depths),而不仅仅是arr = variant.gt_ref_depths

示例

下面的例子展示了cyvcf2的很多用法。

fromcyvcf2importVCFforvariantinVCF('some.vcf.gz'):# or VCF('some.bcf')variant.REF,variant.ALT# e.g. REF='A', ALT=['C', 'T']variant.CHROM,variant.start,variant.end,variant.ID, \
				variant.FILTER,variant.QUAL# numpy arrays of specific things we pull from the sample fields.# gt_types is array of 0,1,2,3==HOM_REF, HET, UNKNOWN, HOM_ALTvariant.gt_types,variant.gt_ref_depths,variant.gt_alt_depths# numpy arraysvariant.gt_phases,variant.gt_quals,variant.gt_bases# numpy array## INFO Field.## extract from the info field by it's name:variant.INFO.get('DP')# intvariant.INFO.get('FS')# floatvariant.INFO.get('AC')# float# convert back to a string.str(variant)## sample info...# Get a numpy array of the depth per sample:dp=variant.format('DP')# or of any other format field:sb=variant.format('SB')assertsb.shape==(n_samples,4)# 4-values per# to do a region-query:vcf=VCF('some.vcf.gz')forvinvcf('11:435345-556565'):ifv.INFO["AF"]>0.1:continueprint(str(v))

安装

pip install cyvcf2

github(从源代码构建htslib和cyvcf2)

git clone --recursive https://github.com/brentp/cyvcf2
cd cyvcf2/htslib
autoheader
autoconf
./configure --enable-libcurl
make

cd ..
pip install -e .

osx上,使用brew时,您可能需要按照brew安装说明设置以下各项:

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

For pkg-config to find openssl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

测试

可以使用以下命令运行测试:

python setup.py test

cli

使用cyvcf2 path_to_vcf

运行
$ cyvcf2 --help
Usage: cyvcf2 [OPTIONS] <vcf_file> or -

  fast vcf parsing with cython + htslib

Options:
  -c, --chrom TEXT                Specify what chromosome to include.
  -s, --start INTEGER             Specify the start of region.
  -e, --end INTEGER               Specify the end of the region.
  --include TEXT                  Specify what info field to include.
  --exclude TEXT                  Specify what info field to exclude.
  --loglevel [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  Set the level of log output.  [default:
                                  INFO]
  --silent                        Skip printing of vcf.
  --help                          Show this message and exit.

另请参见

pysam也是has a cython wrapper to htslib,这里的一段代码直接从那个库中获取。但是,我们希望双子座的优化是非常具体的,所以我们选择创建一个单独的项目。

性能

在本文的性能比较中,我们使用thousand genomes chromosome 22 使用完全比较运行器here

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
面向java语句的方法与面向表达式的方法   密码学如何在java中为json对象签名?   是否可以通过java程序知道给定卡夫卡消费群体的消费偏移量?   打印字符时出现java未知问号   java为JFrame设置背景色   在ubuntu中检查java版本时linux权限被拒绝   如何用java创建xml模式   java无法在远程服务器上运行Vaadin应用程序   java智能垃圾收集?   java如何在SpringMVC中设置缓存头?   在unix计算机上运行java应用程序a:>签名以输入内容   Java、Apache Commons配置XML属性   使用ArrayList调用Java未经检查的方法   在文本文件中查找并替换单词(Java GUI)   java Android Studio无法检测到JDK7或更新版本   java从socket的有效负载获取事件消息   安卓中java调用子类方法   java如何通过点击超链接来运行jar文件(Firefox)