1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- def geneplot(d, geneid, lfc, lfc_thr, pv_thr, genenames, gfont, pv, gstyle):
- if genenames is not None and genenames == "deg":
- for i in d[geneid].unique():
- if (d.loc[d[geneid] == i, lfc].iloc[0] >= lfc_thr[0] and d.loc[d[geneid] == i, pv].iloc[0] < pv_thr[0]) or \
- (d.loc[d[geneid] == i, lfc].iloc[0] <= -lfc_thr[1] and d.loc[d[geneid] == i, pv].iloc[0] < pv_thr[1]):
- if gstyle==1:
- plt.text(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].iloc[0], i,
- fontsize=gfont)
- elif gstyle==2:
- plt.annotate(i, xy=(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].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 d[geneid].unique():
- if i in genenames:
- if gstyle==1:
- plt.text(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].iloc[0], i,
- fontsize=gfont)
- elif gstyle==2:
- plt.annotate(i, xy=(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].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 d[geneid].unique():
- if i in genenames:
- if gstyle==1:
- plt.text(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].iloc[0],
- genenames[i], fontsize=gfont)
- elif gstyle == 2:
- plt.annotate(genenames[i], xy=(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].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)
|