Skip to content

Commit

Permalink
markernames labeling issues fixed in manhatten plot
Browse files Browse the repository at this point in the history
  • Loading branch information
reneshbedre committed May 14, 2020
1 parent 5215303 commit 42ba4c4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 19 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ ANOVA summary, multiple pairwise comparisons, and assumption tests statistics
<b>Manhatten plot</b>

`bioinfokit.visuz.marker.mhat(df, chr, pv, color, dim, r, ar, gwas_sign_line, gwasp, dotsize, markeridcol, markernames,
gfont, valpha, show, figtype, axxlabel, axylabel, axlabelfontsize, ylm)`
gfont, valpha, show, figtype, axxlabel, axylabel, axlabelfontsize, ylm, gstyle)`

Parameters | Description
------------ | -------------
Expand All @@ -386,8 +386,8 @@ Parameters | Description
`gwasp` | Statistical significant threshold to identify significant SNPs [float][default: 5E-08]
`dotsize`| The size of the dots in the plot [float][default: 8]
`markeridcol` | Name of a column having SNPs. This is necessary for plotting SNP names on the plot [string][default: None]
`markernames` | The list of the SNPs to display on the plot. These SNP should be present in SNP column. Additionally, it also accepts the dict of SNPs and its associated gene name. If this option set to True, it will label all SNPs with P-value significant score defined by `gwasp` [string, list, dict][default: True]
`gfont` | Font size for SNP names to display on the plot [float][default: 8]
`markernames` | The list of the SNPs to display on the plot. These SNP should be present in SNP column. Additionally, it also accepts the dict of SNPs and its associated gene name. If this option set to True, it will label all SNPs with P-value significant score defined by `gwasp` [string, list, tuple, dict][default: True]
`gfont` | Font size for SNP names to display on the plot [float][default: 8]. gfont not compatible with gstyle=2.
`valpha` | Transparency of points on plot [float (between 0 and 1)][default: 1.0]
`dim` | Figure size [tuple of two floats (width, height) in inches][default: (6, 4)]
`r` | Figure resolution in dpi [int][default: 300]
Expand All @@ -398,6 +398,8 @@ Parameters | Description
`axylabel` | Label for Y-axis. If you provide this option, default label will be replaced [string][default: None]
`axlabelfontsize` | Font size for axis labels [float][default: 9]
`ylm` | Range of ticks to plot on Y-axis [float tuple (bottom, top, interval)][default: None]
`gstyle` | Style of the text for markernames. 1 for default text and 2 for box text [int][default: 1]



Returns:
Expand Down
5 changes: 5 additions & 0 deletions VERSIONLOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v0.7.3 has the following updates and changes (May 14, 2020)
- In manhatten plot (`visuz.marker.mhat`), the labeling issue with `markernames` parameter corrected (see issue # 4 on github for details;
thanks to mkirchler for reporting)
- `gstyle` parameter added in manhatten plot for box style annotation

v0.7.2 has the following updates and changes (May 08, 2020)
- `splitvcf` function added for splitting VCF file into individual VCF files for each chromosome
- `mergevcf` moved to `analys.marker` class
Expand Down
2 changes: 1 addition & 1 deletion bioinfokit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "bioinfokit"
__version__ = "0.7.2"
__version__ = "0.7.3"
__author__ = "Renesh Bedre"


56 changes: 41 additions & 15 deletions bioinfokit/visuz.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def venn(vennset=(1,1,1,1,1,1,1), venncolor=('#00909e', '#f67280', '#ff971d'), v
else:
print("Error: check the set dataset")

class gene_exp():

class gene_exp:

def __init__(self):
pass

Expand Down Expand Up @@ -267,31 +269,55 @@ def depr_mes(func_name):
print("This function is deprecated. Please use", func_name )
print("Read docs at https://reneshbedre.github.io/blog/howtoinstall.html")

class marker():
def geneplot_mhat(df, markeridcol, chr, pv, gwasp, markernames, gfont, ax):

class marker:

def __init__(self):
pass

def geneplot_mhat(df, markeridcol, chr, pv, gwasp, markernames, gfont, gstyle, ax):
if markeridcol is not None:
if markernames is not None and markernames is True:
for i in df[markeridcol].unique():
if df.loc[df[markeridcol] == i, pv].iloc[0] <= gwasp:
plt.text((df.loc[df[markeridcol] == i, 'ind'].iloc[0]), df.loc[df[markeridcol] == i, 'tpval'].iloc[0],
str(i), fontsize=gfont)
elif markernames is not None and type(markernames) is tuple:
if gstyle == 1:
plt.text(df.loc[df[markeridcol] == i, 'ind'].iloc[0], df.loc[df[markeridcol] == i, 'tpval'].iloc[0],
str(i), fontsize=gfont)
elif gstyle == 2:
plt.annotate(i, xy=(df.loc[df[markeridcol] == i, 'ind'].iloc[0], df.loc[df[markeridcol] == i, 'tpval'].iloc[0]),
xycoords='data', xytext=(5, -15), textcoords='offset points', size=6,
bbox=dict(boxstyle="round", alpha=0.2),
arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.2, relpos=(0, 0)))
elif markernames is not None and isinstance(markernames, (tuple, list)):
for i in df[markeridcol].unique():
plt.text(df.loc[df[markeridcol] == i, 'ind'].iloc[0], df.loc[df[markeridcol] == i, 'tpval'].iloc[0],
str(i), fontsize=gfont)
elif markernames is not None and type(markernames) is dict:
if i in markernames:
if gstyle == 1:
plt.text(df.loc[df[markeridcol] == i, 'ind'].iloc[0], df.loc[df[markeridcol] == i, 'tpval'].iloc[0],
str(i), fontsize=gfont)
elif gstyle == 2:
plt.annotate(i, xy=(df.loc[df[markeridcol] == i, 'ind'].iloc[0], df.loc[df[markeridcol] == i, 'tpval'].iloc[0]),
xycoords='data', xytext=(5, -15), textcoords='offset points', size=6,
bbox=dict(boxstyle="round", alpha=0.2),
arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.2, relpos=(0, 0)))
elif markernames is not None and isinstance(markernames, dict):
for i in df[markeridcol].unique():
if i in markernames:
plt.text(df.loc[df[markeridcol] == i, 'ind'].iloc[0], df.loc[df[markeridcol] == i, 'tpval'].iloc[0],
if gstyle == 1:
plt.text(df.loc[df[markeridcol] == i, 'ind'].iloc[0], df.loc[df[markeridcol] == i, 'tpval'].iloc[0],
markernames[i], fontsize=gfont)
elif gstyle == 2:
plt.annotate(markernames[i], xy=(
df.loc[df[markeridcol] == i, 'ind'].iloc[0], df.loc[df[markeridcol] == i, 'tpval'].iloc[0]),
xycoords='data', xytext=(5, -15), textcoords='offset points', size=6,
bbox=dict(boxstyle="round", alpha=0.2),
arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.2, relpos=(0, 0)))
else:
print("Error: provide 'markeridcol' parameter")
sys.exit(1)
raise Exception("provide 'markeridcol' parameter")

def mhat(df="dataframe", chr=None, pv=None, color=None, dim=(6,4), r=300, ar=90, gwas_sign_line=False,
gwasp=5E-08, dotsize=8, markeridcol=None, markernames=None, gfont=8, valpha=1, show=False, figtype='png',
axxlabel=None, axylabel=None, axlabelfontsize=9, axlabelfontname="Arial", axtickfontsize=9,
axtickfontname="Arial", ylm=None):
axtickfontname="Arial", ylm=None, gstyle=1):

_x, _y = 'Chromosomes', r'$ -log_{10}(P)$'
rand_colors = ('#a7414a', '#282726', '#6a8a82', '#a37c27', '#563838', '#0584f2', '#f28a30', '#f05837',
Expand All @@ -316,7 +342,7 @@ def mhat(df="dataframe", chr=None, pv=None, color=None, dim=(6,4), r=300, ar=90,
if df[chr].nunique() % 2 == 0:
color_list = list(reduce(lambda x, y: x+y, zip(color_1, color_2)))
elif df[chr].nunique() % 2 == 1:
color_list = list(reduce(lambda x, y: x + y, zip(color_1, color_2)))
color_list = list(reduce(lambda x, y: x+y, zip(color_1, color_2)))
color_list.append(color[0])
elif color is not None and len(color) == df[chr].nunique():
color_list = color
Expand All @@ -343,7 +369,7 @@ def mhat(df="dataframe", chr=None, pv=None, color=None, dim=(6,4), r=300, ar=90,
if gwas_sign_line is True:
ax.axhline(y=-np.log10(gwasp), linestyle='--', color='#7d7d7d', linewidth=1)
if markernames is not None:
marker.geneplot_mhat(df, markeridcol, chr, pv, gwasp, markernames, gfont, ax=ax)
marker.geneplot_mhat(df, markeridcol, chr, pv, gwasp, markernames, gfont, gstyle, ax=ax)
ax.margins(x=0)
ax.margins(y=0)
ax.set_xticks(xticks)
Expand Down

0 comments on commit 42ba4c4

Please sign in to comment.