Skip to main content

Pipeline for efficient genomic data processing.

Project description

GenVarLoader

GenVarLoader provides a fast, memory efficient data loader for training sequence models on genetic variation. For example, this can be used to train a DNA language model on human genetic variation (e.g. Nucleotide Transformer).

Features

  • Respects memory budget
  • Supports insertions and deletions
  • Scales to 100,000s of individuals
  • Fast!
  • Extensible to new file formats (drop a feature request!)
  • Coming soon: re-aligning tracks (e.g. expression, chromatin accessibility) to genetic variation (e.g. BigRNA)

Installation

pip install genvarloader

A PyTorch dependency is not included since it requires special instructions.

An optional dependency is TensorStore(version >=0.1.50) for writing genotypes as a Zarr store and using TensorStore for I/O. This dramatically speeds up dataloading performance when training a model on genetic variation, for which approximately uniform random sampling across the genome is required. Standard bioinformatics variant formats like VCF, BCF, and PGEN unfortunately do not have a data layout conducive for this. TensorStore is not included as a dependency due a dependency conflict that, within the scope of GenVarLoader, does not cause any issues. GenVarLoader is developed with Poetry and I am waiting for the ability to override/ignore sub-dependencies to include TensorStore as an explicit dependency.

Quick Start

import genvarloader as gvl

ref_fasta = 'reference.fasta'
variants = 'variants.pgen' # highly recommended to convert VCFs to PGEN
regions_of_interest = 'regions.bed'

Create readers for each file providing sequence data:

ref = gvl.Fasta(name='ref', path=ref_fasta, pad='N')
var = gvl.Pgen(variants)
varseq = gvl.FastaVariants(name='varseq', reference=ref, variants=var)

Put them together and get a torch.DataLoader:

gvloader = gvl.GVL(
    readers=varseq,
    bed=regions_of_interest,
    fixed_length=1000,
    batch_size=16,
    max_memory_gb=8,
    batch_dims=['sample', 'ploid'],
    shuffle=True,
)

dataloader = gvloader.torch_dataloader()

And now you're ready to use the dataloader however you need to:

# implement your training loop
for batch in dataloader:
    ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

genvarloader-0.3.1.tar.gz (151.6 kB view details)

Uploaded Source

Built Distribution

genvarloader-0.3.1-cp39-abi3-manylinux_2_28_x86_64.whl (424.8 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.28+ x86-64

File details

Details for the file genvarloader-0.3.1.tar.gz.

File metadata

  • Download URL: genvarloader-0.3.1.tar.gz
  • Upload date:
  • Size: 151.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.5.1

File hashes

Hashes for genvarloader-0.3.1.tar.gz
Algorithm Hash digest
SHA256 fcff2060d503bf06b9e5006c9fb2507953a3b16645c231785ad7ce36b3a75fa7
MD5 0784c6f82996d29d2859525e6d11da7b
BLAKE2b-256 314b7eba80fc1edd95834fc3d0fa2e407a7c936ff8a43be8ddc61b17417e2d52

See more details on using hashes here.

File details

Details for the file genvarloader-0.3.1-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for genvarloader-0.3.1-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 616c17746928384e1d33519b8e336946cca73da2b0dfe7eb05e2e17bc20e71d3
MD5 fcce4cc62e6e021132070bd1b253b994
BLAKE2b-256 1d4f1cd2aa4091c4f4613598e3568c18fcc3b5e9f7471b9efd75edef69ab4208

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page