scripts.step_1a_fit_upregulation¶
KD (up-regulation) time-course analysis.
This module loads flow cytometry FCS files, applies boundary and singlet gates, computes per-file medians for relevant channels, constructs a KD-only time-course dataset, performs per-plasmid min–max normalization on BFP, fits an exponential rise-to-one model to estimate half-times (t1/2), generates diagnostic plots, and writes the estimated parameters to CSV.
Outputs
- plots/KD_KRAB-Split-dCas9_fitting.pdf
- plots/KD_dCas9_fitting.pdf
- plots/KD_KRAB-dCas9_fitting.pdf
- plots/KD_HDAC4-dCas9_fitting.pdf
- plots/KD_CasRx_fitting.pdf
- parameters/half_times_upregulation.csv
add_minmax_norm_kd ¶
add_minmax_norm_kd(df)
Add per-plasmid min–max normalization of BFP: mean.final = mean(BFP | time > 10) mean.init = mean(BFP | time == 0) norm.bfp = (BFP - mean.init) / (mean.final - mean.init)
Parameters¶
df : pd.DataFrame KD dataset with columns [plasmid, time, BV421-A].
Returns¶
pd.DataFrame Input df with extra columns: mean.final, mean.init, norm.bfp.
Source code in scripts/step_1a_fit_upregulation.py
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 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
apply_boundary_gate ¶
apply_boundary_gate(df)
Keep events within coarse FSC/SSC bounds.
Parameters¶
df : pd.DataFrame Raw events table with at least FSC-A and SSC-A columns.
Returns¶
pd.DataFrame Subset of events passing the boundary gate.
Source code in scripts/step_1a_fit_upregulation.py
100 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 of events passing the singlet gate.
Source code in scripts/step_1a_fit_upregulation.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
compute_nfc_background ¶
compute_nfc_background(nfc_dir)
Estimate background medians from NFC (negative control) files.
Uses the mean of the first 3 NFC medians for BFP and mCherry.
Parameters¶
nfc_dir : str Directory with NFC .fcs files.
Returns¶
(float, float) Tuple of (mBFP_neg, mmCherry_neg).
Source code in scripts/step_1a_fit_upregulation.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
exp_rise_to_one ¶
exp_rise_to_one(t, t_half)
Exponential rise-to-one model
y(t) = 1 - exp(-t * ln(2) / t_half)
Parameters¶
t : array-like Time points (hours). t_half : float Half-time parameter.
Returns¶
np.ndarray Model values y(t).
Source code in scripts/step_1a_fit_upregulation.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
fit_half_time_rise ¶
fit_half_time_rise(t, y, start=0.8)
Fit the exponential rise-to-one model to (t, y) and estimate half-time.
Parameters¶
t : array-like Time points. y : array-like Normalized response in [0, 1] (ideally). start : float, optional Initial guess for t_half, by default 0.8.
Returns¶
(float, float) Estimated t_half and its standard error (SE). SE is NaN if covariance unavailable.
Raises¶
RuntimeError If there are fewer than 3 finite points to fit.
Source code in scripts/step_1a_fit_upregulation.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
load_flowset_medians ¶
load_flowset_medians(folder, mBFP_neg=0.0, mmCherry_neg=0.0)
Load all .fcs files in a folder and compute gated channel medians per file.
Parameters¶
folder : str Directory containing .fcs files. mBFP_neg : float, optional Background median to subtract from BFP before per-file median, by default 0.0. mmCherry_neg : float, optional Background median to subtract from mCherry before per-file median, by default 0.0.
Returns¶
pd.DataFrame One row per file with medians and '__filename'.
Raises¶
FileNotFoundError
If no .fcs files are found in folder.
Source code in scripts/step_1a_fit_upregulation.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
load_kd_timecourse ¶
load_kd_timecourse(mBFP_neg, mmCherry_neg)
Build the KD-only time-course dataset with background-subtracted medians.
Parameters¶
mBFP_neg : float NFC-derived BFP background to subtract. mmCherry_neg : float NFC-derived mCherry background to subtract.
Returns¶
pd.DataFrame DataFrame with columns [BV421-A, PE-A, plasmid, exp, rep, time].
Source code in scripts/step_1a_fit_upregulation.py
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 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
main ¶
main()
Orchestrate KD up-regulation analysis end-to-end
1) Compute NFC background medians (BFP, mCherry) 2) Load KD time-course medians with background subtraction 3) Add per-plasmid min–max normalization on BFP 4) Fit exponential rise model per target plasmid and save plots 5) Save half-times to CSV
Source code in scripts/step_1a_fit_upregulation.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | |
median_channels_for_file ¶
median_channels_for_file(fpath, mBFP_neg=0.0, mmCherry_neg=0.0)
Compute per-channel medians for one FCS file, with gating and optional background subtraction.
Parameters¶
fpath : str Path to the .fcs file. mBFP_neg : float, optional Background (negative control) median for BFP to subtract before median, by default 0.0. mmCherry_neg : float, optional Background (negative control) median for mCherry to subtract before median, by default 0.0.
Returns¶
pd.Series Median values (numeric-only) per channel with an extra '__filename' field (basename without extension).
Raises¶
ValueError If any required channel is missing in the FCS data.
Source code in scripts/step_1a_fit_upregulation.py
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
parse_timecourse_name ¶
parse_timecourse_name(name)
Parse tokens from a filename (already stripped of extension) to extract: plasmid, experiment label, replicate, and numeric time.
Expected pattern (R analogy): separate(rowname, c(NA,NA,"plasmid","exp","rep","time",NA,NA), "_")
Parameters¶
name : str Basename of file without extension.
Returns¶
(str, str, str, float) plasmid, exp, rep, time (np.nan if not parsed).
Source code in scripts/step_1a_fit_upregulation.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
save_kd_plot ¶
save_kd_plot(df, t_half, out_pdf)
Save a KD plot with points (norm.bfp vs time) and fitted curve to a PDF.
Parameters¶
df : pd.DataFrame Subset for one plasmid with columns time, norm.bfp. t_half : float Fitted half-time to draw the curve. out_pdf : str Output PDF filename (basename only; saved under OUT_PATH).
Source code in scripts/step_1a_fit_upregulation.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |