Core classes (Mint, Chromatogram)¶
Main module of the ms-mint library.
Mint
¶
Main class of the ms_mint package for processing metabolomics files.
This class provides the primary interface for extracting, processing, and analyzing mass spectrometry data for metabolomics analysis.
Attributes:
Name | Type | Description |
---|---|---|
verbose |
Controls the verbosity level of the instance. |
|
version |
str
|
The version of the ms_mint package being used. |
progress_callback |
Function to update progress information. |
|
plot |
Instance of MintPlotter for visualization. |
|
opt |
Instance of TargetOptimizer for target optimization. |
|
pca |
Instance of PrincipalComponentsAnalyser for PCA analysis. |
|
tqdm |
Progress bar utility. |
|
wdir |
Working directory for input/output operations. |
|
status |
str
|
Current status of processing ('waiting', 'running', 'done'). |
ms_files |
List[str]
|
List of MS files to be processed. |
n_files |
int
|
Number of MS files currently loaded. |
targets |
DataFrame
|
DataFrame with target compounds information. |
results |
DataFrame
|
DataFrame with analysis results. |
progress |
float
|
Current progress of processing (0-100). |
Source code in src/ms_mint/Mint.py
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 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 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 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 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 |
|
ms_files: List[str]
property
writable
¶
Get list of MS files to process.
Returns:
Type | Description |
---|---|
List[str]
|
List of filenames. |
n_files: int
property
¶
Get number of currently stored MS filenames.
Returns:
Type | Description |
---|---|
int
|
Number of files stored in self.ms_files |
peak_labels: List[str]
property
¶
Get list of peak labels from targets.
Returns:
Type | Description |
---|---|
List[str]
|
List of peak label strings. |
progress: float
property
writable
¶
Get current progress value.
Returns:
Type | Description |
---|---|
float
|
Current progress value (0-100). |
results: pd.DataFrame
property
writable
¶
Get results DataFrame.
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame containing analysis results. |
status: str
property
¶
Get current status of Mint instance.
Returns:
Type | Description |
---|---|
str
|
Status string, one of: 'waiting', 'running', 'done' |
targets: pd.DataFrame
property
writable
¶
Get target list.
Returns:
Type | Description |
---|---|
DataFrame
|
Target list DataFrame. |
version: str
property
¶
Get the ms-mint version number.
Returns:
Type | Description |
---|---|
str
|
Version string. |
__init__(verbose=False, progress_callback=None, time_unit='s', wdir=None)
¶
Initialize a Mint instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
verbose |
bool
|
Sets verbosity of the instance. |
False
|
progress_callback |
Optional[Callable[[float], None]]
|
A callback function for reporting progress (0-100). |
None
|
time_unit |
str
|
Unit for time measurements. |
's'
|
wdir |
Optional[Union[str, Path]]
|
Working directory. If None, uses current directory. |
None
|
Source code in src/ms_mint/Mint.py
clear_ms_files()
¶
clear_results()
¶
clear_targets()
¶
crosstab(var_name=None, index=None, column=None, aggfunc='mean', apply=None, scaler=None, groupby=None)
¶
Create condensed representation of the results.
Creates a cross-table with filenames as index and target labels as columns. The values in the cells are determined by var_name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_name |
Optional[str]
|
Name of the column from results table for cell values. Defaults to 'peak_area_top3'. |
None
|
index |
Optional[Union[str, List[str]]]
|
Column(s) to use as index in the resulting cross-tabulation. Defaults to 'ms_file_label'. |
None
|
column |
Optional[str]
|
Column to use as columns in the resulting cross-tabulation. Defaults to 'peak_label'. |
None
|
aggfunc |
str
|
Aggregation function for aggregating values. Defaults to 'mean'. |
'mean'
|
apply |
Optional[Callable]
|
Function to apply to the resulting cross-tabulation. Options include 'log2p1', 'logp1', or a custom function. |
None
|
scaler |
Optional[Union[str, Any]]
|
Function or name of scaler to scale the data. Options include 'standard', 'robust', 'minmax', or a scikit-learn scaler. |
None
|
groupby |
Optional[Union[str, List[str]]]
|
Column(s) to group data before scaling. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame representing the cross-tabulation. |
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported scaler is specified. |
Source code in src/ms_mint/Mint.py
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 528 529 530 531 532 533 534 535 536 537 538 539 540 |
|
digest_results()
¶
Extract MS files and targets from results and set them in the instance.
export(fn=None)
¶
Export current results to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
Optional[str]
|
Filename to export to. If None, returns file buffer. Supported formats: .xlsx, .csv, .parquet |
None
|
Returns:
Type | Description |
---|---|
Optional[BytesIO]
|
BytesIO buffer if fn is None, otherwise None. |
Source code in src/ms_mint/Mint.py
get_chromatograms(fns=None, peak_labels=None, filters=None, **kwargs)
¶
Get chromatograms for specified files and peak labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fns |
Optional[List[str]]
|
List of filenames to extract chromatograms from. Defaults to all MS files. |
None
|
peak_labels |
Optional[List[str]]
|
List of peak labels to extract. Defaults to all peak labels. |
None
|
filters |
Optional[List[Any]]
|
List of filters to apply to the chromatograms. |
None
|
**kwargs |
Additional arguments to pass to the Chromatogram constructor. |
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame containing chromatogram data. |
Source code in src/ms_mint/Mint.py
get_target_params(peak_label)
¶
Get target parameters for a specific peak label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
peak_label |
str
|
Label of the target peak. |
required |
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float]
|
Tuple of (mz_mean, mz_width, rt_min, rt_max). |
Source code in src/ms_mint/Mint.py
load(fn)
¶
Load results into Mint instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
Union[str, BytesIO]
|
Filename (csv, xlsx, parquet) or file-like object. |
required |
Returns:
Type | Description |
---|---|
Mint
|
Self for method chaining. |
Source code in src/ms_mint/Mint.py
load_files(obj)
¶
Load MS files and return self for chaining.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Union[str, List[str]]
|
Filename pattern (for glob) or list of file names. |
required |
Returns:
Type | Description |
---|---|
Mint
|
Self for method chaining. |
Source code in src/ms_mint/Mint.py
load_metadata(fn=None)
¶
Load metadata from file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
Optional[Union[str, Path]]
|
Filename to load metadata from. Defaults to metadata.parquet in working directory. |
None
|
Returns:
Type | Description |
---|---|
Mint
|
Self for method chaining. |
Source code in src/ms_mint/Mint.py
load_targets(list_of_files)
¶
Load targets from file(s) (csv, xlsx).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list_of_files |
Union[str, Path, List[Union[str, Path]]]
|
Filename or list of file names. |
required |
Returns:
Type | Description |
---|---|
Mint
|
Self for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If input is not a list of files. |
AssertionError
|
If a file is not found. |
Source code in src/ms_mint/Mint.py
reset()
¶
Reset Mint instance by removing targets, MS-files and results.
Returns:
Type | Description |
---|---|
Mint
|
Self for method chaining. |
Source code in src/ms_mint/Mint.py
run(nthreads=None, rt_margin=0.5, mode='standard', fn=None, **kwargs)
¶
Run MINT and process MS-files with current target list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nthreads |
Optional[int]
|
Number of cores to use. Options: * None - Run with min(n_cpus, n_files) CPUs * 1: Run without multiprocessing on one CPU * >1: Run with multiprocessing using specified threads |
None
|
rt_margin |
float
|
Margin to add to rt values when rt_min/rt_max not specified. |
0.5
|
mode |
str
|
Compute mode, one of: * 'standard': calculates peak shapes projected to RT dimension * 'express': omits calculation of other features, only peak_areas |
'standard'
|
fn |
Optional[str]
|
Output filename to save results directly to disk instead of memory. |
None
|
**kwargs |
Additional arguments passed to the processing function. |
{}
|
Returns:
Type | Description |
---|---|
Optional[Mint]
|
Self for method chaining, or None if no files or targets loaded. |
Source code in src/ms_mint/Mint.py
save_metadata(fn=None)
¶
Save metadata to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
Optional[Union[str, Path]]
|
Filename to save metadata to. Defaults to metadata.parquet in working directory. |
None
|
Returns:
Type | Description |
---|---|
Mint
|
Self for method chaining. |
Source code in src/ms_mint/Mint.py
options: show_root_heading: true show_root_full_path: true show_submodules: true members_order: source
Experimental module to run Mint interactively inside the Jupyter notebook.
Mint
¶
Bases: Mint
Interactive MINT for Jupyter Notebook environment (experimental).
This class extends the base Mint class with interactive widgets and controls for use in Jupyter notebooks, allowing for a graphical user interface to manage MS files, target lists, and process data.
Attributes:
Name | Type | Description |
---|---|---|
progress_callback |
Function to update progress bar. |
|
ms_storage_path |
File chooser widget for MS file directory. |
|
target_files_button |
Upload widget for target files. |
|
load_ms_button |
Button to load MS files from selected directory. |
|
message_box |
Text area for displaying messages. |
|
run_button |
Button to start processing. |
|
download_button |
Button to export results. |
|
progress_bar |
Progress indicator for processing. |
|
layout |
Main container for all widgets. |
Source code in src/ms_mint/notebook.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 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 |
|
messages: List[str]
property
¶
Get the list of messages displayed in the message box.
Returns:
Type | Description |
---|---|
List[str]
|
List of messages. |
__init__(*args, **kwargs)
¶
Initialize the interactive Mint instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
Any
|
Positional arguments passed to the parent Mint class. |
()
|
**kwargs |
Any
|
Keyword arguments passed to the parent Mint class. |
{}
|
Source code in src/ms_mint/notebook.py
display()
¶
Display control elements in Jupyter notebook.
Returns:
Type | Description |
---|---|
VBox
|
The main widget layout container. |
options: show_root_heading: true show_root_full_path: true show_submodules: true members_order: source
ms_mint.MintPlotter
¶
MintPlotter
¶
Plot generator for visualizing MS-MINT analysis results.
This class provides various visualization methods for metabolomics data processed by MS-MINT, including heatmaps, chromatograms, peak shapes, and 2D histograms.
Attributes:
Name | Type | Description |
---|---|---|
mint |
The Mint instance containing data to be visualized. |
Source code in src/ms_mint/MintPlotter.py
27 28 29 30 31 32 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 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 |
|
__init__(mint)
¶
Initialize the MintPlotter with a Mint instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mint |
'ms_mint.Mint.Mint'
|
Mint instance containing the data to visualize. |
required |
hierarchical_clustering(data=None, peak_labels=None, ms_files=None, title=None, figsize=(8, 8), targets_var=None, var_name='peak_max', vmin=-3, vmax=3, xmaxticks=None, ymaxticks=None, apply='log2p1', metric='cosine', scaler='standard', groupby=None, transposed=False, **kwargs)
¶
Perform hierarchical clustering and plot a heatmap.
If no data is provided, data is taken from self.mint.crosstab(var_name).
The clustered non-transformed non-scaled data is stored in self.mint.clustered
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Optional[DataFrame]
|
DataFrame with data to be used for clustering. If None, crosstab of mint instance is used. |
None
|
peak_labels |
Optional[List[str]]
|
List of peak labels to include in the analysis. |
None
|
ms_files |
Optional[List[str]]
|
List of MS files to include in the analysis. |
None
|
title |
Optional[str]
|
Title for the plot. |
None
|
figsize |
Tuple[int, int]
|
Tuple of (width, height) in inches for the figure. |
(8, 8)
|
targets_var |
Optional[str]
|
Deprecated, use var_name instead. |
None
|
var_name |
str
|
Name of the column from data to be used for cell values in the heatmap. |
'peak_max'
|
vmin |
int
|
Minimum value for color scaling. |
-3
|
vmax |
int
|
Maximum value for color scaling. |
3
|
xmaxticks |
Optional[int]
|
Maximum number of ticks on x-axis. |
None
|
ymaxticks |
Optional[int]
|
Maximum number of ticks on y-axis. |
None
|
apply |
str
|
Transformation to be applied on the data. Can be "log1p", "log2p1", "log10p1" or None. |
'log2p1'
|
metric |
str
|
The distance metric to use for the tree. Can be any metric supported by scipy.spatial.distance.pdist. |
'cosine'
|
scaler |
str
|
Method to scale data along both axes. Can be "standard", "robust" or None. |
'standard'
|
groupby |
Optional[str]
|
Name of the column to group data before scaling. If None, scaling is applied to the whole data, not group-wise. |
None
|
transposed |
bool
|
Whether to transpose the figure or not. |
False
|
**kwargs |
Additional keyword arguments passed to hierarchical_clustering. |
{}
|
Returns:
Type | Description |
---|---|
Figure
|
Matplotlib figure representing the clustered heatmap. |
Source code in src/ms_mint/MintPlotter.py
peak_shapes(fns=None, peak_labels=None, interactive=False, **kwargs)
¶
Plot peak shapes extracted from MS-MINT results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fns |
Optional[Union[str, List[str]]]
|
Filename(s) to include in the plot. If None, all files in results are used. |
None
|
peak_labels |
Optional[Union[str, List[str]]]
|
Peak label(s) to include in the plot. If None, all peaks are used. |
None
|
interactive |
bool
|
If True, returns an interactive Plotly figure instead of a static Matplotlib figure. |
False
|
**kwargs |
Additional keyword arguments passed to the underlying plotting functions. |
{}
|
Returns:
Type | Description |
---|---|
Union[FacetGrid, Figure]
|
Either a seaborn FacetGrid or a Plotly figure depending on the 'interactive' parameter. |
Source code in src/ms_mint/MintPlotter.py
heatmap(col_name='peak_max', normed_by_cols=True, transposed=False, clustered=False, add_dendrogram=False, name='', correlation=False, **kwargs)
¶
Create an interactive heatmap to explore the data.
Calls mint.crosstab() and then visualizes the result using plotly_heatmap.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
col_name |
str
|
Name of the column in mint.results to be analyzed. |
'peak_max'
|
normed_by_cols |
bool
|
Whether or not to normalize the columns in the crosstab. |
True
|
transposed |
bool
|
If True, transpose matrix before plotting. |
False
|
clustered |
bool
|
Whether or not to cluster the rows. |
False
|
add_dendrogram |
bool
|
Whether or not to replace row labels with a dendrogram. |
False
|
name |
str
|
Label to use for the colorbar. |
''
|
correlation |
bool
|
If True, convert data to correlation matrix before plotting. |
False
|
**kwargs |
Additional keyword arguments passed to plotly_heatmap. |
{}
|
Returns:
Type | Description |
---|---|
Optional[Figure]
|
Interactive Plotly heatmap figure, or None if no results are available. |
Source code in src/ms_mint/MintPlotter.py
histogram_2d(fn, peak_label=None, rt_margin=0, mz_margin=0, **kwargs)
¶
Create a 2D histogram of an MS file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
str
|
File name of the MS file to visualize. |
required |
peak_label |
Optional[str]
|
Target to focus. If provided, the plot will highlight the region defined by the target parameters. |
None
|
rt_margin |
float
|
Margin in retention time dimension to add around the target region. |
0
|
mz_margin |
float
|
Margin in m/z dimension to add around the target region. |
0
|
**kwargs |
Additional keyword arguments passed to plot_metabolomics_hist2d. |
{}
|
Returns:
Type | Description |
---|---|
Figure
|
Matplotlib Figure containing the 2D histogram. |
Source code in src/ms_mint/MintPlotter.py
chromatogram(fns=None, peak_labels=None, interactive=False, filters=None, ax=None, **kwargs)
¶
Plot chromatograms extracted from one or more files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fns |
Optional[Union[str, List[str]]]
|
File name(s) to extract chromatograms from. If None, all files are used. |
None
|
peak_labels |
Optional[Union[str, List[str]]]
|
Target(s) from Mint.targets.peak_label to use for extraction parameters. If None, all targets are used. |
None
|
interactive |
bool
|
If True, returns an interactive Plotly figure instead of a static Matplotlib figure. |
False
|
filters |
Optional[List[Any]]
|
List of filters to apply to the chromatograms before plotting. |
None
|
ax |
Optional[Axes]
|
Matplotlib axes to plot on. If None, a new figure is created. |
None
|
**kwargs |
Additional keyword arguments passed to the underlying plotting functions. |
{}
|
Returns:
Type | Description |
---|---|
Union[FacetGrid, AxesBase, Figure]
|
Either a seaborn FacetGrid, a single Axes, or a Plotly figure depending on |
Union[FacetGrid, AxesBase, Figure]
|
the 'interactive' parameter and whether an 'ax' is provided. |
Source code in src/ms_mint/MintPlotter.py
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 |
|
ms_mint.TargetOptimizer
¶
TargetOptimizer
¶
Optimizer for MS-MINT target lists.
This class provides methods to optimize retention time parameters in target lists based on actual data from MS files.
Attributes:
Name | Type | Description |
---|---|---|
mint |
Mint instance to optimize. |
|
results |
Results of the most recent optimization. |
Source code in src/ms_mint/TargetOptimizer.py
21 22 23 24 25 26 27 28 29 30 31 32 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 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 |
|
__init__(mint=None)
¶
Initialize a TargetOptimizer instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mint |
Optional['ms_mint.Mint.Mint']
|
Mint instance to optimize. |
None
|
reset()
¶
Reset the optimizer results.
Returns:
Type | Description |
---|---|
'TargetOptimizer'
|
Self for method chaining. |
rt_min_max(fns=None, targets=None, peak_labels=None, minimum_intensity=10000.0, plot=False, sigma=20, filters=None, post_opt=False, post_opt_kwargs=None, rel_height=0.9, height=3, aspect=2, col_wrap=3, **kwargs)
¶
Optimize rt_min and rt_max values based on expected retention times.
For this optimization all rt values in the target list must be present. This method analyzes chromatograms to find peaks around expected retention times and sets optimal rt_min and rt_max values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fns |
Optional[List[Union[str, Path]]]
|
List of filenames to use for optimization. If None, uses all files in mint. |
None
|
targets |
Optional[DataFrame]
|
Target list to optimize. If None, uses mint.targets. |
None
|
peak_labels |
Optional[List[str]]
|
Subset of peak_labels to optimize. If None, optimizes all targets. |
None
|
minimum_intensity |
float
|
Minimum intensity required, otherwise skip target. |
10000.0
|
plot |
bool
|
Whether to plot optimizations (up to 1000 plots). |
False
|
sigma |
float
|
Sigma value for peak selection (Gaussian weighting parameter). |
20
|
filters |
Optional[List[Any]]
|
Filter instances to apply in respective order. |
None
|
post_opt |
bool
|
Whether to optimize retention times after peak selection. |
False
|
post_opt_kwargs |
Optional[Dict[str, Any]]
|
Parameters for post-optimization. |
None
|
rel_height |
float
|
Relative height for peak width determination. |
0.9
|
height |
int
|
Height of each subplot in inches. |
3
|
aspect |
int
|
Width-to-height ratio of each subplot. |
2
|
col_wrap |
int
|
Maximum number of columns in the plot. |
3
|
**kwargs |
Additional parameters passed to find_peaks method. |
{}
|
Returns:
Type | Description |
---|---|
Union[Tuple['ms_mint.Mint.Mint', Figure], 'ms_mint.Mint.Mint']
|
If plot=True, returns a tuple of (mint instance, matplotlib figure). |
Union[Tuple['ms_mint.Mint.Mint', Figure], 'ms_mint.Mint.Mint']
|
If plot=False, returns only the mint instance. |
Source code in src/ms_mint/TargetOptimizer.py
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 |
|
detect_largest_peak_rt(fns=None, targets=None, peak_labels=None, minimum_intensity=10000.0, plot=False, height=3, aspect=2, col_wrap=3, **kwargs)
¶
Detect the largest peak and set the RT value (not RT_min and RT_max).
Uses a simple maximum intensity approach rather than complex peak detection to find the retention time of the most intense peak for each target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fns |
Optional[List[Union[str, Path]]]
|
List of filenames to use for peak detection. If None, uses all files in mint. |
None
|
targets |
Optional[DataFrame]
|
Target list to update. If None, uses mint.targets. |
None
|
peak_labels |
Optional[List[str]]
|
Subset of peak_labels to update. If None, updates all targets. |
None
|
minimum_intensity |
float
|
Minimum intensity required, otherwise skip target. |
10000.0
|
plot |
bool
|
Whether to plot results (up to 100 plots). |
False
|
height |
int
|
Height of each subplot in inches. |
3
|
aspect |
int
|
Width-to-height ratio of each subplot. |
2
|
col_wrap |
int
|
Maximum number of columns in the plot. |
3
|
**kwargs |
Additional parameters (not used but accepted for compatibility). |
{}
|
Returns:
Type | Description |
---|---|
Union[Tuple['ms_mint.Mint.Mint', Figure], 'ms_mint.Mint.Mint']
|
If plot=True, returns a tuple of (mint instance, matplotlib figure). |
Union[Tuple['ms_mint.Mint.Mint', Figure], 'ms_mint.Mint.Mint']
|
If plot=False, returns only the mint instance. |
Source code in src/ms_mint/TargetOptimizer.py
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 |
|
ms_mint.Chromatogram
¶
Chromatogram
¶
A class for handling chromatogram data extraction and processing.
This class provides functionality to extract, process, and analyze chromatogram data from mass spectrometry files, including peak detection and visualization capabilities.
Attributes:
Name | Type | Description |
---|---|---|
t |
ndarray
|
Array of scan times. |
x |
ndarray
|
Array of intensity values. |
noise_level |
Optional[float]
|
Estimated noise level of the chromatogram. |
filters |
List[Filter]
|
List of filters to be applied to the chromatogram. |
peaks |
Optional[DataFrame]
|
DataFrame containing detected peaks information. |
selected_peak_ndxs |
Optional[List[int]]
|
Indices of selected peaks. |
expected_rt |
Optional[float]
|
Expected retention time. |
weights |
Optional[ndarray]
|
Weighting values for peak selection. |
Source code in src/ms_mint/Chromatogram.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 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 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 |
|
selected_peaks: pd.DataFrame
property
¶
Get DataFrame of the currently selected peaks.
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame containing information about the selected peaks. |
data: pd.DataFrame
property
¶
Get chromatogram data as a DataFrame.
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame with scan times as index and intensity as a column. |
__init__(scan_times=None, intensities=None, filters=None, expected_rt=None)
¶
Initialize a Chromatogram object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scan_times |
Optional[Union[List[float], ndarray]]
|
Array-like object containing the scan times. |
None
|
intensities |
Optional[Union[List[float], ndarray]]
|
Array-like object containing the intensities. |
None
|
filters |
Optional[List[Filter]]
|
List of filters to be applied. |
None
|
expected_rt |
Optional[float]
|
Expected retention time in seconds. |
None
|
Source code in src/ms_mint/Chromatogram.py
from_file(fn, mz_mean, mz_width=10, expected_rt=None)
¶
Load chromatogram data from a mass spectrometry file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
str
|
Filename of the mass spectrometry file. |
required |
mz_mean |
float
|
Mean m/z value to extract. |
required |
mz_width |
float
|
Width of the m/z window to extract. |
10
|
expected_rt |
Optional[float]
|
Expected retention time in seconds. |
None
|
Source code in src/ms_mint/Chromatogram.py
estimate_noise_level(window=20)
¶
Estimate the noise level of the chromatogram.
Uses a rolling window standard deviation approach to estimate the baseline noise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
window |
int
|
Size of the rolling window for noise estimation. |
20
|
Source code in src/ms_mint/Chromatogram.py
apply_filters()
¶
find_peaks(prominence=None, rel_height=0.9, **kwargs)
¶
Find peaks in the chromatogram.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prominence |
Optional[float]
|
Minimum prominence of peaks. If None, estimated from noise level. |
None
|
rel_height |
float
|
Relative height for determining peak width. |
0.9
|
**kwargs |
Additional keyword arguments to pass to the peak finding function. |
{}
|
Source code in src/ms_mint/Chromatogram.py
optimise_peak_times_with_diff(rolling_window=20, plot=False)
¶
Optimize peak start and end times using the derivative.
Uses the first derivative of the chromatogram to more accurately determine peak start and end times.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rolling_window |
int
|
Window size for rolling mean calculation of the derivative. |
20
|
plot |
bool
|
Whether to plot the results of peak detection on the derivative. |
False
|
Source code in src/ms_mint/Chromatogram.py
select_peak_by_rt(expected_rt=None)
¶
Select the peak closest to the expected retention time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expected_rt |
Optional[float]
|
Expected retention time in seconds. If None, uses the stored expected_rt. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame containing the selected peak information. |
Source code in src/ms_mint/Chromatogram.py
select_peak_by_highest_intensity()
¶
Select the peak with the highest intensity.
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame containing the selected peak information. |
Source code in src/ms_mint/Chromatogram.py
select_peak_with_gaussian_weight(expected_rt=None, sigma=50)
¶
Select peak using Gaussian weighting around expected retention time.
This method applies a Gaussian weighting centered at the expected retention time to favor peaks close to the expected time while still considering peak height.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expected_rt |
Optional[float]
|
Expected retention time in seconds. If None, uses the stored expected_rt. |
None
|
sigma |
float
|
Standard deviation of the Gaussian weight function in seconds. |
50
|
Returns:
Type | Description |
---|---|
Optional[DataFrame]
|
DataFrame containing the selected peak information, or None if no peaks available. |
Source code in src/ms_mint/Chromatogram.py
plot(label=None, **kwargs)
¶
Plot the chromatogram with detected peaks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label |
Optional[str]
|
Label for the plot. |
None
|
**kwargs |
Additional keyword arguments to pass to the plotting function. |
{}
|
Returns:
Type | Description |
---|---|
Figure
|
Matplotlib Figure object. |