Skip to main content

A collection of handy tools for GWAS

Project description

gwaslab

A collection of handy python scripts for GWAS.

Just want to make lif eaiser and save myself from repetitive work.

What you can do with gwaslab:

  1. Side-by-side Manhattan and QQ plot
  2. Manhattan plot
  3. QQ plot
  4. Calculate lamda GC
  5. [Select top SNPs based on a given window size.]
  6. Convert beta/se <-> OR/95%L_U/95%L_L
  7. Select hapmap3 SNPs from sumstats
  8. Convert Observed scale heritability to liability scale heritability
  9. read ldsc log and extract numeric results directly into a pandas dataframe.
  10. compare the effect size of select variants / or automatically detected lead variants from two sumstats. manhattan_qq_plot

Requirements:

  1. Python>3 2. "scipy" 3. "numpy" 4. "pandas" 5. "matplotlib" 6. "seaborn"

Install:

pip install gwaslab

Current version: 0.0.6

Usage:

Input: pandas dataframe

Create Manhattan plot and QQ plot with just one line

import gwaslab as gl

## creat qqplot and manhattan plot with just one line
## pass a dataframe in, and specify the column name for chromosome, base pair position, and also the p values.
gl.mqqplot(sumstats,"CHR","POS","PVALUE")

## adjust the plot, select top snps and add annotation sutomatically.
gl.mqqplot(sumstats,"CHR","POS","PVALUE",cut=20,cutfactor=10,anno=True,verbose=True,save=True,title="gwaslab")

## all options
gl.mqqplot(insumstats,
          chrom,
          pos,
          p,
          scaled=False,
          cut=0,
          cutfactor=10,
          cut_line_color="#ebebeb",
          windowsizekb=500,
          anno=None,
          sig_level=5e-8,
          sig_line_color="grey",
          suggestive_sig_level=5e-6,
          title =None,
          mtitle=None,
          qtitle=None,
          figsize =(15,5),
          fontsize = 10,
          colors = ["#000042", "#7878BA"],
          verbose=True,
          repel_force=0.03,
          gc=True,
          save=None,
          saveargs={"dpi":300,"facecolor":"white"}
          )

Or you can plot it separately.

Manhattan plot

gl.mplot()

QQ plot

gl.qqplot()

Calculate genomic inflation factor

gc(insumstats{"PVALUE"},mode="p",level=0.5)
gc(insumstats["Z"],mode="z",level=0.5)
gc(insumstats["chi2"],mode="chi2",level=0.5)

Extract top snps given a sliding window size

gl.getsig(insumstats,id,chrom,pos,p)

gl.getsig(insumstats,id,chrom,pos,p,windowsizekb=500,verbose=True,sig_level=5e-8)

Ref: Zhou, Wei, and Global Biobank Meta-analysis Initiative. "Global Biobank Meta-analysis Initiative: Powering genetic discovery across human diseases." medRxiv (2021).

Converting observed scale heritability to liability scale heritability

gl.h2_obs_to_liab(h2_obs, P, K)

gl.h2_obs_to_liab(h2_obs, P, K, se_obs=None)

Ref: Equation 23 Lee, Sang Hong, et al. "Estimating missing heritability for disease from genome-wide association studies." The American Journal of Human Genetics 88.3 (2011): 294-305.

Read ldsc results in to pandas DataFrame

Directly read ldsc -h2 or -rg into pandas dataframe...

pathlist=["./test.results.log","./test2.results.log"]

ldsc_h2 = gl.read_ldsc(pathlist, mode="h2")
ldsc_rg = gl.read_ldsc(pathlist, mode="rg")

ldsc_h2
Filename	h2_obs	h2_se	Lambda_gc	Mean_chi2	Intercept	Intercept_se	Ratio	Ratio_se
test.results.log	42.9954	8.657	1.2899	1.3226	0.0098	0.0098	0.6538	0.0304
test2.results.log	NA	NA	1.2899	1.3226	0.0098	0.0098	Ratio < 0	NA

ldsc_rg
p1	p2	rg	se	z	p	h2_obs	h2_obs_se	h2_int	h2_int_se	gcov_int	gcov_int_se
./test.results.log	./test.results.log	0.2317	0.0897	2.5824	0.0098	0.3305	0.0571	0.9612	0.009	-0.0001	0.0062
./test.results.log	./test2.results.log	0.2317	0.0897	2.5824	0.0098	0.3305	0.0571	0.9612	0.009	-0.0001	0.0062

Compare effect sizes of selected variants from two sumstats

gl.compare_effect()

preformat your sumstats for a qc workflow


Log

  • 0.0.5 - 0.0.6

  • added compare_effect, read_ldsc

  • 0.0.4

    • added mqqplot feature
    • fixed gtesig algorithm
    • recreated mplot and qqplot

Next

  • beta to OR
  • OR to beta

For more information: https://gwaslab.com/

Project details


Release history Release notifications | RSS feed

This version

1.0.0

Download files

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

Source Distribution

gwaslab-1.0.0.tar.gz (21.3 kB view details)

Uploaded Source

File details

Details for the file gwaslab-1.0.0.tar.gz.

File metadata

  • Download URL: gwaslab-1.0.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.7.0 readme-renderer/33.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.59.0 importlib-metadata/3.10.0 keyring/22.3.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.8

File hashes

Hashes for gwaslab-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5f85c670cb72dab0efa5ddd9b50d6b8ac5f06ef457ac7119dfc04cc037854536
MD5 1818cc9c37ba8732a027d2b51a82880e
BLAKE2b-256 300c971a0806f04c0a25002f8bce9bec263a5da481e197116affa4aa5362d027

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