API Reference
ovwt
read_feature_file(file_path)
Reads a feature file and returns a Polars DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
PathLike
|
Path to the feature file. Supported formats: .parquet, .pq, .csv. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: The feature data as a Polars DataFrame. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file extension is not supported. |
Source code in src/ovwt/__init__.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
get_feature_cols(df)
Returns the CellProfiler feature columns from a DataFrame.
Infers feature columns as those whose name starts with an uppercase letter and contains an underscore, matching CellProfiler naming conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame to extract feature column names from. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Column names identified as CellProfiler features. |
Source code in src/ovwt/__init__.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
filter_min_cells(data_df, label_col, wt_label, min_cells)
Remove variants (non-wildtype labels) with fewer than min_cells cells.
Wildtype rows are always retained regardless of count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_df
|
DataFrame
|
Input DataFrame containing a label column. |
required |
label_col
|
str
|
Name of the column holding class labels. |
required |
wt_label
|
str
|
The label value that identifies wildtype cells. |
required |
min_cells
|
int
|
Minimum number of cells a variant must have to be retained. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with under-represented variants removed. |
Source code in src/ovwt/__init__.py
290 291 292 293 294 295 296 297 298 299 300 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 | |
downsample_wildtype(data_df, label_col, wt_label, seed)
Downsample wildtype cells to the count of the largest non-wildtype variant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_df
|
DataFrame
|
Input DataFrame containing a label column. |
required |
label_col
|
str
|
Name of the column holding class labels. |
required |
wt_label
|
str
|
The label value that identifies wildtype cells. |
required |
seed
|
int
|
Random seed for reproducible sampling. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with wildtype rows downsampled. Non-wildtype rows are unchanged. Row order is not guaranteed. |
Source code in src/ovwt/__init__.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
train_test_val_split(data_df, cfg)
Splits the data into an 8:1:1 train/test/validation split.
The split is stratified based on the label column to ensure that the distribution of classes is preserved across the train, test, and validation sets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_df
|
DataFrame
|
The input data as a Polars DataFrame. |
required |
cfg
|
DictConfig
|
Hydra config. Uses cfg.app.label_col, cfg.app.seed, and
cfg.app.feature_cols. If cfg.app.feature_cols is None, feature
columns are inferred via |
required |
Returns:
| Type | Description |
|---|---|
tuple[DataFrame, DataFrame, DataFrame]
|
tuple[pl.DataFrame, pl.DataFrame, pl.DataFrame]: DataFrames for train, test, and validation sets respectively, each containing the feature columns and the label column. |
Source code in src/ovwt/__init__.py
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 358 359 360 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 | |
train_xgboost(train, val, cfg)
Trains an XGBoost classifier on the provided training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train
|
DataFrame
|
Training data including feature columns and the label column. |
required |
val
|
DataFrame
|
Validation data including feature columns and the label column. |
required |
cfg
|
DictConfig
|
Hydra config. Uses cfg.app.label_col, cfg.app.wt_label, and cfg.xgboost.num_boost_round, cfg.xgboost.early_stopping_rounds, cfg.xgboost.weigh_samples, and cfg.xgboost.params (passed directly to xgb.train, with objective, eval_metric, and seed added). |
required |
Returns:
| Type | Description |
|---|---|
Booster
|
xgb.Booster: The trained XGBoost booster. |
Source code in src/ovwt/__init__.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
test_xgboost(model, train, val, test, cfg)
Computes the train, validation, and test AUC and accuracy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Booster
|
The trained XGBoost booster to evaluate. |
required |
train
|
DataFrame
|
Training DataFrame including feature and label columns. |
required |
val
|
DataFrame
|
Validation DataFrame including feature and label columns. |
required |
test
|
DataFrame
|
Test DataFrame including feature and label columns. |
required |
cfg
|
DictConfig
|
Hydra config. Uses cfg.app.label_col and cfg.app.wt_label. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary with the keys: - "variant": The first non wt_label value in the label column. - "train_auroc": The AUC on the training set. - "train_accuracy": The accuracy on the training set. - "val_auroc": The AUC on the validation set. - "val_accuracy": The accuracy on the validation set. - "test_auroc": The AUC on the test set. - "test_accuracy": The accuracy on the test set. |
Source code in src/ovwt/__init__.py
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 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 | |
evaluate(df, model, label_col, wt_label)
Evaluates an XGBoost model on a dataset, returning AUROC and accuracy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Dataset including feature columns and the label column. |
required |
model
|
Booster
|
The trained XGBoost booster to evaluate. |
required |
label_col
|
str
|
The name of the label column. |
required |
wt_label
|
str
|
The label value corresponding to the wild-type (positive) class. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
tuple[float, float]: A tuple of (AUROC, accuracy), where accuracy is computed at a decision threshold of 0.5. |
Source code in src/ovwt/__init__.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
get_dmatrix(df, label_col, wt_label, weight=None)
Converts a Polars DataFrame into an XGBoost DMatrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing feature columns and the label column. |
required |
label_col
|
str
|
The name of the label column. |
required |
wt_label
|
str
|
The label value corresponding to the wild-type (positive) class. |
required |
weight
|
Optional[ndarray]
|
Sample weights. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
DMatrix
|
xgb.DMatrix: The XGBoost DMatrix with boolean labels. |
Source code in src/ovwt/__init__.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
convert_labels_to_boolean(labels, wt_label)
Converts an array of labels to boolean values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
ndarray
|
An array of labels to be converted. |
required |
wt_label
|
str
|
The label corresponding to the positive class (True). |
required |
Source code in src/ovwt/__init__.py
20 21 22 23 24 25 26 27 28 29 30 | |
configure_logging(log_file=None, level='INFO')
Configures root logger with a stdout handler and optional file handler.
No-ops if the root logger already has handlers (e.g. called twice).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_file
|
Optional[PathLike]
|
If provided, log messages are also written to this file. |
None
|
level
|
str
|
Logging level name (e.g. |
'INFO'
|
Source code in src/ovwt/__init__.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
log_config(cfg)
Logs the Hydra config at INFO level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DictConfig
|
The Hydra config to log. |
required |
Source code in src/ovwt/__init__.py
425 426 427 428 429 430 431 432 433 | |
profile_variant(v, train_all, test_all, val_all, cfg)
Train and evaluate an XGBoost classifier for a single variant vs. wild-type.
Filters each split to rows belonging to v or the wild-type label, trains
a model on the training split, and evaluates it on all three splits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
str
|
The variant label to profile. |
required |
train_all
|
DataFrame
|
Full training split (all variants and wild-type). |
required |
test_all
|
DataFrame
|
Full test split. |
required |
val_all
|
DataFrame
|
Full validation split. |
required |
cfg
|
DictConfig
|
Hydra config. Uses cfg.app.label_col, cfg.app.wt_label, and cfg.xgboost settings. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict, Booster]
|
tuple[dict, xgb.Booster]:
A result dict (as returned by |
Source code in src/ovwt/__init__.py
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 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
main(cfg)
Trains and evaluates one XGBoost classifier per variant vs. wild-type.
Performs a single stratified 8:1:1 train/test/val split on the full
dataset, then for each unique non-wild-type label trains an XGBoost model
on the rows belonging to that variant or the wild-type. Results are written
to results.csv and trained models are pickled to models.pkl in
out_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DictConfig
|
Hydra config with two groups: - cfg.app: feature_file, label_col, wt_label, out_dir - cfg.xgboost: XGBoost hyperparameters and training options |
required |
Source code in src/ovwt/__init__.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 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 | |