Skip to main content

ld_estimator: A package to estimate linkage disequilibrium

Computes linkage disequilibrium in python. This uses the maximum-likelihood of Excoffier & Slatkin, just converted from HaploView to c++ , with python bindings. It's not too slow, can calculate ~1500 pairs per second from the HapMap Phase 3 VCFs.

Installation

The simplest way to install ld_estimator is through pip:

pip install ld_estimator

Usage

Use ld_estimator within a python environment

from ld_estimator import pairwise_ld

var1 = [(0, 0), (0, 0), (0, 1), (1, 0), (1, 1), (0, 1), (0, 0), (0, 0), (1, 1)]
var2 = [(0, 0), (0, 0), (0, 1), (1, 0), (1, 1), (0, 1), (0, 0), (1, 1), (1, 1)]
is_haploid = [False, False, False, False, False, False, False, True, True, True]
ld = pairwise_ld(var1, var2, is_haploid)
print(ld.dprime)
print(ld.r_squared)

# or calculate LD for all pairs of variants in a region in a VCF:
from ld_estimator import region_ld
vcf_path = 'PATH_TO_VCF'
ld = region_ld(vcf_path, chrom, start, end)

# or calculate LD to a site within a region in a VCF. This defaults to checking
# variants within a 100 kb window of the specified site.
from ld_estimator import site_ld
vcf_path = 'PATH_TO_VCF'
ld = site_ld(vcf_path, chrom, pos, window=200000)

# can pass in multiple positions in the same region at once
ld = site_ld(vcf_path, chrom, [pos2, pos2, pos3], window=200000)

# both region_ld() and site_ld() can take a list of sample IDs to subset the
# samples used for calculating LD. For example:
ld = site_ld(vcf_path, chrom, pos, subset=['sample1', 'sample2'])

# if the variant is on a sex chromosome, you'll have to pass in a list of sample
# sexes (matching order of the subset IDs if present, otherwise the VCF samples)
ld = site_ld(vcf_path, 'X', 20000000, sexes=['male', 'female'])

Metadata

Release files for ld-estimator 1.1.2

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

Source distribution (sdist)

Source distribution for ld-estimator 1.1.2
File Size Uploaded
ld_estimator-1.1.2.tar.gz 102.7 kB Details

Release files / ld_estimator-1.1.2.tar.gz

Download URL ld_estimator-1.1.2.tar.gz
Size 102.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cff4b1788d6b30c80bdae14597336bd7d48eb7fbf589115bf84f61b93f3e0f8c
BLAKE2b-256 checksum
How to use checksums
c9265bed2f679439b3bfa3d8b053e57e5196dddc0ce503521ef1ad759e680463
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

1.1.2 This release

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

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