Skip to main content

cyvcf2

Note: cyvcf2 versions < 0.20.0 require htslib < 1.10. cyvcf2 versions >= 0.20.0 require htslib >= 1.10

The latest documentation for cyvcf2 can be found here:

Docs

If you use cyvcf2, please cite the paper

Fast python (2 and 3) parsing of VCF and BCF including region-queries.

Build Status

cyvcf2 is a cython wrapper around htslib built for fast parsing of Variant Call Format (VCF) files.

Attributes like variant.gt_ref_depths return a numpy array directly so they are immediately ready for downstream use. note that the array is backed by the underlying C data, so, once variant goes out of scope. The array will contain nonsense. To persist a copy, use: cpy = np.array(variant.gt_ref_depths) instead of just arr = variant.gt_ref_depths.

Example

The example below shows much of the use of cyvcf2.

from cyvcf2 import VCF

for variant in VCF('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_ALT
	variant.gt_types, variant.gt_ref_depths, variant.gt_alt_depths # numpy arrays
	variant.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') # int
	variant.INFO.get('FS') # float
	variant.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')
    assert sb.shape == (n_samples, 4) # 4-values per

# to do a region-query:

vcf = VCF('some.vcf.gz')
for v in vcf('11:435345-556565'):
    if v.INFO["AF"] > 0.1: continue
    print(str(v))

Installation

pip (assuming you have htslib < 1.10 installed)

pip install cyvcf2

github (building htslib and cyvcf2 from source)

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

cd ..
pip install -r requirements.txt
CYTHONIZE=1 pip install -e .

On OSX, using brew, you may have to set the following as indicated by the brew install:

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"

Testing

Install pytest, then tests can be run with:

pytest

CLI

Run with 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.

See Also

Pysam also has a cython wrapper to htslib and one block of code here is taken directly from that library. But, the optimizations that we want for gemini are very specific so we have chosen to create a separate project.

Performance

For the performance comparison in the paper, we used thousand genomes chromosome 22 With the full comparison runner here.

Release files for cyvcf2 0.30.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cyvcf2 0.30.16
File Size Uploaded
cyvcf2-0.30.16.tar.gz 1.2 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for cyvcf2 0.30.16
File
cyvcf2-0.30.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
cyvcf2-0.30.16-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
cyvcf2-0.30.16-cp310-cp310-macosx_10_9_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.9+ x86-64 Details
cyvcf2-0.30.16-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
cyvcf2-0.30.16-cp39-cp39-macosx_11_0_arm64.whl CPython 3.9 CPython 3.9 macOS 11.0+ ARM64 Details
cyvcf2-0.30.16-cp39-cp39-macosx_10_9_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.9+ x86-64 Details
cyvcf2-0.30.16-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
cyvcf2-0.30.16-cp38-cp38-macosx_11_0_arm64.whl CPython 3.8 CPython 3.8 macOS 11.0+ ARM64 Details
cyvcf2-0.30.16-cp38-cp38-macosx_10_9_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.9+ x86-64 Details
cyvcf2-0.30.16-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
cyvcf2-0.30.16-cp37-cp37m-macosx_10_9_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64 Details
cyvcf2-0.30.16-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64 Details
cyvcf2-0.30.16-cp36-cp36m-macosx_10_9_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.9+ x86-64 Details

Total release size: 53.9 MB

Release files / cyvcf2-0.30.16.tar.gz

Download URL cyvcf2-0.30.16.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
8d48f0d09d8d400c05ac44cbbe173545eda00f6ee484be2aab966922715d8073
BLAKE2b-256 checksum
How to use checksums
fbc5ccc4711aeb71cbe7d0d169fe569a03b3481b1e02b45b803a97eddb47ca9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cyvcf2-0.30.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 6.7 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
33911e301268b346baddd0668547788b8458e2ef4dc163e822cbf181ab6a4784
BLAKE2b-256 checksum
How to use checksums
85413e1f8f473d5792f07cf9daab48f395cae6361b7f27e6dbd4acc925da4147
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp310-cp310-macosx_11_0_arm64.whl

Download URL cyvcf2-0.30.16-cp310-cp310-macosx_11_0_arm64.whl
Size 1.4 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5144d56fde7452a19fd042033f17d4b65b1dc9ebc0e0971d0dfa3bc2f74516da
BLAKE2b-256 checksum
How to use checksums
04c6cf0420506346da3698edc9da17383fd9241c5dc6109e8cf574b5aa74bc9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp310-cp310-macosx_10_9_x86_64.whl

Download URL cyvcf2-0.30.16-cp310-cp310-macosx_10_9_x86_64.whl
Size 3.0 MB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
a091d1c4f10767ac12366b4e16c1ec07951b1714a6454dce4240c3f1000605bb
BLAKE2b-256 checksum
How to use checksums
0bc17115cf73251ce65ca0c2b08ff8578d0de4afd8c1de6f8268290ec7c38e15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cyvcf2-0.30.16-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 6.8 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ddf1520aafa49d0cc57f233cba110403e1c71b4bc2426515d17a1213ffe1bbc3
BLAKE2b-256 checksum
How to use checksums
ebfd95cd3f576bdea9c4adbd204edbd3e44ccf44581694f99fdd6e3a3c54d440
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp39-cp39-macosx_11_0_arm64.whl

Download URL cyvcf2-0.30.16-cp39-cp39-macosx_11_0_arm64.whl
Size 1.4 MB
Tags CPython 3.9 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8f30b3169d6f4bde70040d10a0277e07c4d21ed06dfaaf09b047ab561189b45c
BLAKE2b-256 checksum
How to use checksums
429136851c51808ab862e18fd72641af816890206f540d57930c05a4c3e42c15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp39-cp39-macosx_10_9_x86_64.whl

Download URL cyvcf2-0.30.16-cp39-cp39-macosx_10_9_x86_64.whl
Size 3.0 MB
Tags CPython 3.9 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
a08f82b0181b31c83f505717251ac8637a98cd556fdb57c3667de1aa2180d427
BLAKE2b-256 checksum
How to use checksums
7218c95916002f9e67401b5b96f75d30f7c789aa6655597a3c15d529b644ed3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cyvcf2-0.30.16-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 6.8 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
0e6760580c251f3a4aaed5bc22d025641d2e50922e3c50f9b46fd5c5df122f37
BLAKE2b-256 checksum
How to use checksums
224256cffb5049a7b425b9ecccf884b47bb6e04df9247c545a53b6739a9904dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp38-cp38-macosx_11_0_arm64.whl

Download URL cyvcf2-0.30.16-cp38-cp38-macosx_11_0_arm64.whl
Size 1.4 MB
Tags CPython 3.8 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2f0a65664c0579cd212cd9dba872eb672ce2e23c1214f5dd5fa9e6176f7b270b
BLAKE2b-256 checksum
How to use checksums
399b4eb08058c363ed032bb140d11112d92afe42e2d474599efa094f97bb1910
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp38-cp38-macosx_10_9_x86_64.whl

Download URL cyvcf2-0.30.16-cp38-cp38-macosx_10_9_x86_64.whl
Size 3.0 MB
Tags CPython 3.8 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
b28c0029c1760b79ed3d0f3757e9454a7a7fb877a294ee32cc7dad3a4e66f4a5
BLAKE2b-256 checksum
How to use checksums
35ee12277d74feaf4f8286922da6ba3b3305f9d8ea8c611bdbabb2a684c15a58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cyvcf2-0.30.16-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 6.6 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
06c88221263be536292127bb68a8068e36201176f0ee5dd48796ee954f546c49
BLAKE2b-256 checksum
How to use checksums
1d6fe52e4613c0688b8aa0f55b2f497ec9d6d8063ea3a30fc07be6592ab2eafb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp37-cp37m-macosx_10_9_x86_64.whl

Download URL cyvcf2-0.30.16-cp37-cp37m-macosx_10_9_x86_64.whl
Size 3.0 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
e24f6d93e4debc98548435a986136ffed8d28757e94f58277cf146568a9e431e
BLAKE2b-256 checksum
How to use checksums
a931cee08239f85296dd1851a725f96557f5c3542cd3407b430fdd4a30d1493e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cyvcf2-0.30.16-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 6.6 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
02e0a5e7cc4350648a18b65b48a5ef8dda3a2b3ca31e503d95277091a6434e66
BLAKE2b-256 checksum
How to use checksums
0544f3941937d61ad6a8c2f9db1ffca7a7901ffd06360970196e323443c5d76e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cyvcf2-0.30.16-cp36-cp36m-macosx_10_9_x86_64.whl

Download URL cyvcf2-0.30.16-cp36-cp36m-macosx_10_9_x86_64.whl
Size 3.0 MB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
2c62a75536a11e52ad3a042ec1954391fa9240b784ca2d1f999bb939db61ae87
BLAKE2b-256 checksum
How to use checksums
578a1e37df734993277baa187c4d8c300b3960253bc0c09d1ce485f3dee2d017
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.30.16 This release

14 release files

0.30.9

9 release files

0.30.1

1 release file

0.20.9

1 release file

0.20.8

1 release file

0.20.7

1 release file

0.20.6

1 release file

0.20.5

1 release file

0.20.4

1 release file

0.20.3

1 release file

0.20.1

1 release file

0.20.0

1 release file

0.11.7

1 release file

0.11.6

1 release file

0.11.5

1 release file

0.11.4

1 release file

0.11.3

1 release file

0.11.2

1 release file

0.11.1

2 release files

0.11.0

1 release file

0.10.9

1 release file

0.10.8

1 release file

0.10.7

1 release file

0.10.6

1 release file

0.10.4

1 release file

0.10.3

1 release file

0.10.1

1 release file

0.10.0

1 release file

0.9.0

1 release file

0.8.9

1 release file

0.8.8

1 release file

0.8.7

1 release file

0.8.6

1 release file

0.8.5

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.9

1 release file

0.7.7

1 release file

0.7.4

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.0

1 release file

0.6.5

1 release file

0.6.4

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.5.5

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.2

1 release file

0.3.0

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page