visualize_5_3.py 2.9 KB

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