|
| 1 | +import pandas as pd |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +from adjustText import adjust_text |
| 4 | +import seaborn as sns |
| 5 | + |
| 6 | +data1 = pd.read_csv('D:\\New2\\1_residue.csv', header = 0) |
| 7 | +[data1.drop([ind], inplace = True) for ind in data1[data1.pep_only.str.contains('HOH')].index] |
| 8 | +data2_res = pd.read_csv('D:\\New2\\2_residue_resist.csv', header = 0) |
| 9 | + |
| 10 | +data1.to_excel('D:\\New2\\1_residue.xlsx') |
| 11 | +data2_res.to_excel('D:\\New2\\2_residue.xlsx') |
| 12 | + |
| 13 | +def Plot(datas, title): |
| 14 | + fig, axes = plt.subplots(ncols = len(datas)) |
| 15 | + for n, data in enumerate(datas): |
| 16 | + box_dict = axes[n].boxplot(data['value']) |
| 17 | + flier = box_dict['fliers'] |
| 18 | + position = [(flier[i].get_xdata(),flier[i].get_ydata()) for i in range(len(flier))] |
| 19 | + post = [(position[0][0][i], position[0][1][i]) for i in range(len(position[0][0]))] |
| 20 | + pep_name = [data[data['value'] == y]['pep_only'].values[0] for x, y in post] |
| 21 | + [axes[n].text(x + 0.02, y + 0.02, s = data[data['value'] == y]['pep_only'].values[0], color = 'r') for x,y in post] |
| 22 | + axes[n].set_xticks([],[]) |
| 23 | + axes[n].set_title(title[n], color = 'b') |
| 24 | + axes[n].set_ylabel('Năng lượng tự do trung bình (kcal/mol)') |
| 25 | + texts = [axes[n].annotate(data.iloc[i]['pep_only'], color = 'r', xy = (1, data.iloc[i]['value']), xytext = (1, data.iloc[i]['value'] + 0.05), arrowprops=dict(arrowstyle="fancy", color = 'r', connectionstyle="angle3,angleA=0,angleB=-90")) for i in range(5) if all(~data.iloc[i].isin(pep_name))] |
| 26 | + adjust_text(texts) |
| 27 | + |
| 28 | + |
| 29 | +def Plotsame(datas, title): |
| 30 | + fig, axes = plt.subplots() |
| 31 | + # axes.violinplot([datas[0]['value'], datas[1]['value']]) |
| 32 | + box_dict = axes.boxplot([datas[0]['value'], datas[1]['value']]) |
| 33 | + flier = box_dict['fliers'] |
| 34 | + position = [(flier[i].get_xdata(),flier[i].get_ydata()) for i in range(len(flier))] |
| 35 | + post = [(position[0][0][i], position[0][1][i]) for i in range(len(position[0][0]))] |
| 36 | + pep_name = [datas[int(x)-1][datas[int(x)-1]['value'] == y]['pep_only'].values[0] for x, y in post] |
| 37 | + [axes.text(x + 0.02, y + 0.02, s = datas[int(x)-1][datas[int(x)-1]['value'] == y]['pep_only'].values[0], color = 'r', fontsize = 11) for x,y in post] |
| 38 | + axes.set_xticklabels(title, color = 'b', fontsize = 13) |
| 39 | + axes.set_ylabel('Năng lượng tự do trung bình (kcal/mol)', fontsize = 13) |
| 40 | + texts = [axes.annotate(datas[n].iloc[i]['pep_only'], color = 'r', xy = (n+1, datas[n].iloc[i]['value']), xytext = (n+1, datas[n].iloc[i]['value'] + 0.05), arrowprops=dict(arrowstyle="fancy", color = 'r', connectionstyle="angle3,angleA=0,angleB=-90"), fontsize = 11) for n in range(2) for i in range(6) if (n+1, datas[n].iloc[i]['value']) not in post] |
| 41 | + adjust_text(texts) |
| 42 | + |
| 43 | + |
| 44 | +def Plotswarm(datas, title): |
| 45 | + data = pd.concat([datas[0]['value'], datas[1]['value']], axis = 1, keys = title).stack(0).reset_index(level = 1) |
| 46 | + data.columns = ['index', 'value'] |
| 47 | + axes = sns.swarmplot(x = 'index', y = 'value', data = data, order = title) |
| 48 | + text1 = [axes.annotate(datas[n].iloc[i]['pep_only'], color = 'r', xy = (n, datas[n].iloc[i]['value']), xytext = (n + 0.05, datas[n].iloc[i]['value'] - 0.05), fontsize = 11) for n in range(1) for i in range(10) if datas[n].iloc[i]['value'] < -3] |
| 49 | + text2 = [axes.annotate(datas[n].iloc[i]['pep_only'], color = 'r', xy = (n, datas[n].iloc[i]['value']), xytext = (n + 0.1, datas[n].iloc[i]['value'] - 0.05), arrowprops=dict(arrowstyle="fancy", color = 'grey', alpha = 0.3, connectionstyle="angle3,angleA=0,angleB=-90"), fontsize = 11) for n in range(1,2) for i in range(10) if datas[n].iloc[i]['value'] < -3] |
| 50 | + # text3 = [axes.annotate(datas[n].iloc[i]['pep_only'], color = 'g', xy = (n, datas[n].iloc[i]['value']), xytext = (n + 0.1, datas[n].iloc[i]['value'] - 0.05), arrowprops=dict(arrowstyle="fancy", color = 'grey', alpha = 0.3, connectionstyle="angle3,angleA=0,angleB=-90"), fontsize = 11) for n in range(1,2) for i in range(len(datas[1])) if datas[n].iloc[i]['value'] > 0] |
| 51 | + axes.set_xticklabels(title, color = 'b', fontsize = 13) |
| 52 | + axes.set_ylabel('Năng lượng tự do trung bình (kcal/mol)', fontsize = 13) |
| 53 | + axes.set_xlabel('') |
| 54 | + adjust_text(text2) |
| 55 | + # adjust_text(text3) |
| 56 | + |
| 57 | +# Plot(datas = [data1, data2_res], title = ['6BKL','2LY0']) |
| 58 | +Plotswarm(datas = [data1, data2_res], title = ['6BKL','2LY0']) |
| 59 | +plt.tight_layout() |
| 60 | +plt.show() |
0 commit comments