Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
29 changes: 15 additions & 14 deletions bioinfokit/visuz.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,18 @@ def geneplot_mhat(df, markeridcol, chr, pv, gwasp, markernames, gfont, gstyle, a
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:
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)))
for j in range(len(df[chr].unique())):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This for-loop enables the annotator iterates all the chromosome, so that it won't only mark the first chromosome.

if df.loc[df[markeridcol] == i, pv].iloc[j] <= gwasp:
if gstyle == 1:
plt.text(df.loc[df[markeridcol] == i, 'ind'].iloc[j], df.loc[df[markeridcol] == i, 'tpval'].iloc[j],
str(i), fontsize=gfont)
elif gstyle == 2:
plt.annotate(i, xy=(df.loc[df[markeridcol] == i, 'ind'].iloc[j], df.loc[df[markeridcol] == i, 'tpval'].iloc[j]),
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():
if i in markernames:
Expand Down Expand Up @@ -631,7 +634,7 @@ def mhat(df="dataframe", chr=None, pv=None, log_scale=True, color=None, dim=(6,4
df['tpval'] = df[pv]
# df = df.sort_values(chr)
# if the column contains numeric strings
df = df.loc[pd.to_numeric(df[chr], errors='coerce').sort_values().index]
df = df.loc[pd.to_numeric(df[chr], errors='ignore').sort_values().index]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'coerce' will produce nan if not convertible, while ignore will maintain the input. This change from makes the column still sortable even if it cannot be converted to numbers. If the column isn't sorted, it will result in color problem in the plot.

# add indices
df['ind'] = range(len(df))
df_group = df.groupby(chr)
Expand All @@ -657,14 +660,12 @@ def mhat(df="dataframe", chr=None, pv=None, log_scale=True, color=None, dim=(6,4
if theme == 'dark':
general.dark_bg()
fig, ax = plt.subplots(figsize=dim)
i = 0
for label, df1 in df.groupby(chr):
for i, (label, df1) in enumerate(df.groupby(chr)):
df1.plot(kind='scatter', x='ind', y='tpval', color=color_list[i], s=dotsize, alpha=valpha, ax=ax)
df1_max_ind = df1['ind'].iloc[-1]
df1_min_ind = df1['ind'].iloc[0]
xlabels.append(label)
xticks.append((df1_max_ind - (df1_max_ind - df1_min_ind) / 2))
i += 1

# add GWAS significant line
if gwas_sign_line is True:
Expand All @@ -681,7 +682,7 @@ def mhat(df="dataframe", chr=None, pv=None, log_scale=True, color=None, dim=(6,4
else:
ylm = np.arange(0, max(df['tpval']+1), 1)
ax.set_yticks(ylm)
ax.set_xticklabels(xlabels, rotation=ar)
ax.set_xticklabels(xlabels, fontsize=axtickfontsize, fontproperties=axtickfontname, rotation=ar)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables the caller to change font name and font size of tick labels, which is especially useful when the labels is in another language.

# ax.set_yticklabels(ylm, fontsize=axtickfontsize, fontname=axtickfontname, rotation=ar)
if axxlabel:
_x = axxlabel
Expand Down