Environmental Hazard: Eukaryotic Basal Toxicity (T. pyriformis)

DrugBank database
MolPort database
Python script number 108 to build the frequency distribution graph of the pyriformis_toxicity_c parameter on DrugBank molecules.
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from matplotlib.patches import Patch
import numpy as np
from scipy.interpolate import PchipInterpolator

# 1. PASTE YOUR DATA HERE (pyriformis_toxicity_c)
datos_crudos = """Bin Center	% Frequency
0	2.84501061571125
0.05	5.05307855626327
0.1	2.33545647558386
0.15	2.4203821656051
0.2	2.37791932059448
0.25	2.1656050955414
0.3	1.40127388535032
0.35	1.78343949044586
0.4	2.12314225053079
0.45	1.23142250530786
0.5	1.6135881104034
0.55	1.82590233545648
0.6	1.52866242038217
0.65	1.40127388535032
0.7	1.91082802547771
0.75	2.59023354564756
0.8	3.90658174097665
0.85	5.22292993630573
0.9	9.51167728237792
0.95	17.5796178343949
1	29.171974522293"""

# 2. AUTOMATIC PROCESSING
lineas = datos_crudos.strip().split('\n')[1:] 
bins_array = []
freq_array = []

for linea in lineas:
    b, f = linea.strip().split() 
    bins_array.append(float(b))
    freq_array.append(float(f))

bins = np.array(bins_array)
freq = np.array(freq_array)

mean_val = np.average(bins, weights=freq)

interpolator = PchipInterpolator(bins, freq)
x_fit = np.linspace(min(bins), max(bins), 500)
y_fit = interpolator(x_fit)
y_fit = np.clip(y_fit, 0, None)

def get_colors(b_array):
    return ['#008000' if b < 0.4 else '#FFD700' if b <= 0.7 else '#B22222' for b in b_array]

colors_hex = get_colors(bins)
face_colors = [mcolors.to_rgba(c, alpha=0.60) for c in colors_hex]
edge_colors = [mcolors.to_rgba(c, alpha=0.90) for c in colors_hex]

# 3. CREATION OF THE GRAPH
plt.figure(figsize=(7, 6))

plt.bar(bins, freq, width=0.04, color=face_colors, edgecolor=edge_colors, linewidth=1.5, zorder=2)

plt.xlabel('T. pyriformis Toxicity Probability (pIGC50 > -0.5)', fontsize=12)
plt.ylabel('% Frequency', fontsize=12)
plt.title('Environmental Hazard: Eukaryotic Basal Toxicity (T. pyriformis)', fontsize=14)

legend_elements = [
    Patch(facecolor=mcolors.to_rgba('#008000', 0.6), edgecolor='#008000', label='Low Toxicity / Non-TPT (< 0.4)'),
    Patch(facecolor=mcolors.to_rgba('#FFD700', 0.6), edgecolor='#FFD700', label='Moderate Hazard (0.4 - 0.7)'),
    Patch(facecolor=mcolors.to_rgba('#B22222', 0.6), edgecolor='#B22222', label='High Toxicity / TPT-positive (> 0.7)')
]
plt.legend(handles=legend_elements, loc='upper left', framealpha=0.95, fontsize=10)

plt.grid(axis='y', linestyle=':', alpha=0.7, zorder=0)
plt.xlim(-0.05, 1.05)
plt.ylim(0, max(freq) * 1.2) 
plt.tight_layout()

plt.show()