Skip to main content

Package for estimating linkage disequilibrium

Project description

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 ~1000 pairs per second.

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'])

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

ld_estimator-1.0.2.tar.gz (96.6 kB view details)

Uploaded Source

File details

Details for the file ld_estimator-1.0.2.tar.gz.

File metadata

  • Download URL: ld_estimator-1.0.2.tar.gz
  • Upload date:
  • Size: 96.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.7.1

File hashes

Hashes for ld_estimator-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a1847a727c7092a7932086a8b4d45cd7440160b4c506f27de3fcd89e4df98c7e
MD5 c27e031e977e115b45c63d1fa54f9cf6
BLAKE2b-256 49b9a5da72cf83f50a32ae15e2356358d3e454b8095a9d252d9bda83a3e2eb2b

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