CLI¶
cli
¶
__version__ = '0.1.0'
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
LOG_MAPPING = {'DEBUG': logging.DEBUG, 'INFO': logging.INFO, 'WARNING': logging.WARNING, 'ERROR': logging.ERROR, 'CRITICAL': logging.CRITICAL}
module-attribute
¶
Pipeline(config)
¶
Main pipeline class for optiMHC, encapsulating the full data processing workflow.
This class orchestrates input parsing, feature generation, rescoring, result saving, and visualization. It supports both single-run and experiment modes (multiple feature/model combinations).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str, dict, or Config
|
Path to YAML config, dict, or Config object. |
required |
Examples:
Initialize the pipeline with a configuration file, dict, or Config object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str, dict, or Config
|
Path to YAML config, dict, or Config object. |
required |
Source code in optimhc/core/pipeline.py
read_input()
¶
Read input PSMs based on configuration.
Returns:
| Type | Description |
|---|---|
PsmContainer
|
Object containing loaded PSMs. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input type is unsupported. |
Exception
|
If file reading fails. |
Source code in optimhc/core/pipeline.py
rescore(psms, model_type=None, n_jobs=None, test_fdr=None, rescoring_features=None)
¶
Perform rescoring on the PSMs using the specified or configured model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psms
|
PsmContainer
|
PSM container object. |
required |
model_type
|
str
|
Model type ('XGBoost', 'RandomForest', 'Percolator'). |
None
|
n_jobs
|
int
|
Number of parallel jobs. |
None
|
test_fdr
|
float
|
FDR threshold. List of features to use for rescoring. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
results |
Results
|
Rescoring results. |
models |
list
|
Trained models. |
Notes
Rescoring logic is adapted from mokapot (https://mokapot.readthedocs.io/)
Source code in optimhc/core/pipeline.py
save_results(psms, results, models, output_dir=None, file_root='optimhc')
¶
Save rescoring results, PSM data, and trained models to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psms
|
PsmContainer
|
PSM container object. |
required |
results
|
Results
|
Rescoring results. |
required |
models
|
list
|
Trained models. |
required |
output_dir
|
str
|
Output directory. |
None
|
file_root
|
str
|
Root name for output files. |
'optimhc'
|
Source code in optimhc/core/pipeline.py
visualize_results(psms, results, models, output_dir=None, sources=None)
¶
Generate and save visualizations for the analysis results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psms
|
PsmContainer
|
PSM container object. |
required |
results
|
Results
|
Rescoring results. |
required |
models
|
list
|
Trained models. |
required |
output_dir
|
str
|
Output directory. |
None
|
sources
|
list
|
Feature sources to include in visualizations. |
None
|
Source code in optimhc/core/pipeline.py
run()
¶
Run the complete optiMHC pipeline (single run mode).
This method executes the full workflow: input parsing, feature generation, rescoring, saving, and visualization.
Returns:
| Name | Type | Description |
|---|---|---|
psms |
PsmContainer
|
PSM container object. |
results |
Results
|
Rescoring results. |
models |
list
|
Trained models. |
Source code in optimhc/core/pipeline.py
run_experiments()
¶
Run experiments with different feature/model combinations using multiprocessing.
Each experiment is executed in its own process for complete resource isolation. The experiment configurations must be provided in the config under the 'experiments' key.
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in optimhc/core/pipeline.py
Config(config_source=None)
¶
Configuration manager for optiMHC pipeline.
This class handles loading, validating, and providing access to configuration parameters from YAML files or dictionaries. It implements a fail-fast validation strategy to ensure configuration correctness before pipeline execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_source
|
str or dict or None
|
Path to YAML file, dictionary with configuration, or None for default config. If None, uses DEFAULT_CONFIG. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
_config |
dict
|
The internal configuration dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If configuration is invalid or required parameters are missing. |
FileNotFoundError
|
If specified YAML file does not exist. |
YAMLError
|
If YAML file is malformed. |
Examples:
>>> # Load from dictionary
>>> config_dict = {
... "inputType": "pepxml",
... "inputFile": ["data.pep.xml"],
... "outputDir": "./results",
... "rescore": {"testFDR": 0.01, "model": "Percolator"}
... }
>>> config = Config(config_dict)
>>> # Access configuration values
>>> input_type = config["inputType"]
>>> output_dir = config.get("outputDir", "./default")
Initialize Config from a YAML file path or a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_source
|
str or dict or None
|
Path to YAML file, dictionary with configuration, or None for default config. If None, uses DEFAULT_CONFIG. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If config_source is neither a string, dict, nor None. |
FileNotFoundError
|
If specified YAML file does not exist. |
YAMLError
|
If YAML file is malformed. |
Source code in optimhc/core/config.py
validate()
¶
Validate the configuration using a fail-fast strategy.
This method performs comprehensive validation of the configuration, including required fields, data types, file existence, and feature generator configurations.
Raises:
| Type | Description |
|---|---|
ValueError
|
If any validation check fails. The error message will indicate the specific validation failure. |
Notes
The validation includes checks for: - Required fields (inputType, inputFile, outputDir, rescore) - Input file existence and type - Output directory creation - Rescore configuration validity (TODO) - Feature generator configuration primitive validity (TODO) - Optional parameter validity (TODO): we should validate 'allele' first !!!
Source code in optimhc/core/config.py
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 | |
setup_logging(level='INFO')
¶
Source code in optimhc/cli.py
cli()
¶
pipeline(config, inputtype, inputfile, decoyprefix, outputdir, visualization, numprocesses, allele, featuregenerator, loglevel, testfdr, model)
¶
Run the optiMHC pipeline with the specified configuration.
Source code in optimhc/cli.py
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 | |
experiment(config)
¶
Run multiple experiments with different feature combinations.