-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed some bugs in Manhattan plotting #47
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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())): | ||
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: | ||
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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: | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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.