{"id":18373551,"url":"https://github.com/shujiahuang/qmplot","last_synced_at":"2025-08-08T06:10:34.732Z","repository":{"id":46825357,"uuid":"340579658","full_name":"ShujiaHuang/qmplot","owner":"ShujiaHuang","description":"A Python package for creating high-quality manhattan and Q-Q plots from GWAS results.","archived":false,"fork":false,"pushed_at":"2023-12-27T01:37:20.000Z","size":2475,"stargazers_count":46,"open_issues_count":8,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-29T06:57:08.300Z","etag":null,"topics":["genomics-data-visualization","gwas","gwas-tools","matplotlib","python","visualization"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ShujiaHuang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-20T06:25:40.000Z","updated_at":"2025-07-02T07:03:47.000Z","dependencies_parsed_at":"2024-06-21T13:13:01.949Z","dependency_job_id":"5b919369-8212-42a4-ac97-3ca7f8a0c4c4","html_url":"https://github.com/ShujiaHuang/qmplot","commit_stats":{"total_commits":102,"total_committers":4,"mean_commits":25.5,"dds":0.0490196078431373,"last_synced_commit":"003a911dcc25a9cc5f4b98af8b02d9b22a33caa1"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/ShujiaHuang/qmplot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShujiaHuang%2Fqmplot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShujiaHuang%2Fqmplot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShujiaHuang%2Fqmplot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShujiaHuang%2Fqmplot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShujiaHuang","download_url":"https://codeload.github.com/ShujiaHuang/qmplot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShujiaHuang%2Fqmplot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269373109,"owners_count":24406321,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["genomics-data-visualization","gwas","gwas-tools","matplotlib","python","visualization"],"created_at":"2024-11-06T00:10:48.364Z","updated_at":"2025-08-08T06:10:34.690Z","avatar_url":"https://github.com/ShujiaHuang.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"QMplot: A Python tool for creating high-quality manhattan and Q-Q plots from GWAS results.\n==========================================================================================\n\n[![image](https://zenodo.org/badge/340579658.svg)](https://zenodo.org/badge/latestdoi/340579658)\n\n**qmplot** is a handy, user-friendly tool and Python library that allows\nfor quick and flexible of publication-ready manhattan and Q-Q plots\ndirectly from PLINK association results files or any data frame with\ncolumns containing chromosomal name, chromosomal position, P-value and\noptionally the SNP name(e.g. rsID in dbSNP).\n\nThis library is inspired by\n[r-qqman](https://github.com/stephenturner/qqman), but it\\'s much more\nconvenient than *r-qqman* that the column of chromosomal name doesn\\'t\nhave to be numeric any more, which means you can **keep the raw name of\nchromosomal** and don\\'t have to covert X, Y, MT, etc to be 23, 24, 25,\netc.\n\nDependencies\n------------\n\nqmplot supports Python 3.6+ and no longer supports Python 2.\n\nInstatllation requires [numpy](https://numpy.org/),\n[scipy](https://www.scipy.org/), [pandas](https://pandas.pydata.org/)\nand [matplotlib](https://matplotlib.org/).\n\nInstallation\n------------\n\n**qmplot** is written by Python and release in PyPI. The latest stable\nrelease can be installed by running the following command:\n\n``` {.bash}\npip install qmplot\n```\n\nQuick Start\n-----------\n\nWe use a PLINK2.x association output data\n\"[gwas_plink_result.tsv](tests/data/gwas_plink_result.tsv)\" which is\nin `tests/data` directory, as the input for the plots below. Here is the\nformat preview of \\\"gwas_plink_result.tsv\\\":\n\n  ----------------------------------------------------------------------------------------------------------------\n  \\#CHROM   POS       ID          REF   ALT   A1   TEST   OBS_CT   BETA         SE         T_STAT      P\n  --------- --------- ----------- ----- ----- ---- ------ -------- ------------ ---------- ----------- -----------\n  1         904165    1_904165    G     A     A    ADD    282      -0.0908897   0.195476   -0.464967   0.642344\n\n  1         1563691   1_1563691   T     G     G    ADD    271      0.447021     0.422194   1.0588      0.290715\n\n  1         1707740   1_1707740   T     G     G    ADD    283      0.149911     0.161387   0.928888    0.353805\n\n  1         2284195   1_2284195   T     C     C    ADD    275      -0.024704    0.13966    -0.176887   0.859739\n\n  1         2779043   1_2779043   T     C     T    ADD    272      -0.111771    0.139929   -0.79877    0.425182\n\n  1         2944527   1_2944527   G     A     A    ADD    276      -0.054472    0.166038   -0.32807    0.743129\n\n  1         3803755   1_3803755   T     C     T    ADD    283      -0.0392713   0.128528   -0.305547   0.760193\n\n  1         4121584   1_4121584   A     G     G    ADD    279      0.120902     0.127063   0.951511    0.342239\n\n  1         4170048   1_4170048   C     T     T    ADD    280      0.250807     0.143423   1.74873     0.0815274\n  ----------------------------------------------------------------------------------------------------------------\n\n**qmplot** apply two ways to generate manhattan and Q-Q plots:\n\n### 1. Commandline options\n\nThis is the simplest way to plot manhattan and QQ plots if you already\nhave PLINK2.x association output. You can directly type `qmplot --help`\nand will find all the options below:\n\n```bash\nusage: qmplot [-h] -I INPUT -O OUTPREFIX [-T TITLE] [-P SIGN_PVALUE] [-M M_ID]\n          [--open-gui]\n\nqmplot: Creates high-quality manhattan and QQ plots from PLINK association\noutput (or any dataframe with chromosome, position, and p-value).\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -I INPUT, --input INPUT\n                        Input file\n  -O OUTPREFIX, --outprefix OUTPREFIX\n                        The prefix of output file\n  -T TITLE, --title TITLE\n                        Title of figure\n  -P SIGN_PVALUE, --sign-mark-pvalue SIGN_PVALUE\n                        Genome wide significant p-value sites. [1e-6]\n  -M M_ID, --top-sign-signal-mark-id M_ID\n                        A string denoting the column name for which you want\n                        to annotate the Top Significant SNPs. Default: \"ID\"(PLINK2.x)\n  --display             Set to be GUI backend, which can show the figure.\n```\n\nThe following command will give you the two png plots with 300 dpi\nresolution:\n\n```bash\n$ qmplot -I data/gwas_plink_result.tsv -T Test -M ID --dpi 300 -O test\n```\n\nThe manhattan plot looks like:\n\n![](tests/test.manhattan.png)\n\nThe Q-Q plot looks like:\n\n![](tests/test.QQ.png)\n\nNote: You can only modify the plots throught `qmplot` commandline\noptions which is a big limitation when you want to make more change.\n\n### 2. Python library\n\nThis is the most flexible way. You can use qmplot as a library in you\nPython code and create the plots by your mind.\n\n### Manhattan plot with default parameters\n\nThe `manhattanplot()` function in **qmplot** takes a data frame with\ncolumns containing the chromosomal name/id, chromosomal position,\nP-value and optionally the name of SNP(e.g. rsID in dbSNP).\n\nBy default, `manhattanplot()` looks for column names corresponding to\nthose outout by the plink2 association results, namely, \"#CHROM\",\n\"POS\", \"P\", and \"ID\", although different column names can be\nspecificed by user. Calling `manhattanplot()` function with a data frame\nof GWAS results as the single argument draws a basic manhattan plot,\ndefaulting to a darkblue and lightblue color scheme.\n\n```python\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom qmplot import manhattanplot\n\nif __name__ == \"__main__\":\n\n    df = pd.read_table(\"tests/data/gwas_plink_result.tsv\", sep=\"\\t\")\n    df = df.dropna(how=\"any\", axis=0)  # clean data\n\n    # generate manhattan plot and set an output file.\n    ax = manhattanplot(data=df)\n    plt.savefig(\"output_manhattan_plot.png\")\n```\n\n![](tests/output_manhattan_plot.png)\n\nRotate the x-axis tick label by setting `xticklabel_kws` to avoid label\noverlap:\n\n```python\nax = manhattanplot(data=df,\n                   # set vertical or any other degrees as you like.\n                   xticklabel_kws={\"rotation\": \"vertical\"})\n```\n\n![](tests/output_manhattan_plot_xviertical.png)\n\nOr rotate the labels 45 degrees by setting\n`xticklabel_kws={\"rotation\": 45}`.\n\nWhen run with default parameters, the `manhattanplot()` function draws\nhorizontal lines drawn at $-log_{10}{(10^{-5})}$ for \"suggestive\" \nassociations and $-log_{10}{(5×10^{-8})}$ for the \"genome-wide significant\" \nthreshold. These can be move to different locations or turned off completely \nwith the arguments `suggestiveline` and `genomewideline`, respectively.\n\n```python\nax = manhattanplot(data=df,\n                   suggestiveline=None,  # Turn off suggestiveline\n                   genomewideline=None,  # Turn off genomewideline\n                   xticklabel_kws={\"rotation\": \"vertical\"},\n                   is_show=True)  # display the plot in screen\n```\n\n![](tests/output_manhattan_plot_xviertical_noline.png)\n\nThe behavior of the `manhattanplot` function changes slightly when\nresults from only a single chromosome is used. Here, instead of plotting\nalternating colors and chromosome ID on the x-axis, the SNP\\'s position\non the chromosome is plotted on the x-axis:\n\n```python\n# plot only results of chromosome 8.\nmanhattanplot(data=df, CHR=\"chr8\", xlabel=\"Chromosome 8\")\nplt.savefig(\"output_chr8_manhattan_plot.png\")\n```\n\n![](tests/output_chr8_manhattan_plot.png)\n\n`manhattanplot()` funcion has the ability to highlight SNPs with\nsignificant GWAS signal and annotate the Top SNP, which has the lowest\nP-value:\n\n```python\nax = manhattanplot(data=df,\n                   sign_marker_p=1e-6,  # highline the significant SNP with ``sign_marker_color`` color.\n                   is_annotate_topsnp=True,  # annotate the top SNP\n                   xticklabel_kws={\"rotation\": \"vertical\"})\n```\n\n![](tests/output_manhattan_anno_plot.png)\n\nAdditionally, highlighting SNPs of interest can be combined with\nlimiting to a single chromosome to enable \\\"zooming\\\" into a particular\nregion containing SNPs of interest.\n\n### An example for a better Manhattan plot\n\nFuther graphical parameters can be passed to the `manhattanplot()`\nfunction to control things like plot title, point character, size,\ncolors, etc. Here is the example:\n\n```python\nimport pandas as pd\nfrom qmplot import manhattanplot\n\nif __name__ == \"__main__\":\n\n    # loading data from local file\n    df = pd.read_table(\"tests/data/gwas_plink_result.tsv\", sep=\"\\t\")\n    df = df.dropna(how=\"any\", axis=0)  # clean data\n\n    # defined the plot style\n    f, ax = plt.subplots(figsize=(12, 4), facecolor='w', edgecolor='k')\n    xtick = set(['chr' + i for i in list(map(str, range(1, 10))) + ['11', '13', '15', '18', '21', 'X']])\n    manhattanplot(data=data,\n                  marker=\".\",\n                  sign_marker_p=1e-6,  # Genome wide significant p-value\n                  sign_marker_color=\"r\",\n                  snp=\"ID\",\n\n                  title=\"Test\",\n                  xtick_label_set=xtick,\n                  xlabel=\"Chromosome\",\n                  ylabel=r\"$-log_{10}{(P)}$\",\n\n                  sign_line_cols=[\"#D62728\", \"#2CA02C\"],\n                  hline_kws={\"linestyle\": \"--\", \"lw\": 1.3},\n\n                  is_annotate_topsnp=True,\n                  ld_block_size=500000,  # 500000 bp\n                  text_kws={\"fontsize\": 12,  # The fontsize of annotate text\n                            \"arrowprops\": dict(arrowstyle=\"-\", color=\"k\", alpha=0.6)},\n                  ax=ax)\n    plt.savefig(\"better.manhattan.png\")\n```\n\n![](tests/better.manhattan.png)\n\nFind more details about the parameters by typing `manhattanplot?` in\nIPython console.\n\n### QQ plot with defualt parameters\n\nThe `qqplot()` function can be used to generate a Q-Q plot to visualize\nthe distribution of association \\\"P-value\\\". The `qqplot()` function\ntakes a vector of P-values as its the only required argument.\n\n``` {.python}\nimport pandas as pd\nfrom qmplot import qqplot\n\nif __name__ == \"__main__\":\n\n    df = pd.read_table(\"tests/data/gwas_plink_result.tsv\", sep=\"\\t\")\n    df = df.dropna(how=\"any\", axis=0)  # clean data\n    ax = qqplot(data=df[\"P\"])\n```\n\n![](tests/output_QQ_plot.png)\n\n### A better QQ plot\n\nFuther graphical parameters can be passed to `qqplot()` to control the\nplot title, axis labels, point characters, colors, points sizes, etc.\nHere is the example:\n\n``` {.python}\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom qmplot import qqplot\n\nif __name__ == \"__main__\":\n    df = pd.read_table(\"tests/data/gwas_plink_result.tsv\", sep=\"\\t\")\n    df = df.dropna(how=\"any\", axis=0)  # clean data\n\n    # Create a Q-Q plot\n    f, ax = plt.subplots(figsize=(6, 6), facecolor=\"w\", edgecolor=\"k\")\n    qqplot(data=data[\"P\"],\n           marker=\"o\",\n           title=\"Test\",\n           xlabel=r\"Expected $-log_{10}{(P)}$\",\n           ylabel=r\"Observed $-log_{10}{(P)}$\",\n           ax=ax)\n\n    plt.savefig(\"test.QQ.png\")\n```\n\n![](tests/test.QQ.png)\n\nFind more details about the parameters by typing `qqplot?` in IPython\nconsole.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshujiahuang%2Fqmplot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshujiahuang%2Fqmplot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshujiahuang%2Fqmplot/lists"}