Skip to main content

Genotype Representation Graph Library

Project description

install with bioconda

Genotype Representation Graphs

A Genotype Representation Graph (GRG) is a compact way to store reference-aligned genotype data for large genetic datasets. Computations with GRG can either be performed in a "graph native" way (DFS, BFS, or topological order traversals) or using matrix multiplication, which also supports the standardized matrix and GRM through LinearOperators.

A GRG can be constructed from .vcf.gz, IGD, tskit tree-sequence ARGs, or through Python APIs for node and edge creation.

A GRG contains Mutation nodes (representing variants) and Sample nodes (representing haploid samples), where there is a path from a Mutation node to a Sample node if-and-only-if that sample contains that mutation. These paths go through internal nodes that represent common ancestry between multiple samples, and this can result in significant compression (25-50x smaller than .vcf.gz). Calculations on the whole dataset can be performed very quickly on GRG, using GRGL.

If you use GRG in your research, please cite the initial paper:

DeHaas, Drew, Ziqing Pan, and Xinzhu Wei. "Enabling efficient analysis of biobank-scale data with genotype representation graphs." Nature computational science 5, no. 2 (2025): 112-124.

If you use grapp for PCA, GWAS, LinearOperators, etc., you can cite the recent preprint:

DeHaas, Drew, Chris Adonizio, Ziqing Pan, and Xinzhu Wei. "General, orders-of-magnitude faster whole-genome analysis with genotype representation graphs." bioRxiv (2026).

This preprint also describes improvements in GRGL v2.5: graphs are smaller, faster to construct, and faster for computation.

  • Unlike other graph-based methods (e.g., ARG inference), GRG can be constructed very quickly from tabular datasets, similar to the cost of creating a PLINK2 PGEN file.
  • There is experimental support for unphased data, but it does not compress nearly as well as phased data.
  • Construction from .vcf.gz now supports tabix indexes, making that input format feasible for large datasets
  • Missing data is supported, see the documentation

GRG possible workflows including PCA, GWAS, and arbitrary linear algebra operations

Documentation

Check out the main documentation for core API documentation, examples, tutorials, etc. Things covered in the documentation include:

  • Creating and using GRGs
  • Performing GWAS, PCA, GWAS with covariates, or other analyses with GRG via grapp (pip install grapp)
  • Simulating phenotypes with GRG via grg_pheno_sim (pip install grg_pheno_sim -- see the paper)
  • Using GRG with Python (integration with numpy, pandas, scipy, etc.)

You can also download the tutorials as Jupyter Notebooks and work through them interactively.

Genotype Representation Graph Library (GRGL)

GRGL can be used as a library in both C++ and Python. Support is currently limited to Linux and MacOS. It contains both an API (see docs) and a set of command-line tools.

Installing from pip

If you just want to use the tools (e.g., constructing GRG or converting tree-sequence to GRG) and the Python API then you can install via pip (from PyPi).

pip install pygrgl

This will use prebuilt packages for most modern Linux situations, and will build from source for MacOS. In order to build from source it will require CMake (at least v3.14), zlib development headers, and a clang or GCC compiler that supports C++11.

Installing from conda

You can also install the conda package via the bioconda channel: conda install pygrgl.

Building (Python)

The Python installation installs the command line tools and Python libraries (the C++ executables are packaged as part of this). Make sure you clone with git clone --recursive!

Requires Python 3.7 or newer to be installed (including development headers). It is recommended that you build/install in a virtual environment.

