Skip to main content

vcforge

vcforge is a python library for working with VCF files.

It provides a variety of tools and methods for importing, exploring, manipulating and analyzing Variant Call Format (VCF) data.

VCF parsing is handled by the cyvcf2 library (https://github.com/brentp/cyvcf2), which is based on the htslib library (https://github.com/samtools/htslib) written in C, resulting in very fast parsing.

vcforge utilizes pandas for producing tables and statistics.

The library is designed for explorative analyses, by linking the information about the samples with the variant data.

Features

  • Import VCF data along with sample information
  • Automatically extract basic information about the variants and optionally assign variant IDs
  • Extract INFO fields for all variants
  • Extract selected FORMAT fields for all samples
  • Split the variant data based on sample information (i.e. breed, population, etc)
  • Get variant statistics (n called, call rate, allele frequency, nucleotide diversity, variant types and subtypes )

How to install

Install with pip:

pip install vcforge

Dependencies

  • pandas
  • numpy
  • cyvcf2

Why vcforge?

I started working on this library for myself, seeing how I found myself increasingly frustrated with the lack of python VCF parsing libraries that would allow me to easily explore VCF files in a readable and workable format, such as pandas DataFrames, and allow me to connect sample-level information with the variants. For example, splitting the variants by sample group is something that allows me to quickly and easily explore variants without having to rely on command-line tools that produce files that need to be examined.

How to use

!!! Documentation is still a work in progress !!!

Import the library and read a VCF with its sample information

from vcforge import VCFClass

dataset=VCFClass(vcf_path='variants.vcf.gz', sample_info='samples.tsv',sample_id_column="sample", add_info=True, create_ids_if_none=True, threads=4)

Show the variant information

var_info=dataset.variants

Split the dataset by sample column(s) and get all genotypes of the variants in one of the populations as a pandas dataframe

split_dataset_by_breed=dataset.split_by_sample_column(column='population')

split_dataset_by_breed['POP_1'].show_genotypes()

Calculate some variant statistics about the selected population, that will be added to the variant information in the VCFClass

split_dataset_by_breed['POP_1'].get_var_stats(add_to_info=True)

Filter out variants with call rate < 0.9

var_info=split_dataset_by_breed['POP_1'].variants

selected_variants=var_info[var_info['CALL_RATE']>0.9]

Save the filtered subset as a VCF, with the ID column previously created.

split_dataset_by_breed['POP_1'].save_vcf(save_path='pop_1.vcf.gz', add_ids=True, var_ids=selected_variants.index, samples=None)

Metadata

Release files for vcforge 0.1.8

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

Source distribution (sdist)

Source distribution for vcforge 0.1.8
File Size Uploaded
vcforge-0.1.8.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vcforge 0.1.8
File Interpreter ABI Platform
vcforge-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 21.4 kB

Release files / vcforge-0.1.8.tar.gz

Download URL vcforge-0.1.8.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d36ac5cde0b52bde1c92aafc2ec5b977d6d740eec037a84a97b38125bf36b1e4
BLAKE2b-256 checksum
How to use checksums
db857469321f540507922c48ddfc96000c8f7e8c103c64013d6315b289367c6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.2 Linux/6.8.0-48-generic

Release files / vcforge-0.1.8-py3-none-any.whl

Download URL vcforge-0.1.8-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b061a8b2b19676c42760536724f7aca24ae511c91ceb537432bcb41d9fd785a
BLAKE2b-256 checksum
How to use checksums
feebd2588b762fa708643bd28d75aec42e219e653375a7aec3d7d19c5b3e9e8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.2 Linux/6.8.0-48-generic

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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