Skip to main content

Package genomvar works with genomic variants and implements set-like operations on them. It supports import from VCF files and export to NumPy.

For documentation see here.

Installation

Requirements:

  1. Python >=3.6

  2. rbi-tree

  3. jinja2

To install:

pip install genomvar

Sample usage

Case 1

Common task in genome variant analysis is: there are two VCF files (for example obtained from variant caller #1 and caller #2) and the differences should be investigated.

First we read the VCF files into genomvar genomvar.varset.VariantSet objects which hold the variants with underlying data contained in INFO fields:

>>> from genomvar.varset import VariantSet
>>> vs1 = VariantSet.from_vcf('caller1.out.vcf.gz',parse_info=True)
>>> vs2 = VariantSet.from_vcf('caller2.out.vcf.gz',parse_info=True)

To find variants detected by caller #1 but not caller #2 diff method is used. Then differences are exported to numpy for futher analysis:

>>> diff = vs1.diff(vs2)
>>> recs = diff.to_records() # recs is a numpy structured dtype array
>>> recs[['chrom','start','end','ref','alt','vartype']]
[('chr1',  1046755,  1046756, 'T', 'G', 'SNP')
 ('chr1',  1057987,  1057988, 'T', 'C', 'SNP')
  ...,
 ('chr19', 56434340, 56434341, 'A', 'G', 'SNP')
 ('chrY', 56839067, 56839068, 'A', 'G', 'SNP')]
>>> recs['INFO']['DP'].mean() # recs['INFO']['DP'] is a numpy ndarray
232.18819746028257

Case 2

There is a smaller variant file obtained from the data and a bigger one usually obtained from a database. Variants in the former should be “annotated” with some data associated with variants in the latter.

This case is different from the previous in that DB file might not comfortably fit into memory. Class genomvar.varset.VariantSetFromFile can be used for this purpose:

>>> vs = varset.VariantSet.from_vcf('vcf_of_interest.vcf')
>>> dbSNP = varset.VariantSetFromFile('DBSNP.vcf.gz', index=Trueg)
>>> annots = []
>>> for vrt in vs.iter_vrt():
>>>     m = dbSNP.match(vrt)
>>>     annots.append(m[0].attrib['id'] if m else None)
>>> annots
[None, None, 'rs540057607', 'rs367710686', 'rs940651103', ...]

Here genomvar.varset.VariantSet.match method is used. It searches for variants with the same genomic alteration as argument variant and returns a list of those. Then VCF ID field can be accessed from those matching variants in attrib['id'] (dbSNP rs numbers in this particular case).

Release files for genomvar 0.3.0

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

Source distribution (sdist)

Source distribution for genomvar 0.3.0
File Size Uploaded
genomvar-0.3.0.tar.gz 45.8 kB Details

Release files / genomvar-0.3.0.tar.gz

Download URL genomvar-0.3.0.tar.gz
Size 45.8 kB
Tags Source
SHA-256 checksum
How to use checksums
639a265e272897362e716d5efae478fb7952663b9d7db3fe002be30bb9468105
BLAKE2b-256 checksum
How to use checksums
fa4042d18fbeb6e3a1bff1b973f183f82c517ff818b294555b2b07828fabffbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

0.2.14

1 release file

0.2.12

1 release file

0.2.11

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.16

1 release file

0.1.15

1 release file

0.1.14

1 release file

0.1.13

2 release files

0.1.12

2 release files

0.1.1

2 release files

0.1

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