Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CSP_Rank/fig2.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
81 lines (66 sloc)
3.11 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import pandas as pd | |
import seaborn as sns | |
import numpy as np | |
CSmethod = "UCBShift" | |
data_source_file = './CSPRANK.csv' | |
df = pd.read_csv(data_source_file) | |
# Create figure and define a GridSpec for layout | |
fig = plt.figure(figsize=(15, 10)) | |
gs = fig.add_gridspec(2, 2, height_ratios=[1, 2], width_ratios=[1, 1]) | |
# Top plot spanning both columns | |
ax_top = fig.add_subplot(gs[0, :]) | |
# Bottom left and right plots | |
ax_bottom_left = fig.add_subplot(gs[1, 0]) | |
ax_bottom_right = fig.add_subplot(gs[1, 1]) | |
# Histogram for AF2_TM scores | |
ax_top.hist(df['AF2_TM_align'].dropna(), bins=20, color='blue', alpha=0.7) | |
ax_top.set_xlabel('TM score', fontsize=20) | |
ax_top.set_ylabel('Frequency', fontsize=20) | |
ax_top.set_xlim((0.0, 1)) | |
# Calculate residuals | |
df['residual_1'] = df['F_AF2'] - df['F_NMR'] | |
df['residual_2'] = df['MCC_AF2'] - df['MCC_NMR'] | |
df['residual_3'] = df['consensus_AF2'] - df['consensus_NMR'] | |
# Scatter plot | |
sns.scatterplot(ax=ax_bottom_left, x=df['consensus_NMR'], y=df['consensus_AF2']) | |
ax_bottom_left.plot([0, 1], [0, 1], color='red') | |
ax_bottom_left.set_xlabel('PDB model CSP_Rank_Score', fontsize=20) | |
ax_bottom_left.set_ylabel('Baseline AF2 CSP_Rank_Score', fontsize=20) | |
ax_bottom_left.text(0.7, 0.1, 'PDB>AF2', color='red', fontweight='bold', fontsize=22, | |
verticalalignment='bottom', horizontalalignment='left', transform=ax_bottom_left.transAxes) | |
ax_bottom_left.text(0.1, 0.9, 'AF2>PDB', color='red', fontweight='bold', fontsize=22, | |
verticalalignment='top', horizontalalignment='left', transform=ax_bottom_left.transAxes) | |
# Histogram of residuals | |
data = df['residual_3'] | |
max_abs_value = max(abs(data.min()), abs(data.max())) | |
symmetric_range = (-max_abs_value, max_abs_value) | |
bin_width = (symmetric_range[1] - symmetric_range[0]) / 20 | |
bins = np.arange(symmetric_range[0], symmetric_range[1] + bin_width, bin_width) | |
sns.histplot(ax=ax_bottom_right, data=data, kde=True, bins=bins) | |
ax_bottom_right.set_xlabel('Residual', fontsize=20) | |
ax_bottom_right.set_ylabel('Frequency', fontsize=20) | |
ax_bottom_right.axvline(x=0.0, color='red', linestyle='-', linewidth=2) | |
ax_bottom_right.text(0.7, 0.7, 'AF2>PDB', color='red', fontweight='bold', fontsize=22, | |
verticalalignment='bottom', horizontalalignment='left', transform=ax_bottom_right.transAxes) | |
ax_bottom_right.text(0.05, 0.7, 'PDB>AF2', color='red', fontweight='bold', fontsize=22, | |
verticalalignment='top', horizontalalignment='left', transform=ax_bottom_right.transAxes) | |
plt.tight_layout() | |
plt.show() | |
plt.clf() | |
plt.close() | |
# Scatter plot for AF2_TM_align vs residual_3 | |
plt.figure(figsize=(10, 6)) | |
sns.scatterplot(x=df['AF2_TM_align'], y=df['residual_3'], alpha=0.7, color='blue') | |
# Add a horizontal line at y=0 for reference | |
plt.axhline(y=0, color='red', linestyle='--', linewidth=2) | |
# Set axis labels and title | |
plt.xlabel('AF2_TM_align', fontsize=16) | |
plt.ylabel('Residual (consensus_AF2 - consensus_NMR)', fontsize=16) | |
plt.title('AF2_TM_align vs Residual (consensus_AF2 - consensus_NMR)', fontsize=18) | |
# Customize ticks | |
plt.xticks(fontsize=12) | |
plt.yticks(fontsize=12) | |
# Show the plot | |
plt.tight_layout() | |
plt.show() |