Mouse Carcinogenic Potency Distribution Dashboard

DrugBank database
MolPort database
Python script number 73 to build the frequency distribution graph of the Mouse_carcinogenicity parameter on DrugBank molecules.
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
import numpy as np

# 1. Original Data (Mouse Carcinogenicity - Quantitative TD50)
bin_centers = np.array([-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5])
frequencies = np.array([0.17, 0.81, 2.68, 7.09, 12.27, 22.12, 22.00, 12.61, 9.60, 6.58, 2.46, 1.23, 0.34, 0.04])

# Exact Parameters
amp = 21.19
mean = 0.8277
std_dev = 0.9122

def gauss_exact(x, a, mu, sigma):
    return a * np.exp(-((x - mu)**2) / (2 * sigma**2))

x_fit = np.linspace(-2.5, 5.0, 500)
y_fit = gauss_exact(x_fit, amp, mean, std_dev)

# 2. Hexadecimal Colors (TD50 Biological Thresholds)
color_safe = '#008000'
color_warn = '#FFD700'
color_danger = '#B22222'

colors = []
for val in bin_centers:
    if val < 1.0:
        colors.append(color_safe)
    elif val <= 3.0:
        colors.append(color_warn)
    else:
        colors.append(color_danger)

# 3. Create the graph
plt.figure(figsize=(7, 6))

# Bars
plt.bar(bin_centers, frequencies, width=0.4, color=colors, edgecolor='black', alpha=0.7, label='Observed Data')

# Trend Line Gaussian
plt.plot(x_fit, y_fit, color='orange', linewidth=3, 
         label=f'Gaussian Fit\n$\\mu={mean:.4f}, \\sigma={std_dev:.4f}$')

# 4. Tags and Titles
plt.xlabel(r'Carcinogenic Potency ($-\log_{10} TD_{50}$)', fontsize=12)
plt.ylabel('% Frequency', fontsize=12)
plt.title('Mouse Carcinogenic Potency Distribution', fontsize=14)

# 5. Legend (Restored)
legend_elements = [
    Patch(facecolor=color_safe, edgecolor='black', label='Very Low Risk ($< 1$)'),
    Patch(facecolor=color_warn, edgecolor='black', label='Low-Moderate Risk ($1 - 3$)'),
    Patch(facecolor=color_danger, edgecolor='black', label='High Risk Elimination ($> 3$)'),
    plt.Line2D([0], [0], color='orange', lw=3, label=f'Fit (Mean={mean}, SD={std_dev})'),
]

plt.legend(handles=legend_elements, loc='upper right', framealpha=0.95, fontsize=10)

plt.grid(axis='y', linestyle='--', alpha=0.5)
plt.tight_layout()

plt.show()