Package: geneview
geneview: A python package for visualizing genomics datageneviewis a library for making attractive and informative genomics graphics in Python.
It is built on top ofmatplotliband tightly integrated with the PyData
stack, including support fornumpyandpandasdata structures. And now it is actively developed.Some of the features that geneview offers are:High-level abstractions for structuring grids of plots that let you easily build complex visualizations.Functions for visualizing general genomics plots.InstallationTo install the released version, just dopipinstallgeneviewThis command will installgeneviewand all the dependencies.Quick startManhattanandQ-QplotWe use a PLINK2.x association output datagwas.csvwhich
is ingeneview-datadirectory,
as the input for the plots below. Here is the format preview ofgwas:#CHROMPOSIDREFALTA1TESTOBS_CTBETASET_STATPchr19041651_904165GAAADD282-0.09088970.195476-0.4649670.642344chr115636911_1563691TGGADD2710.4470210.4221941.05880.290715chr117077401_1707740TGGADD2830.1499110.1613870.9288880.353805chr122841951_2284195TCCADD275-0.0247040.13966-0.1768870.859739chr127790431_2779043TCTADD272-0.1117710.139929-0.798770.425182chr129445271_2944527GAAADD276-0.0544720.166038-0.328070.743129chr138037551_3803755TCTADD283-0.03927130.128528-0.3055470.760193chr141215841_4121584AGGADD2790.1209020.1270630.9515110.342239chr141700481_4170048CTTADD2800.2508070.1434231.748730.0815274chr141808421_4180842CTTADD2770.2091950.1461221.431650.153469chr160536301_6053630TGGADD269-0.2109170.129069-1.634140.103503chr175696021_7569602CTCADD281-0.1368340.13265-1.031540.303249chr175756661_7575666TCCADD277-0.2312780.159448-1.450490.14815Manhattan plot with default parametersThemanhattanplot()function ingeneviewtakes a data frame with
columns containing the chromosomal name/id, chromosomal position,
P-value and optionally the name of SNP(e.g. rsID in dbSNP).By default,manhattanplot()looks for column names corresponding to
those outout by the plink2 association results, namely,#CHROM,POS,P, andID, although different column names can be
specificed by user. Callingmanhattanplot()function with a data frame
of GWAS results as the single argument draws a basic manhattan plot,
defaulting to a darkblue and lightblue color scheme.importmatplotlib.pyplotaspltimportgeneviewasgv# load datadf=gv.load_dataset("gwas")# Plot a basic manhattan plot with horizontal xtick labels and the figure will display in screen.ax=gv.manhattanplot(data=df)plt.show()Rotate the x-axis tick label by settingxticklabel_kwsto avoid label
overlap:ax=manhattanplot(data=df,xticklabel_kws={"rotation":"vertical"})Or rotate the labels 45 degrees by settingxticklabel_kws={"rotation": 45}.When run with default parameters, themanhattanplot()function draws
horizontal lines drawn at $-log_{10}{(1e-5)}$ for "suggestive"
associations and $-log_{10}{(5e-8)}$ for the "genome-wide
significant" threshold. These can be move to different locations or
turned off completely with the argumentssuggestivelineandgenomewideline, respectively.ax=manhattanplot(data=df,suggestiveline=None,# Turn off suggestivelinegenomewideline=None,# Turn off genomewidelinexticklabel_kws={"rotation":"vertical"})The behavior of themanhattanplotfunction changes slightly when
results from only a single chromosome is used. Here, instead of plotting
alternating colors and chromosome ID on the x-axis, the SNP's position
on the chromosome is plotted on the x-axis:# plot only results of chromosome 8.manhattanplot(data=df,CHR="chr8",xlabel="Chromosome 8")manhattanplot()funcion has the ability to highlight SNPs with
significant GWAS signal and annotate the Top SNP, which has the lowest
P-value:ax=manhattanplot(data=df,sign_marker_p=1e-6,# highline the significant SNP with ``sign_marker_color`` color.is_annotate_topsnp=True,# annotate the top SNPxticklabel_kws={"rotation":"vertical"})Additionally, highlighting SNPs of interest can be combined with
limiting to a single chromosome to enable "zooming" into a particular
region containing SNPs of interest.Show a better manhattan plotFuther graphical parameters can be passed to themanhattanplot()function
to control thing like plot title, point character, size, colors, etc.
Here is the example:importmatplotlib.pyplotaspltimportgeneviewasgv# common parameters for plottingplt_params={"font.sans-serif":"Arial","legend.fontsize":14,"axes.titlesize":18,"axes.labelsize":16,"xtick.labelsize":14,"ytick.labelsize":14}plt.rcParams.update(plt_params)# Create a manhattan plotf,ax=plt.subplots(figsize=(12,4),facecolor="w",edgecolor="k")xtick=set(["chr"+iforiinlist(map(str,range(1,10)))+["11","13","15","18","21","X"]])_=gv.manhattanplot(data=df,marker=".",sign_marker_p=1e-6,# Genome wide significant p-valuesign_marker_color="r",snp="ID",# The column name of annotation information for top SNPs.title="Test",xtick_label_set=xtick,xlabel="Chromosome",ylabel=r"$-log_{10}{(P)}$",sign_line_cols=["#D62728","#2CA02C"],hline_kws={"linestyle":"--","lw":1.3},is_annotate_topsnp=True,ld_block_size=50000,# 50000 bptext_kws={"fontsize":12,"arrowprops":dict(arrowstyle="-",color="k",alpha=0.6)},ax=ax)QQ plot with default parametersTheqqplot()function can be used to generate a Q-Q plot to visualize the
distribution of association "P-value". Theqqplot()function takes a vector
of P-values as its the only required argument.importmatplotlib.pyplotaspltimportgeneviewasgv# load datadf=gv.load_dataset("gwas")# Plot a basic manhattan plot with horizontal xtick labels and the figure will display in screen.ax=gv.qqplot(data=df["P"])plt.show()Show a better QQ plotFuther graphical parameters can be passed toqqplot()to control the plot
title, axis labels, point characters, colors, points sizes, etc. Here is the
example:importmatplotlib.pyplotaspltimportgeneviewasgvf,ax=plt.subplots(figsize=(6,6),facecolor="w",edgecolor="k")_=gv.qqplot(data=df["P"],marker="o",title="Test",xlabel=r"Expected $-log_{10}{(P)}$",ylabel=r"Observed $-log_{10}{(P)}$",ax=ax)More tutorials about GWASAdmixture plotGenerateAdmixtureplot from the raw admixture output result:simple example for admixtureplotimportmatplotlib.pyplotaspltfromgeneviewimportload_datasetfromgeneviewimportadmixtureplotf,ax=plt.subplots(1,1,figsize=(14,2),facecolor="w",constrained_layout=True,dpi=300)admixtureplot(data=load_dataset("admixture_output.Q"),population_info=load_dataset("admixture_population.info"),ylabel_kws={"rotation":45,"ha":"right"},ax=ax)orimportmatplotlib.pyplotaspltimportgeneviewasgvadmixture_output_fn=gv.load_dataset("admixture_output.Q")population_group_fn=gv.load_dataset("admixture_population.info")# define the order for population to plotpop_group_1kg=["KHV","CDX","CHS","CHB","JPT","BEB","STU","ITU","GIH","PJL","FIN","CEU","GBR","IBS","TSI","PEL","PUR","MXL","CLM","ASW","ACB","GWD","MSL","YRI","ESN","LWK"]f,ax=plt.subplots(1,1,figsize=(14,2),facecolor="w",constrained_layout=True,dpi=300)gv.popgen.admixtureplot(data=admixture_output_fn,population_info=population_group_fn,edgewidth=2.0,group_order=pop_group_1kg,shuffle_popsample_kws={"frac":0.5},ylabel_kws={"rotation":45,"ha":"right"},ax=ax)The format of input files and more details about admixtureplotVenn plotsVenn diagrams for 2, 3, 4, 5, 6 sets.Minimal venn plot exampleimportgeneviewasgvtable={"Dataset 1":{"A","B","D","E"},"Dataset 2":{"C","F","B","G"},"Dataset 3":{"J","C","K"}}ax=gv.venn(table)Manual adjustment of petal labelsIf necessary, the labels on the petals (i.e., various intersections in the
Venn diagram) can be adjusted manually.For this,generate_petal_labels()can be called first to get thepetal_labelsdictionary, which can be modified.After modification, pass petal_labels to functionsvenn().fromnumpy.randomimportchoiceimportgeneviewasgvdataset_dict={name:set(choice(1000,250,replace=False))fornameinlist("ABCD")}petal_labels=gv.generate_petal_labels(dataset_dict.values(),fmt="{logic}\n({percentage:.1f}%)")ax=gv.venn(data=petal_labels,names=list(dataset_dict.keys()),legend_use_petal_color=True)More tutorials about vennDependenciesGeneviewonly supports Python 3 and no longer supports Python 2.Installation requiresnumpy,scipy,pandas, andmatplotlib.
Some functions will usestatsmodels.We need the data structures:DataFrameandSeriesinpandas.
It's easy and worth to learn, clickhereto see more detail
tutorial for these two data type.LicenseReleased under a GPL-3.0 license