quantms-rescoring
quantms-rescoring is a Python tool that adds features to peptide-spectrum matches (PSMs) in idparquet format using multiple tools including SAGE features, quantms spectrum features, MS2PIP, AlphaPeptDeep and DeepLC. It is part of the quantms ecosystem and leverages the MS²Rescore framework to improve identification confidence in proteomics data analysis.
Core Components
- Annotator Engine: Integrates MS2PIP, AlphaPeptDeep and DeepLC models to improve peptide-spectrum match (PSM) confidence.
- Feature Generation: Extracts signal-to-noise ratios, spectrum metrics, SAGE extra features and add them to each PSM for posterior downstream with Percolator.
- Multi-Engine Support: Merges identifications from Comet, MS-GF+, and Sage with configurable priority for consensus rescoring.
- Parquet Format: Uses
.idparquetdirectories as the primary identification format — each directory containspsms.parquet,proteins.parquet,protein_groups.parquet, andsearch_params.parquet— processed via OpenMS. - Transfer Learning: Fine-tunes the MS² prediction model to generate project-specific weights and pass them to the quantms workflow for rescoring.
CLI Tools
rescoring msrescore2feature --help
rescoring sage2feature --help
Incorporates additional features from SAGE into the search_params.parquet file within an idparquet directory.
rescoring spectrum2feature --help
Adds spectrum features like signal-to-noise ratio, spectral entropy, and TIC distribution to each PSM in the idparquet.
rescoring psm_feature_clean --help
Filters and cleans PSMs with missing spectra, invalid features, or multi-engine consensus in the idparquet format.
rescoring download_models --help
Download all required models (MS2PIP, AlphaPeptDeep) for offline use. This is useful for running quantms-rescoring in environments without internet access, such as HPC clusters.
rescoring transfer_learning --help
Perform train and fine-tuning model for AlphaPeptDeep to generate project-specific model. This is useful for running quantms-rescoring in PTM datasets, which are unseen for AlphaPeptDeep pretrained model.
Advanced Algorithms and Improvements
quantms-rescoring significantly enhances the capabilities of MS2PIP, AlphaPeptDeep, DeepLC, and MS2Rescore through several innovative approaches:
MS2PIP Integration Enhancements
- Intelligent Model Selection: Automatically evaluates and selects the optimal MS2PIP model for each dataset based on fragmentation type and correlation quality. If the user-selected model performs poorly, the system will intelligently search for a better alternative.
- Adaptive MS2 Tolerance: Dynamically adjusts MS2 tolerance based on the dataset characteristics, analyzing both reported and predicted tolerances to find the optimal setting.
- Correlation Validation: Implements a robust validation system that ensures the selected model achieves sufficient correlation with experimental spectra, preventing the use of inappropriate models.
- Enhanced Spectrum Processing: Uses OpenMS for spectrum file reading instead of ms2rescore_rs, providing better compatibility with a wider range of mzML files and formats.
AlphaPeptDeep Innovations
- Fine-tuning: Leverages fine-tuning to adapt models to specific experimental/project conditions based on identifications from quantms (idparquet format), improving prediction accuracy for challenging datasets, such as PTM.
- Model Optimization: Automatically benchmarks pretrained vs. retrained AlphaPeptDeep models for each dataset, selecting the one with the better Median PCC for MS2 intensity prediction.
- Enhanced Spectrum Processing: AlphaPeptDeep does not natively support idparquet input, so we use OpenMS for spectrum file reading and pass the processed data to AlphaPeptDeep for prediction and fine-tuning.
- Correlation Validation: Implements a robust validation system that ensures the pretrained and retrained models achieve sufficient correlation with experimental spectra, preventing the use of inappropriate models.
DeepLC Innovations
- Model Optimization: Automatically benchmarks pretrained vs. retrained DeepLC models for each dataset, selecting the one with the lowest Mean Absolute Error (MAE) for retention time prediction.
- Per-Run Calibration: Calibrates DeepLC models for each run to account for chromatographic variations between experiments, improving prediction accuracy.
- Best Peptide Retention Time: Tracks the best retention time prediction for each peptide across multiple PSMs, providing more reliable retention time features.
- Transfer Learning: Leverages transfer learning to adapt models to specific experimental conditions, improving prediction accuracy for challenging datasets.
Spectrum Feature Analysis
Unlike traditional rescoring approaches, quantms-rescoring incorporates advanced spectrum quality metrics:
- Signal-to-Noise Ratio (SNR): Calculates the ratio of maximum intensity to background noise, providing a robust measure of spectrum quality.
- Spectral Entropy: Quantifies the uniformity of peak distribution, helping to distinguish between high and low-quality spectra.
- TIC Distribution Analysis: Analyzes the distribution of Total Ion Current across peaks, identifying spectra with concentrated signal in top peaks.
- Weighted m/z Standard Deviation: Estimates spectral complexity by calculating the intensity-weighted standard deviation of m/z values.
SAGE Feature Integration
- Seamless Integration: Incorporates additional features from SAGE (Spectrum Agnostic Generation of Embeddings) into the rescoring pipeline.
- Feature Validation: Ensures all features are properly validated and formatted for compatibility with OpenMS and downstream tools.
Advantages Over Existing Tools
- Compared to MS2PIP: Adds automatic model selection, validation, features calculations and tolerance optimization, eliminating the need for manual parameter tuning.
- Compared to DeepLC: Provides automatic model selection between pretrained and retrained models, with per-run calibration for improved accuracy.
- Compared to MS2Rescore: Integrates a broader range of MS2 prediction models, including AlphaPeptDeep, and supports fine-tuning to generate project-specific models. It provides a richer feature set encompassing spectrum quality metrics, tighter integration with OpenMS, and more robust support for diverse fragmentation methods and MS levels.
- Compared to AlphaPeptDeep: Seamlessly integrates into the quantms workflow and natively supports the quantms identification results format. It introduces automatic model selection and validation, delivers an expanded feature set, and offers improved handling of different fragmentation methods and MS levels.
Technical Implementation Details
Model Selection and Optimization
- MS2PIP Model Selection:
- Automatically evaluate the quality of the MS2PIP model selected by the user. If the correlation between predicted and experimental spectra is lower than a given threshold, we will try to find the best model to use (
annotator.py). For example, if the user provides as model parameter HCD for a CI experiment, the tool will try to find the best model for this experiment within the CID models available. - If the
ms_toleranceis to restrictive for the data (e.g. 0.05 Da for a 0.5 Da dataset), the tool will try to find the annotated tolerances in the idparquet file and use the best model for this tolerance.
- Automatically evaluate the quality of the MS2PIP model selected by the user. If the correlation between predicted and experimental spectra is lower than a given threshold, we will try to find the best model to use (
- AlphaPeptDeep Model:
- Automatically evaluate the quality of the AlphaPeptDeep model weight passed by the user. If the correlation between predicted and experimental spectra is lower than a given threshold, we will skip MS2 features generation to avoid potential erroneous results.
- When enabling
transfer_learning, the tool will try to fine-tune the AlphaPeptDeep model on the given idparquet and mzML files and compare it with the pretrained model, finally using the best model based on similarity metrics.
- DeepLC Model Selection:
- Automatically select the best DeepLC model for each run based on the retention time calibration and prediction accuracy. Different to ms2rescore, the tool will try to use the best model from MS2PIP and benchmark it with the same model by using transfer learning (
annotator.py). The best model is selected to be used to predict the retention time of PSMs.
- Automatically select the best DeepLC model for each run based on the retention time calibration and prediction accuracy. Different to ms2rescore, the tool will try to use the best model from MS2PIP and benchmark it with the same model by using transfer learning (
Feature Engineering Pipeline
-
Retention Time Analysis:
- Calibrates DeepLC models per run to account for chromatographic variations.
- Calculates delta RT (predicted vs. observed) as a discriminative feature
- Normalizes RT differences for cross-run comparability
-
Spectral Feature Extraction:
- Computes signal-to-noise ratio using maximum intensity relative to background noise
- Calculates spectral entropy to quantify peak distribution uniformity
- Analyzes TIC (Total Ion Current) distribution across peaks for quality assessment
- Determines weighted standard deviation of m/z values for spectral complexity estimation
-
Feature Selection: The parameters
only_featuresallows to select the features to be added to the idparquet file. For example:--only_features "rt_diff,predicted_retention_time_best,dotprod".
Features
MS2PIP and AlphaPeptDeep Feature Mapping Table
| MS2PIP and AlphaPeptDeep Feature | quantms-rescoring Name |
|---|---|
| spec_pearson | MS2PIP/AlphaPeptDeep:SpecPearson |
| cos_norm | MS2PIP/AlphaPeptDeep:SpecCosineNorm |
| spec_pearson_norm | MS2PIP/AlphaPeptDeep:SpecPearsonNorm |
| dotprod | MS2PIP/AlphaPeptDeep:DotProd |
| ionb_pearson_norm | MS2PIP/AlphaPeptDeep:IonBPearsonNorm |
| iony_pearson_norm | MS2PIP/AlphaPeptDeep:IonYPearsonNorm |
| spec_mse_norm | MS2PIP/AlphaPeptDeep:SpecMseNorm |
| ionb_mse_norm | MS2PIP/AlphaPeptDeep:IonBMseNorm |
| iony_mse_norm | MS2PIP/AlphaPeptDeep:IonYMseNorm |
| min_abs_diff_norm | MS2PIP/AlphaPeptDeep:MinAbsDiffNorm |
| max_abs_diff_norm | MS2PIP/AlphaPeptDeep:MaxAbsDiffNorm |
| abs_diff_Q1_norm | MS2PIP/AlphaPeptDeep:AbsDiffQ1Norm |
| abs_diff_Q2_norm | MS2PIP/AlphaPeptDeep:AbsDiffQ2Norm |
| abs_diff_Q3_norm | MS2PIP/AlphaPeptDeep:AbsDiffQ3Norm |
| mean_abs_diff_norm | MS2PIP/AlphaPeptDeep:MeanAbsDiffNorm |
| std_abs_diff_norm | MS2PIP/AlphaPeptDeep:StdAbsDiffNorm |
| ionb_min_abs_diff_norm | MS2PIP/AlphaPeptDeep:IonBMinAbsDiffNorm |
| ionb_max_abs_diff_norm | MS2PIP/AlphaPeptDeep:IonBMaxAbsDiffNorm |
| ionb_abs_diff_Q1_norm | MS2PIP/AlphaPeptDeep:IonBAbsDiffQ1Norm |
| ionb_abs_diff_Q2_norm | MS2PIP/AlphaPeptDeep:IonBAbsDiffQ2Norm |
| ionb_abs_diff_Q3_norm | MS2PIP/AlphaPeptDeep:IonBAbsDiffQ3Norm |
| ionb_mean_abs_diff_norm | MS2PIP/AlphaPeptDeep:IonBMeanAbsDiffNorm |
| ionb_std_abs_diff_norm | MS2PIP/AlphaPeptDeep:IonBStdAbsDiffNorm |
| iony_min_abs_diff_norm | MS2PIP/AlphaPeptDeep:IonYMinAbsDiffNorm |
| iony_max_abs_diff_norm | MS2PIP/AlphaPeptDeep:IonYMaxAbsDiffNorm |
| iony_abs_diff_Q1_norm | MS2PIP/AlphaPeptDeep:IonYAbsDiffQ1Norm |
| iony_abs_diff_Q2_norm | MS2PIP/AlphaPeptDeep:IonYAbsDiffQ2Norm |
| iony_abs_diff_Q3_norm | MS2PIP/AlphaPeptDeep:IonYAbsDiffQ3Norm |
| iony_mean_abs_diff_norm | MS2PIP/AlphaPeptDeep:IonYMeanAbsDiffNorm |
| iony_std_abs_diff_norm | MS2PIP/AlphaPeptDeep:IonYStdAbsDiffNorm |
| dotprod_norm | MS2PIP/AlphaPeptDeep:DotProdNorm |
| dotprod_ionb_norm | MS2PIP/AlphaPeptDeep:DotProdIonBNorm |
| dotprod_iony_norm | MS2PIP/AlphaPeptDeep:DotProdIonYNorm |
| cos_ionb_norm | MS2PIP/AlphaPeptDeep:CosIonBNorm |
| cos_iony_norm | MS2PIP/AlphaPeptDeep:CosIonYNorm |
| ionb_pearson | MS2PIP/AlphaPeptDeep:IonBPearson |
| iony_pearson | MS2PIP/AlphaPeptDeep:IonYPearson |
| spec_spearman | MS2PIP/AlphaPeptDeep:SpecSpearman |
| ionb_spearman | MS2PIP/AlphaPeptDeep:IonBSpearman |
| iony_spearman | MS2PIP/AlphaPeptDeep:IonYSpearman |
| spec_mse | MS2PIP/AlphaPeptDeep:SpecMse |
| ionb_mse | MS2PIP/AlphaPeptDeep:IonBMse |
| iony_mse | MS2PIP/AlphaPeptDeep:IonYMse |
| min_abs_diff_iontype | MS2PIP/AlphaPeptDeep:MinAbsDiffIonType |
| max_abs_diff_iontype | MS2PIP/AlphaPeptDeep:MaxAbsDiffIonType |
| min_abs_diff | MS2PIP/AlphaPeptDeep:MinAbsDiff |
| max_abs_diff | MS2PIP/AlphaPeptDeep:MaxAbsDiff |
| abs_diff_Q1 | MS2PIP/AlphaPeptDeep:AbsDiffQ1 |
| abs_diff_Q2 | MS2PIP/AlphaPeptDeep:AbsDiffQ2 |
| abs_diff_Q3 | MS2PIP/AlphaPeptDeep:AbsDiffQ3 |
| mean_abs_diff | MS2PIP/AlphaPeptDeep:MeanAbsDiff |
| std_abs_diff | MS2PIP/AlphaPeptDeep:StdAbsDiff |
| ionb_min_abs_diff | MS2PIP/AlphaPeptDeep:IonBMinAbsDiff |
| ionb_max_abs_diff | MS2PIP/AlphaPeptDeep:IonBMaxAbsDiff |
| ionb_abs_diff_Q1 | MS2PIP/AlphaPeptDeep:IonBAbsDiffQ1 |
| ionb_abs_diff_Q2 | MS2PIP/AlphaPeptDeep:IonBAbsDiffQ2 |
| ionb_abs_diff_Q3 | MS2PIP/AlphaPeptDeep:IonBAbsDiffQ3 |
| ionb_mean_abs_diff | MS2PIP/AlphaPeptDeep:IonBMeanAbsDiff |
| ionb_std_abs_diff | MS2PIP/AlphaPeptDeep:IonBStdAbsDiff |
| iony_min_abs_diff | MS2PIP/AlphaPeptDeep:IonYMinAbsDiff |
| iony_max_abs_diff | MS2PIP/AlphaPeptDeep:IonYMaxAbsDiff |
| iony_abs_diff_Q1 | MS2PIP/AlphaPeptDeep:IonYAbsDiffQ1 |
| iony_abs_diff_Q2 | MS2PIP/AlphaPeptDeep:IonYAbsDiffQ2 |
| iony_abs_diff_Q3 | MS2PIP/AlphaPeptDeep:IonYAbsDiffQ3 |
| iony_mean_abs_diff | MS2PIP/AlphaPeptDeep:IonYMeanAbsDiff |
| iony_std_abs_diff | MS2PIP/AlphaPeptDeep:IonYStdAbsDiff |
| dotprod_ionb | MS2PIP/AlphaPeptDeep:DotProdIonB |
| dotprod_iony | MS2PIP/AlphaPeptDeep:DotProdIonY |
| cos_ionb | MS2PIP/AlphaPeptDeep:CosIonB |
| cos_iony | MS2PIP/AlphaPeptDeep:CosIonY |
DeepLC Feature Mapping Table
| MMS2Rescore DeepLC Feature | quantms-rescoring Name |
|---|---|
| observed_retention_time | DeepLC:ObservedRetentionTime |
| predicted_retention_time | DeepLC:PredictedRetentionTime |
| rt_diff | DeepLC:RtDiff |
| observed_retention_time_best | DeepLC:ObservedRetentionTimeBest |
| predicted_retention_time_best | DeepLC:PredictedRetentionTimeBest |
| rt_diff_best | DeepLC:RtDiffBest |
Spectrum Feature Mapping Table
| Spectrum Feature | quantms-rescoring Name |
|---|---|
| snr | Quantms:Snr |
| spectral_entropy | Quantms:SpectralEntropy |
| fraction_tic_top_10 | Quantms:FracTICinTop10Peaks |
| weighted_std_mz | Quantms:WeightedStdMz |
Data Processing of idparquet Files
- Parallel Processing: Implements multiprocessing capabilities for handling large datasets efficiently
- OpenMS Compatibility Layer: Custom helper classes that gather statistics of number of PSMs by MS levels / dissociation methods, etc.
- Feature Validation: Convert all Features from MS2PIP, AlphaPeptDeep, DeepLC, and quantms into OpenMS features with well-established names (
constants.py) - PSM Filtering and Validation:
- Filter PSMs with missing spectra information or empty peaks.
- Aborts processing when the input contains more than one MS level or dissociation method; only MS2 spectra are supported.
- Multi-Engine Consensus Rescoring: When multiple idparquet directories from different search engines (Comet, MS-GF+, Sage) are provided, the tool merges them in priority order (
Comet > MS-GF+ > Sage), fills missing scores for each engine, and marks the result asquantms-consensus-rescoring. - Output / Input files:
- Input is an
.idparquetdirectory containingpsms.parquet,proteins.parquet,protein_groups.parquet, andsearch_params.parquet, along with a companion.mzMLspectrum file. - Output is an
.idparquetdirectory with the same structure, enriched with predicted features.
- Input is an
Installation
Install quantms-rescoring using one of the following methods:
Using pip
❯ pip install quantms-rescoring
Using conda
❯ conda install -c bioconda quantms-rescoring
Using Docker
# Pull the latest image from GitHub Container Registry
❯ docker pull ghcr.io/bigbio/quantms-rescoring:latest
# Run the container
❯ docker run --rm ghcr.io/bigbio/quantms-rescoring:latest --help
# Run with data mounted
❯ docker run --rm -v /path/to/data:/data ghcr.io/bigbio/quantms-rescoring:latest rescoring msrescore2feature --help
Build from source:
-
Clone the quantms-rescoring repository:
❯ git clone https://github.com/bigbio/quantms-rescoring
-
Navigate to the project directory:
❯ cd quantms-rescoring
-
Install the project dependencies:
-
Using
pip:❯ pip install -r requirements.txt
-
Using
conda:❯ conda env create -f environment.yml
-
-
Install the package using
poetry:❯ poetry install
Build Docker image locally:
# Build the Docker image
❯ docker build -t quantms-rescoring:latest .
# Test the image
❯ ./scripts/test-docker.sh latest
HPC and Nextflow Integration
quantms-rescoring is optimized for HPC/Slurm environments and Nextflow workflows. The tool automatically manages thread allocation, GPU configuration, and multiprocessing stability to prevent resource contention and failures.
Thread Configuration
The tool uses a single --processes parameter that directly maps to available CPUs. Each process uses 1 internal thread to avoid thread explosion when using multiprocessing.
For Nextflow workflows:
process MS2Rescore {
container 'ghcr.io/bigbio/quantms-rescoring:latest'
input:
path idparquet
path mzml
output:
path "*.idparquet"
script:
"""
rescoring msrescore2feature \\
--idparquet ${idparquet} \\
--mzml ${mzml} \\
--output ${idparquet.baseName}_rescored.idparquet \\
--processes ${task.cpus}
"""
}
For standalone HPC usage:
# Set environment variable for automatic thread configuration (optional)
# This also disables GPU to prevent CUDA initialization errors on CPU-only nodes
export QUANTMS_HPC_MODE=1
# Run with explicit process count
rescoring msrescore2feature \\
--idparquet input.idparquet \\
--mzml input.mzML \\
--output output.idparquet \\
--processes 8
HPC Stability Features
The tool includes several stability features designed for reliable operation on HPC clusters:
-
GPU/CUDA Disabled by Default: CLI commands automatically disable GPU (
CUDA_VISIBLE_DEVICES="") to prevent CUDA initialization errors on CPU-only nodes. This eliminates the "CUDA Error 303" and TensorFlow/cuDNN warning spam. -
Worker Process Initialization: Spawned worker processes are properly initialized with warning filters to prevent log spam from pyopenms, TensorFlow, and other libraries.
-
Pool Timeout Protection: Multiprocessing pool operations have a 1-hour timeout to prevent indefinite hangs. If a worker becomes unresponsive, the pool is terminated gracefully.
-
Daemon Process Protection: The tool detects when running inside daemon processes (common in some job schedulers) and automatically falls back to single-threaded mode to avoid "daemonic processes cannot have children" errors.
-
File Handle Management: Proper cleanup of file handles when suppressing stdout from verbose libraries like TensorFlow.
Thread Management Details:
- Automatic Configuration: CLI commands (
msrescore2feature,transfer_learning) automatically configure thread limits for all numerical libraries (NumPy, PyTorch, TensorFlow, etc.) - Opt-in Import-time Configuration: Set
QUANTMS_HPC_MODE=1to automatically apply thread limits and disable GPU when importing the library in Python scripts - Explicit Configuration: For programmatic use, call
configure_threading()andconfigure_torch_threads()directly:
from quantmsrescore import configure_threading, configure_torch_threads
# Configure before importing heavy libraries
# disable_gpu=True prevents CUDA initialization errors on CPU-only nodes
configure_threading(n_threads=1, verbose=True, disable_gpu=True)
configure_torch_threads(n_threads=1)
This prevents thread explosion where processes × cpu_count threads compete for cpu_count cores, which can cause:
- Excessive memory usage from thread stacks
- Node OOM kills in Slurm clusters
- Performance degradation from context switching
Offline Model Download
For environments without internet access (e.g., HPC clusters), you can download all required models ahead of time using the download_models command:
# Download all models to default cache locations
❯ rescoring download_models
# Download models to a specific directory
❯ rescoring download_models --model_dir /path/to/models
# Download only specific models
❯ rescoring download_models --models deeplc,alphapeptdeep
# Get help
❯ rescoring download_models --help
This command downloads models for:
- MS2PIP: Fragment ion intensity prediction models (bundled with ms2pip package)
- AlphaPeptDeep: MS2 spectrum, retention time, and CCS prediction models
Note: DeepLC does not require a separate model download — it is handled internally by the DeepLC package. Once downloaded, you can transfer the models to your offline environment and use them with the processing commands. For AlphaPeptDeep models, use the
--ms2_model_diroption when runningmsrescore2feature.
Issues and Contributions
For any issues or contributions, please open an issue in the GitHub repository - we use the quantms repo to control all issues—or PR in the GitHub repository.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quantms_rescoring-0.0.23.tar.gz.
File metadata
- Download URL: quantms_rescoring-0.0.23.tar.gz
- Upload date:
- Size: 97.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63b4d16059922e190b54b54615773ecbacf96a751e291958a993a142017f202a
|
|
| MD5 |
fe10f53be552cc19fe4344ce8444f5d4
|
|
| BLAKE2b-256 |
b6d0dcef8c96f624ff2cd0c4880dc7212642ab740c77c206692f5142497483da
|
File details
Details for the file quantms_rescoring-0.0.23-py3-none-any.whl.
File metadata
- Download URL: quantms_rescoring-0.0.23-py3-none-any.whl
- Upload date:
- Size: 102.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
380806f6b2f660f3ad4ebd0954ae7059cf23c96dc69a72a962b7d4395647e743
|
|
| MD5 |
d4a8f297e4c4e8caf29aa91597d28e9c
|
|
| BLAKE2b-256 |
a0ffa37ba4c1a2586bbbe1263ce24268c91bc9a63ba720bc30f1578bc8f6bad0
|