Drug-Induced Liver Injury (DILI) Risk Comparison Dashboard

DrugBank database
MolPort database
Python script number 57 to build the frequency distribution graph of the DILI parameter on DrugBank molecules.
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
from matplotlib.lines import Line2D
import numpy as np
from scipy.interpolate import make_interp_spline

# 1. DILI (Probability) Data
bin_centers = [0.10, 0.15, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50, 
               0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85, 0.90, 0.95]

frequencies = [0.12, 0.36, 0.81, 3.20, 4.98, 6.55, 7.61, 8.66, 8.33, 
               8.66, 7.36, 8.01, 8.70, 10.40, 7.52, 5.22, 3.11, 0.40]

# 2. Smoothing (Spline to see the shape of the distribution)
x_smooth = np.linspace(min(bin_centers), max(bin_centers), 300)
spl = make_interp_spline(bin_centers, frequencies, k=3)
y_smooth = spl(x_smooth)
y_smooth = [val if val > 0 else 0 for val in y_smooth]

# 3. Colors (Risk Traffic Light)
colors = []
for val in bin_centers:
    if val < 0.3:
        colors.append('mediumseagreen')
    elif val > 0.7:
        colors.append('firebrick')
    else:
        colors.append('gold')

# 4. Create the chart
plt.figure(figsize=(7, 6))

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

# 5. Tags and Titles
plt.xlabel('DILI Probability Score (0=Safe, 1=Toxic)', fontsize=12)
plt.ylabel('% Frequency', fontsize=12)
plt.title('Drug-Induced Liver Injury (DILI) Risk Profile', fontsize=14)

# Axle settings
plt.xticks(np.arange(0.1, 1.0, 0.1))
plt.xlim(0.05, 1.0)
plt.ylim(0, 12)

# 6. Legend
legend_elements = [
    Patch(facecolor='mediumseagreen', edgecolor='black', alpha=0.7, label='Predicted Safe (< 0.3)'),
    Patch(facecolor='gold', edgecolor='black', alpha=0.7, label='Ambiguous / Monitor Req. (0.3 - 0.7)'),
    Patch(facecolor='firebrick', edgecolor='black', alpha=0.7, label='Predicted DILI Positive (> 0.7)'),
]

plt.legend(handles=legend_elements, loc='upper left', framealpha=0.95)

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

plt.show()