interface¶
The main interface module provides the core workflow functions and command-line interface components for tfbpmodeling.
tfbpmodeling.interface ¶
CustomHelpFormatter ¶
Bases: HelpFormatter
This could be used to customize the help message formatting for the argparse parser.
Left as a placeholder.
common_modeling_input_arguments ¶
common_modeling_input_arguments(parser, top_n_default=600)
Add common input arguments for modeling commands.
Source code in tfbpmodeling/interface.py
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 489 490 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 | |
linear_perturbation_binding_modeling ¶
linear_perturbation_binding_modeling(args)
| Parameters: |
|
|---|
Source code in tfbpmodeling/interface.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 114 115 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 144 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 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 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 231 232 233 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 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 288 289 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 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 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
Overview¶
The interface module serves as the primary entry point for the tfbpmodeling workflow. It contains:
- Main workflow function:
linear_perturbation_binding_modeling() - CLI helper functions: Argument parsing utilities for the command-line interface
- Custom formatters: Enhanced help formatting for better user experience
Main Functions¶
linear_perturbation_binding_modeling¶
The core function that executes the complete 4-stage TFBP modeling workflow:
- Data Preprocessing: Load and validate input files, handle missing data
- Bootstrap Modeling: All-data analysis with bootstrap resampling and LassoCV
- Top-N Modeling: Refined analysis on significant predictors from top-performing data
- Interactor Significance: Statistical evaluation of interaction terms vs main effects
Parameters: Command-line arguments object containing all configuration options
Returns: None (results saved to output directory)
Key Features: - Comprehensive input validation - Automatic output directory creation with timestamps - Detailed logging of all processing steps - Error handling with informative messages
CLI Helper Functions¶
common_modeling_input_arguments¶
Adds standard input arguments to argument parsers: - File paths for response and predictor data - Perturbed TF specification - Bootstrap and sampling parameters
common_modeling_feature_options¶
Configures feature engineering options: - Polynomial terms (squared, cubic) - Row maximum inclusion - Custom variable additions and exclusions
common_modeling_binning_arguments¶
Sets up data stratification parameters: - Bin edge specifications - Stratification methods
add_general_arguments_to_subparsers¶
Propagates global arguments to subcommand parsers: - Logging configuration - System-wide options
Data Flow¶
Usage Examples¶
Programmatic Usage¶
import argparse
from tfbpmodeling.interface import linear_perturbation_binding_modeling
# Create arguments object
args = argparse.Namespace(
response_file='data/expression.csv',
predictors_file='data/binding.csv',
perturbed_tf='YPD1',
n_bootstraps=1000,
top_n=600,
all_data_ci_level=98.0,
topn_ci_level=90.0,
max_iter=10000,
output_dir='./results',
output_suffix='',
n_cpus=4,
# ... other parameters
)
# Run analysis
linear_perturbation_binding_modeling(args)
Custom Argument Parser¶
import argparse
from tfbpmodeling.interface import (
common_modeling_input_arguments,
common_modeling_feature_options,
CustomHelpFormatter
)
# Create custom parser
parser = argparse.ArgumentParser(
formatter_class=CustomHelpFormatter,
description="Custom TFBP Analysis"
)
# Add standard arguments
input_group = parser.add_argument_group("Input")
common_modeling_input_arguments(input_group)
feature_group = parser.add_argument_group("Features")
common_modeling_feature_options(feature_group)
# Parse and use
args = parser.parse_args()
linear_perturbation_binding_modeling(args)
Error Handling¶
The interface module includes comprehensive error handling:
Input Validation Errors¶
# File existence checks
FileNotFoundError: "File data/missing.csv does not exist."
# Parameter validation
ValueError: "The `max_iter` parameter must be a positive integer."
# Data format validation
ValueError: "Perturbed TF 'INVALID' not found in response file columns"
Runtime Errors¶
# Convergence issues
RuntimeWarning: "LassoCV failed to converge for 15/1000 bootstrap samples"
# Insufficient data
ValueError: "Insufficient data after filtering. Found 5 samples, minimum required: 10"
Configuration Options¶
The interface supports extensive configuration through command-line arguments:
Core Parameters¶
- Input files: Response data, predictor data, optional blacklist
- TF specification: Name of perturbed transcription factor
- Bootstrap settings: Sample count, random seed, weight normalization
Feature Engineering¶
- Polynomial terms: Squared and cubic pTF terms
- Additional predictors: Row max, custom variables
- Interaction control: Variable exclusions, main effects
Model Configuration¶
- Confidence intervals: Separate thresholds for each stage
- Convergence: Maximum iterations, dropout options
- Performance: CPU cores, memory management
Output Control¶
- Directory structure: Base directory, custom suffixes
- Logging: Verbosity levels, file vs console output
Performance Considerations¶
Memory Management¶
- Bootstrap samples stored efficiently using sparse representations
- Automatic garbage collection between stages
- Memory usage monitoring and warnings
Parallel Processing¶
- LassoCV uses specified CPU cores for cross-validation
- Bootstrap samples processed in batches
- I/O operations optimized for large datasets
Runtime Optimization¶
- Early stopping for non-convergent models
- Adaptive batch sizing based on available memory
- Progress reporting for long-running analyses
Related Modules¶
- modeling_input_data: Core data structures
- bootstrapped_input_data: Bootstrap resampling
- bootstrap_model_results: Result aggregation
- evaluate_interactor_significance_lassocv: LassoCV-based significance testing
- evaluate_interactor_significance_linear: Linear regression-based significance testing