def geneplot_ma(df, geneid, lfc, lfc_thr, genenames, gfont, gstyle): if genenames is not None and genenames == "deg": for i in df[geneid].unique(): if df.loc[df[geneid] == i, lfc].iloc[0] >= lfc_thr[0] or \ df.loc[df[geneid] == i, lfc].iloc[0] <= -lfc_thr[1]: if gstyle == 1: plt.text(df.loc[df[geneid] == i, 'A_add_axy'].iloc[0], df.loc[df[geneid] == i, lfc].iloc[0], i, fontsize=gfont) elif gstyle == 2: plt.annotate(i, xy=(df.loc[df[geneid] == i, 'A_add_axy'].iloc[0], df.loc[df[geneid] == i, lfc].iloc[0]), xycoords='data', xytext=(5, -15), textcoords='offset points', size=6, bbox=dict(boxstyle="round", alpha=0.1), arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1, relpos=(0, 0))) else: print("Error: invalid gstyle choice") sys.exit(1) elif genenames is not None and type(genenames) is tuple: for i in df[geneid].unique(): if i in genenames: if gstyle == 1: plt.text(df.loc[df[geneid] == i, 'A_add_axy'].iloc[0], df.loc[df[geneid] == i, lfc].iloc[0], i, fontsize=gfont) elif gstyle == 2: plt.annotate(i, xy=(df.loc[df[geneid] == i, 'A_add_axy'].iloc[0], df.loc[df[geneid] == i, lfc].iloc[0]), xycoords='data', xytext=(5, -15), textcoords='offset points', size=6, bbox=dict(boxstyle="round", alpha=0.1), arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1, relpos=(0, 0))) else: print("Error: invalid gstyle choice") sys.exit(1) elif genenames is not None and type(genenames) is dict: for i in df[geneid].unique(): if i in genenames: if gstyle == 1: plt.text(df.loc[df[geneid] == i, 'A_add_axy'].iloc[0], df.loc[df[geneid] == i, lfc].iloc[0], genenames[i], fontsize=gfont) elif gstyle == 2: plt.annotate(genenames[i], xy=(df.loc[df[geneid] == i, 'A_add_axy'].iloc[0], df.loc[df[geneid] == i, lfc].iloc[0]), xycoords='data', xytext=(5, -15), textcoords='offset points', size=6, bbox=dict(boxstyle="round", alpha=0.1), arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1, relpos=(0, 0))) else: print("Error: invalid gstyle choice") sys.exit(1)