PYVCFLIB(1)
π PYVCFLIB(1) β VCFLib Python FFI π
okay bestie, so this is the manual for PYVCFLIB(1), aka the VCFLib Python FFI. Like, we're building up a Python FFI for vcflib using the brilliant Python pybind11 module β¨. Mostly for (our) testing purposes, so we are not aiming for complete coverage β it's giving "good enough, bestie". See below for adding new bindings π«Ά.
πΈ DESCRIPTION β Setting it up and example πΈ
First things first: import the module π
. It may require setting the PYTHONPATH to the shared library pyvcflib.cpython-39-x86_64-linux-gnu.so.
env PYTHONPATH=./build python3 -c 'import pyvcflib'
and in a GNU Guix shell you may prepend LD_LIBRARY_PATH to find GLIBC etc. π§
LD_LIBRARY_PATH=$LIBRARY_PATH
Now you should be able to use the pyvcflib module. Let's try with a VCF samples/10158243.vcf that has only one record:
>>> from pyvcflib import *
>>> vcf = VariantCallFile()
>>> vcf.openFile("../samples/10158243.vcf")
True
# ... list(rec.name,rec.pos,rec.ref,rec.alt)
>>> rec = Variant(vcf)
>>> while (vcf.getNextVariant(rec)):
... [rec.name,rec.pos,rec.ref]
['grch38#chr4', 10158243, 'ACCCCCACCCCCACC']
>>> rec.alt[0]
'ACC'
>>> rec.alleles
['ACCCCCACCCCCACC', 'ACC', 'AC', 'ACCCCCACCCCCAC', 'ACCCCCACC', 'ACA']
So the one input record shows it has a ref of ACCCCCACCCCCACC and six alt alleles [ACCCCCACCCCCACC, ACC, AC, ACCCCCACCCCCAC, ACCCCCACC, ACA] π₯
This works fine! No cap π
π Masking genotypes π
With vcfwave's allelic primitives, when two VCF records get combined, we need to combine the genotypes. This happens, for example, with vcfwave deletions π.
When a deletion spans any SNPs from realignment we want to make sure the SNPs are masked for those deletions. I.e. π
6/28/2022, 4:21:44 PM - erikg: if you have a deletion in hap 1 .|0 or .|1 in hap 2 0|. or 1|. etc.
So, if we have input two variants at the same position with the first a DEL and the second a SNP the SNP genotypes need to be masked as
>> deletion_mask_genotypes(['1|0', '0|0', '0|1', '1|1', '1|0', '1|0', '1|1'],
... ['0|0', '1|1', '1|0', '0|0', '1|0', '1|1', '1|1'])
['0|0', '1|1', '1|0', '0|0', '.|0', '.|1', '.|.']
In the 5-7th column the deletion has the same genotype and gets masked π β¨
π¦ Another example π¦
See realign.py for examples of using the FFI in the form of a python unit test π§ͺ. We used that to develop the vcfwave module. Iconic behaviour, honestly π
π Additional bindings π
It may be the case you want additional bindings that we have not included yet π. See vcflib's pythonffi.cpp for the existing bindings and Variant.h for the classes and accessors π.
π that's the whole page, bestie π β this one's signed off from the <rainbow>-- coding: utf-8 --()</rainbow> era, brought to you by the VCFLib Python FFI, and you *know* it's giving -- coding: utf-8 --()` energy fr fr πΈβ¨π«Ά
π¦ where this page comes from
- debian trixie: libvcflib-tools 1.0.12+dfsg-1 Β· MIT
- ubuntu questing: libvcflib-tools 1.0.12+dfsg-1
- ubuntu resolute: libvcflib-tools 1.0.12+dfsg-2 Β· MIT
- ubuntu stonking: libvcflib-tools 1.0.12+dfsg-2 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms