# Data-generating model shared by make_data.py and simulation.py. Python 3.13, NumPy.
# ChIP-qPCR at one target region: in each independent experiment, vehicle- and drug-treated cells give separate
# chromatin preparations; each gives an IP, an IgG control and a 1% input, each run in 3 qPCR wells. The true
# percent input (about 2%) varies between experiments (cross-linking, sonication, antibody lot) and a little between
# the two preparations of one experiment; IgG background varies more and its high Ct makes wells noisier.
import numpy as np
REPS = 3

def experiment(rng, drug_ratio=1.0, pct=2.0, sd_day=0.5, sd_prep=0.25, igg=0.05, sd_igg=0.6, sd_ct=0.2, sd_ct_igg=0.4):
    rows = []; day = rng.normal(0, sd_day)
    for cond, ratio in (("vehicle", 1.0), ("drug", drug_ratio)):
        amount = rng.normal(0, 0.3)                                   # chromatin amount (log2), shifts every Ct of the prep
        p_ip = pct * ratio * 2 ** (day + rng.normal(0, sd_prep)); p_igg = igg * 2 ** rng.normal(0, sd_igg)
        ct_in = 25 - amount                                           # Ct of the 1% input
        for sample, ct, sd in (("input", ct_in, sd_ct), ("IP", ct_in - np.log2(100) - np.log2(p_ip / 100), sd_ct),
                               ("IgG", ct_in - np.log2(100) - np.log2(p_igg / 100), sd_ct_igg)):
            rows += [(cond, sample, r + 1, round(ct + rng.normal(0, sd), 2)) for r in range(REPS)]
    return rows
