codexrna-required-segment-intact-probability.py
rna-required-segment-intact-probability.py
"""Draw rna-required-segment-intact-probability.png in CWD on opaque white.
Original independent-cut model, not an RNA integrity number calibration.
Tested with Python 3.14.4, NumPy 2.3.5, Matplotlib 3.10.7.
"""
from pathlib import Path
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
def main():
cut_density = .001
length = np.linspace(0, 2000, 401)
fig, ax = plt.subplots(figsize=(6.8, 4.3), dpi=100)
fig.subplots_adjust(left=.12, right=.97, top=.80, bottom=.26)
ax.plot(length, np.exp(-cut_density*length), color='#1768ac', lw=2.5)
for required, text_pos in [(100, (430, .91)), (1000, (1180, .49))]:
probability = np.exp(-cut_density*required)
ax.scatter([required], [probability], color='#b66316', s=40, zorder=4)
ax.annotate(f'L = {required} nt\nP = {probability:.3f}',
(required, probability), xytext=text_pos,
arrowprops={'arrowstyle': '-', 'color': '#b66316'},
fontsize=10, color='#8e4a10')
ax.set(xlim=(0, 2000), ylim=(0, 1.03),
xlabel='Required unbroken segment length L (nucleotides)',
ylabel='Probability the required segment is intact')
ax.spines[['top', 'right']].set_visible(False)
ax.grid(alpha=.18)
fig.suptitle('Short target segments can survive\nwhen long RNA regions often do not', y=.98, fontsize=14)
fig.text(.5, .095, r'Illustrative Poisson cuts: $P(\mathrm{intact})=e^{-kL}$; $k=0.001$ cuts/nt.',
ha='center', fontsize=10)
fig.text(.5, .035, 'Not experimental data, an assay-performance guarantee or a conversion from RIN.',
ha='center', fontsize=9)
fig.savefig(Path.cwd() / 'rna-required-segment-intact-probability.png',
facecolor='white', transparent=False)
plt.close(fig)
if __name__ == '__main__':
main()