scripts.step_1b_fit_downregulation¶
Reverse (Rev) time-course analysis.
This module loads flow cytometry FCS files, applies boundary and singlet gates, computes per-file medians, subtracts NFC-derived background, constructs a Rev-only time-course dataset, performs per-plasmid min–max normalization on BFP, fits an exponential decay model to estimate half-times (t1/2), generates diagnostic plots, and writes the estimated parameters to CSV.
Outputs
- plots/REV_SP430ABA_fitting.pdf
- plots/REV_dCas9_fitting.pdf
- plots/REV_KRAB-dCas9_fitting.pdf
- plots/REV_HDAC4-dCas9_fitting.pdf
- plots/REV_CasRx_fitting.pdf
- parameters/half_times_downregulation.csv
add_minmax_norm ¶
add_minmax_norm(df)
Add per-plasmid min–max normalization for downregulation:
mean.final = mean(BFP | time > 10) mean.init = mean(BFP | time == 0) norm.bfp = (BFP - mean.final) / (mean.init - mean.final)
Parameters¶
df : pd.DataFrame Rev dataset with columns [plasmid, time, BV421-A].
Returns¶
pd.DataFrame Input with added columns mean.final, mean.init, norm.bfp.
Source code in scripts/step_1b_fit_downregulation.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
apply_boundary_gate ¶
apply_boundary_gate(df)
Apply coarse boundary gate on FSC-A and SSC-A.
Parameters¶
df : pd.DataFrame Events table with FSC-A and SSC-A.
Returns¶
pd.DataFrame Subset passing the boundary gate.
Source code in scripts/step_1b_fit_downregulation.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
apply_singlet_gate ¶
apply_singlet_gate(df)
Keep singlets using FSC-H / FSC-A ratio.
Parameters¶
df : pd.DataFrame Events table with FSC-H and FSC-A.
Returns¶
pd.DataFrame Subset passing the singlet gate.
Source code in scripts/step_1b_fit_downregulation.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
compute_nfc_background ¶
compute_nfc_background(nfc_dir)
Estimate background medians from NFC files (first 3 medians).
Parameters¶
nfc_dir : str Directory with NFC .fcs files.
Returns¶
(float, float) (mBFP_neg, mmCherry_neg) background medians.
Source code in scripts/step_1b_fit_downregulation.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
exp_decay ¶
exp_decay(t, t_half)
Exponential decay model
y(t) = exp(-t * ln(2) / t_half)
Parameters¶
t : array-like Time points. t_half : float Half-time parameter.
Returns¶
np.ndarray Model values y(t).
Source code in scripts/step_1b_fit_downregulation.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
fit_half_time ¶
fit_half_time(t, y, start=0.1)
Fit exponential decay to (t, y) to estimate half-time.
Parameters¶
t : array-like Time points. y : array-like Normalized response (ideally in [0, 1]). start : float, optional Initial guess for t_half, by default 0.1.
Returns¶
(float, float) (t_half estimate, standard error). SE is NaN if covariance missing.
Raises¶
RuntimeError If fewer than 3 finite points are available.
Source code in scripts/step_1b_fit_downregulation.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
load_flowset_medians ¶
load_flowset_medians(folder)
Load all FCS files in a folder and compute gated medians.
Parameters¶
folder : str Directory with .fcs files.
Returns¶
pd.DataFrame One row per file with medians and '__filename'.
Source code in scripts/step_1b_fit_downregulation.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
load_rev_timecourse ¶
load_rev_timecourse(mBFP_neg, mmCherry_neg)
Build Rev-only dataset with background-subtracted medians.
Parameters¶
mBFP_neg : float BFP background (NFC mean of first 3 medians). mmCherry_neg : float mCherry background (NFC mean of first 3 medians).
Returns¶
pd.DataFrame Columns: [BV421-A, PE-A, plasmid, exp, rep, time]
Source code in scripts/step_1b_fit_downregulation.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
median_channels_for_file ¶
median_channels_for_file(fpath)
Compute per-file channel medians after gating.
Parameters¶
fpath : str Path to .fcs file.
Returns¶
pd.Series Median values (numeric-only) with '__filename' field.
Source code in scripts/step_1b_fit_downregulation.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
parse_timecourse_name ¶
parse_timecourse_name(name)
Parse plasmid/exp/rep/time tokens from filename stem.
Parameters¶
name : str Basename without extension.
Returns¶
(str, str, str, float) (plasmid, exp, rep, time)
Source code in scripts/step_1b_fit_downregulation.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
save_rev_plot ¶
save_rev_plot(df, t_half, out_pdf)
Save a Rev plot (norm.bfp vs time) with fitted decay curve.
Parameters¶
df : pd.DataFrame Data for a single plasmid with 'time' and 'norm.bfp'. t_half : float Estimated half-time to draw the curve. out_pdf : str Output PDF filename (saved in OUT_PATH).
Source code in scripts/step_1b_fit_downregulation.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |