From 9acc42774db3261904b6d528665d2365457858bf Mon Sep 17 00:00:00 2001 From: liliwen Date: Mon, 18 Apr 2022 00:25:13 +0800 Subject: [PATCH] Fixed some bugs in Manhattan plotting 1. Sorting problem when chr column cannot be converted into numbers; 2. Unable to change font name and size of tick labels; 3. Unable to annote all the dots higher than gwasp when markernames=True --- .DS_Store | Bin 0 -> 6148 bytes bioinfokit/visuz.py | 29 +++++++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b12f6e49f0fd4b01fee42b2ac22b63aabc63d160 GIT binary patch literal 6148 zcmeHK%}N6?5Kh`^cP&B>3OxqA7Ob@v#LKeQ7jQ)nDs`8wx^zuSyS0Z>*t5QnPvY}9 zlcZv4J$MnZGcfs*`Pq;!OD18Aaeo{iFji%ZIiQFI7n&7B3af&VQUq{%32G~RikSlZYuJ7uTh+y;+o5@caE z9{J($8b=pOrO~_}Mwdx%(yi{CDw&0e>h~n)qrgYVv$~ibHyd@)I&9BouCu$he{$aKr%zJ77(zMxds?bkb2Q+wnM1Khp1^W1w zKok}|i@8DYfN+xvXi~X-VsMiVc46Z@i@8CQ&bXc#zGG+R_JzXr>|hr<}wZs51 zu*g8s469iG&%S^EFDB857$64z6$8A~2|7M3$=24T#bK=#pm(4s7?&ITOo5Ir#Sn|7 dxCW{P>;gN0p2gfCSU~6^plP6n82D8NJ^)eHP2~Up literal 0 HcmV?d00001 diff --git a/bioinfokit/visuz.py b/bioinfokit/visuz.py index 1fd3620..3dc33c6 100644 --- a/bioinfokit/visuz.py +++ b/bioinfokit/visuz.py @@ -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] # 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) # ax.set_yticklabels(ylm, fontsize=axtickfontsize, fontname=axtickfontname, rotation=ar) if axxlabel: _x = axxlabel