Models
Prioritization models for ML step.
Model Process: 1. Identify Positive Dataset - All representative pairs from parsimonious selection 2. Generate Negative Dataset - Random protein pairs that are not candidate pairs
ModelConfig
Configuration options for the ML prioritization step.
Source code in src/xlranker/ml/models.py
__init__(runs=10, folds=5, xgb_params=DEFAULT_XGB_PARAMS)
Config for the prioritization model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runs
|
int
|
the number of model runs. Defaults to 10. |
10
|
folds
|
int
|
number of folds per run. Defaults to 5. |
5
|
xgb_params
|
dict[str, Any]
|
dictionary of parameters for the XGBoost model. Defaults to DEFAULT_XGB_PARAMS. |
DEFAULT_XGB_PARAMS
|
Source code in src/xlranker/ml/models.py
validate()
Validate the parameters of the config.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if all parameters are the correct type and meet the minimum value requirements. |
Source code in src/xlranker/ml/models.py
PrioritizationModel
Prioritization model using XGBoost to predict which pair should be selected as the representative.
Raises:
Type | Description |
---|---|
ValueError
|
Raised if there aren't enough negatives and config.fragile is True. |
Source code in src/xlranker/ml/models.py
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 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 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
|
__init__(dataset, model_config=None, gmt_list=None, ppi_db=None, pair_selector=BestSelector(with_secondary=False))
Initialize PrioritizationModel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset
|
XLDataSet
|
XL data set that needs prioritization. Requires Parsimony Analysis to have been performed. |
required |
model_config
|
ModelConfig | None
|
Config for the model. If None use defaults. Defaults to None. |
None
|
gmt_list
|
list[list[set[str]]] | None
|
list of exclusive sets. Negative pairs can't be in the same set. Defaults to None. |
None
|
ppi_db
|
DataFrame | None
|
PPI database. Should have two columns P1 and P2, where P1 is first alphabetically. Defaults to None. |
None
|
pair_selector
|
(PairSelector, optional)
|
Pair selector |
BestSelector(with_secondary=False)
|
Source code in src/xlranker/ml/models.py
construct_df_from_pairs(pair_list, has_label, label_value=0.0)
Construct a DataFrame from the list of Protein Pairs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pair_list
|
list[ProteinPair]
|
list of protein pairs to get the dataframe from |
required |
has_label
|
bool
|
if True, adds label column to dataframe |
required |
label_value
|
float
|
value assigned to the label column. Defaults to 0.0 (negative). |
0.0
|
Returns:
Type | Description |
---|---|
DataFrame
|
pl.DataFrame: DataFrame object with the first column being the pair ID, following columns with abundances for the proteins. If |
Source code in src/xlranker/ml/models.py
construct_predict_df()
Construct the data frame for pairs that need predictions.
Returns:
Type | Description |
---|---|
DataFrame
|
pl.DataFrame: Polars DataFrame of the protein pairs needing prediction. |
Source code in src/xlranker/ml/models.py
construct_training_df(negative_pairs)
Generate a Polars DataFrame from the positive pairs and a list of negative ProteinPair.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
negative_pairs
|
list[ProteinPair]
|
the list of negative pairs to add to DataFrame |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pl.DataFrame: DataFrame where the first column is 'pair', followed by abundances. Last column is 'label' |
Source code in src/xlranker/ml/models.py
get_negatives(n)
Get a list of negative protein pairs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
the number of pairs to generate |
required |
Raises:
Type | Description |
---|---|
ValueError
|
Raised if the value of |
Returns:
Type | Description |
---|---|
list[ProteinPair]
|
list[ProteinPair]: list of negative protein pairs |
Source code in src/xlranker/ml/models.py
get_selected()
Get all ProteinPair
s that were accepted.
Returns:
Type | Description |
---|---|
list[ProteinPair]
|
list[ProteinPair]: All machine-learning selected pairs predicted by this model |
Source code in src/xlranker/ml/models.py
get_selections()
Get the best pair for each protein pair subgroup.
Returns:
Type | Description |
---|---|
list[ProteinPair]
|
list[ProteinPair]: list of the protein pairs that were accepted |
Source code in src/xlranker/ml/models.py
is_intra(a, b)
Determine if a and b are intra pairs and represent as float.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
str
|
name of protein a |
required |
b
|
str
|
name of protein b |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
1.0 if a and b have same name, else returns 0.0 |
Source code in src/xlranker/ml/models.py
is_ppi(a, b)
Determine if protein a and protein b has a known ppi in ppi_db.
Order of a
and b
does not matter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
str
|
First protein |
required |
b
|
str
|
Second protein |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Return float with 1.0 meaning there is a known ppi in the db |
Source code in src/xlranker/ml/models.py
run_model()
Run the model and get predictions for all protein pairs.
Source code in src/xlranker/ml/models.py
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 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 408 409 410 411 412 413 414 |
|
save_model(file_path)
Save the model using the official XGBoost method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
path to save model to. |
required |
in_same_set(a, b, sets)
Check if a and b are located in the same set in any of the exclusive sets provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
str
|
entity a |
required |
b
|
str
|
entity b |
required |
sets
|
list[list[set[str]]]
|
list of gmts, which are lists of sets |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if a and b both located in at least one set |