python3 -m venv /path/to/MyEnv
source /path/to/MyEnv/bin/activate
python setup.py bdist_wheel               # Compiles C++, builds a wheel in the dist/ directory
pip install --force-reinstall dist/*.whl  # Install from wheel

Build and installation should take at most a few minutes on the typical computer. For more details on build options, see DEVELOPING.md.

Building (C++ only)

The C++ build is only necessary for folks who want to include GRGL as a library in their C++ project. Typically, you would include our CMake into your project via add_subdirectory, but you can also build standalone as below. Make sure you clone with git clone --recursive!

If you only intend to use GRGL from C++, you can just build it via CMake:

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j4

See below to install the libraries to your system. It is recommended to install it to a custom location (prefix) since removing packages installed via make install is a pain otherwise. Example:

mkdir /path/to/grgl_installation/
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/path/to/grgl_installation/
make -j4
make install
# There should now be bin/, lib/, etc., directories under /path/to/grgl_installation/

Building (Docker)

We've included a Dockerfile if you want to use GRGL in a container.

Example to build:

docker build . -t grgl:latest

Example to run, constructing a GRG from an example VCF file:

docker run -v $PWD:/working -it grgl:latest bash -c "cd /working && grg construct --force /working/test/inputs/msprime.example.vcf"

Usage (Command line)

There is a command line tool that is mostly for file format conversion and performing common computations on the GRG. For more flexibility, use the Python or C++ APIs. After building and installing the Python version, run grg --help to see all the command options. Some examples are below.

Convert a tskit tree-sequence into a GRG. This creates my_arg_data.grg from my_arg_data.trees:

grg convert /path/to/my_arg_data.trees my_arg_data.grg

Load a GRG and emit some simple statistics about the GRG itself:

grg process stats my_arg_data.grg

You can also use grapp to see the same stats:

grapp show -i my_arg_data.grg

To construct a GRG from a VCF file, use the grg construct command. (NOTE raw VCF is incredibly slow for non-trivial datasets, use BGZF indexed with tabix or IGD):

grg construct -j 1 path/to/foo.vcf.gz

To convert a VCF(.gz) to an IGD and then build a GRG:

pip install igdtools
igdtools path/to/foo.vcf -o foo.igd
grg construct -j 1 foo.igd

Increase -j to the number of threads you have. igdtools can also use more threads if the VCF is BGZF and tabix indexed. Construction for small datasets (such as those included as tests in this repository) should be very fast, on the order of seconds. Really large datasets (such as Biobank-scale whole genome sequences) can take on the order of hours when using lots of threads (e.g., 70). 1,000 Genomes Project chromosomes usually take on the order of a few minutes.

Usage (Python API)

See the provided jupyter notebooks and GettingStarted.md for more examples.

Limits

Quantity Limit
Haploid samples 2,147,483,646
Total nodes 2,147,483,646
Total mutations (variants) 4,294,967,294
Total edges 18,446,744,073,709,551,615
Edges to/from a single node 4,294,967,295

Note: Node limits can theoretically be expanded to about a trillion, by turning on the LARGE_NODE_IDS preprocessor flag, but this mode is not well tested.

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

pygrgl-2.9.tar.gz (8.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pygrgl-2.9-cp315-cp315-manylinux_2_24_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.15manylinux: glibc 2.24+ x86-64

pygrgl-2.9-cp314-cp314-manylinux_2_24_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ x86-64

pygrgl-2.9-cp313-cp313-manylinux_2_24_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64

pygrgl-2.9-cp312-cp312-manylinux_2_24_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64

pygrgl-2.9-cp311-cp311-manylinux_2_24_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64

pygrgl-2.9-cp310-cp310-manylinux_2_24_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64

pygrgl-2.9-cp39-cp39-manylinux_2_24_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64

File details

Details for the file pygrgl-2.9.tar.gz.

File metadata

  • Download URL: pygrgl-2.9.tar.gz
  • Upload date:
  • Size: 8.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for pygrgl-2.9.tar.gz
Algorithm Hash digest
SHA256 b3b9758f4a44b778c9f94a912c744b8da6db3cd18b8647b6a3254e99b75d1c0c
MD5 463845f0bf0eeb499dc278171535a87f
BLAKE2b-256 637632a80a3d9559e070307a15f45077134e614e9d60a138918698ae13252d8e

See more details on using hashes here.

File details

Details for the file pygrgl-2.9-cp315-cp315-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pygrgl-2.9-cp315-cp315-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 45404edf5877b5509e3b0c8f2c2a62eb02a80b96695085496157e0f3655d9e6b
MD5 eec17517abfb89361a05c4e0a9bb2ced
BLAKE2b-256 51ebe8fd43866fb394c379be2695c6992c6a8ce9969a8b809d94c046f0648320

See more details on using hashes here.

File details

Details for the file pygrgl-2.9-cp314-cp314-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pygrgl-2.9-cp314-cp314-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 ba0818929c73457f1e239e30c0bb8be12c99582df73c6dd8db7298006499fc62
MD5 39fc4d0053c3160254c61fc3b6a29f39
BLAKE2b-256 86c7b5494be581616397c26039a19fe256c81d3d60a7bda1143816b5fed338c2

See more details on using hashes here.

File details

Details for the file pygrgl-2.9-cp313-cp313-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pygrgl-2.9-cp313-cp313-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 2248b33604ab2d0bf3ab9347e1df0e906a64651578d5d71fb015eae8dc9a843d
MD5 95f6db42218104099d593be9aab158fe
BLAKE2b-256 361eb310eeadd7af0cb93b5da491cf7e5cc9f108161bde485c020fafc224d20b

See more details on using hashes here.

File details

Details for the file pygrgl-2.9-cp312-cp312-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pygrgl-2.9-cp312-cp312-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 854eb3776626bc5eb5034f145296b4893551a72e5ca9dbdb62bac35f93dada94
MD5 c479444043f66d662991d11582f7833a
BLAKE2b-256 eb0e87c9562804a154c3248cda97227aa2d9751263d5f41144d19af907d5815a

See more details on using hashes here.

File details

Details for the file pygrgl-2.9-cp311-cp311-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pygrgl-2.9-cp311-cp311-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 e732d4216b2a39826e3f9c8b51af08d5327602d75d1978b0b475c21fcc471641
MD5 b327795c1957d4d895b6269a7668dabd
BLAKE2b-256 7b8fa48326c555cced57a0a7acb9f3cb17678c3aaa88969354f797b16b8d6580

See more details on using hashes here.

File details

Details for the file pygrgl-2.9-cp310-cp310-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pygrgl-2.9-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 c557efca57e393ea2bafdc06fc4d4f5d86c0232b0f917c3f8a18df67434e9c72
MD5 7dfb4ea4e2db1e8ade36e8da4297122f
BLAKE2b-256 fe4eeab6332e195bc7ab6dffc5177c10c2a874fbae25d1d3c2be99fc9d856f43

See more details on using hashes here.

File details

Details for the file pygrgl-2.9-cp39-cp39-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: pygrgl-2.9-cp39-cp39-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.9, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for pygrgl-2.9-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 7bad3f07149415c5252cb4a89b7831edf5e5a510c2bf5174ac00e7ff4538fceb
MD5 cdead378bb0a3962a77d9c22d4d161c5
BLAKE2b-256 eb46bad8620a489bee4fb39033b9585f5c93af433073ad55cb8311291c0cc215

See more details on using hashes here.

Supported by

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