visualize_5_2.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. def gene_plot(d, geneid, lfc, lfc_thr, pv_thr, genenames, gfont, pv, gstyle):
  2. if genenames is not None and genenames == "deg":
  3. for i in d[geneid].unique():
  4. 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 \
  5. (d.loc[d[geneid] == i, lfc].iloc[0] <= -lfc_thr[1] and d.loc[d[geneid] == i, pv].iloc[0] < pv_thr[1]):
  6. if gstyle == 1:
  7. plt.text(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].iloc[0], i,
  8. fontsize=gfont)
  9. elif gstyle == 2:
  10. plt.annotate(i, xy=(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].iloc[0]),
  11. xycoords='data', xytext=(5, -15), textcoords='offset points', size=6,
  12. bbox=dict(boxstyle="round", alpha=0.1),
  13. arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1, relpos=(0, 0)))
  14. else:
  15. print("Error: invalid gstyle choice")
  16. sys.exit(1)
  17. elif genenames is not None and type(genenames) is tuple:
  18. for i in d[geneid].unique():
  19. if i in genenames:
  20. if gstyle == 1:
  21. plt.text(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].iloc[0], i,
  22. fontsize=gfont)
  23. elif gstyle == 2:
  24. plt.annotate(i, xy=(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].iloc[0]),
  25. xycoords='data', xytext=(5, -15), textcoords='offset points', size=6,
  26. bbox=dict(boxstyle="round", alpha=0.1),
  27. arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1, relpos=(0, 0)))
  28. else:
  29. print("Error: invalid gstyle choice")
  30. sys.exit(1)
  31. elif genenames is not None and type(genenames) is dict:
  32. for i in d[geneid].unique():
  33. if i in genenames:
  34. if gstyle == 1:
  35. plt.text(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].iloc[0],
  36. genenames[i], fontsize=gfont)
  37. elif gstyle == 2:
  38. plt.annotate(genenames[i], xy=(d.loc[d[geneid] == i, lfc].iloc[0], d.loc[d[geneid] == i, 'logpv_add_axy'].iloc[0]),
  39. xycoords='data', xytext=(5, -15), textcoords='offset points', size=6,
  40. bbox=dict(boxstyle="round", alpha=0.1),
  41. arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1, relpos=(0, 0)))
  42. else:
  43. print("Error: invalid gstyle choice")
  44. sys.exit(1)