2323from ms2pip ._utils .feature_names import get_feature_names
2424from ms2pip ._utils .psm_input import read_psms
2525from ms2pip ._utils .retention_time import RetentionTime
26+ from ms2pip ._utils .ion_mobility import IonMobility
2627from ms2pip ._utils .xgb_models import get_predictions_xgb , validate_requested_xgb_model
2728from ms2pip .constants import MODELS
2829from ms2pip .result import ProcessingResult , calculate_correlations
@@ -74,6 +75,7 @@ def predict_single(
7475def predict_batch (
7576 psms : Union [PSMList , str , Path ],
7677 add_retention_time : bool = False ,
78+ add_ion_mobility : bool = False ,
7779 psm_filetype : Optional [str ] = None ,
7880 model : Optional [str ] = "HCD" ,
7981 model_dir : Optional [Union [str , Path ]] = None ,
@@ -91,6 +93,8 @@ def predict_batch(
9193 filetypes. See https://psm-utils.readthedocs.io/en/stable/#supported-file-formats.
9294 add_retention_time
9395 Add retention time predictions with DeepLC (Requires optional DeepLC dependency).
96+ add_ion_mobility
97+ Add ion mobility predictions with IM2Deep (Requires optional IM2Deep dependency).
9498 model
9599 Model to use for prediction. Default: "HCD".
96100 model_dir
@@ -113,6 +117,11 @@ def predict_batch(
113117 rt_predictor = RetentionTime (processes = processes )
114118 rt_predictor .add_rt_predictions (psm_list )
115119
120+ if add_ion_mobility :
121+ logger .info ("Adding ion mobility predictions" )
122+ im_predictor = IonMobility (processes = processes )
123+ im_predictor .add_im_predictions (psm_list )
124+
116125 with Encoder .from_psm_list (psm_list ) as encoder :
117126 ms2pip_parallelized = _Parallelized (
118127 encoder = encoder ,
@@ -130,6 +139,7 @@ def predict_library(
130139 fasta_file : Optional [Union [str , Path ]] = None ,
131140 config : Optional [Union [ProteomeSearchSpace , dict , str , Path ]] = None ,
132141 add_retention_time : bool = False ,
142+ add_ion_mobility : bool = False ,
133143 model : Optional [str ] = "HCD" ,
134144 model_dir : Optional [Union [str , Path ]] = None ,
135145 batch_size : int = 100000 ,
@@ -148,6 +158,8 @@ def predict_library(
148158 parameters. Required if `fasta_file` is not provided.
149159 add_retention_time
150160 Add retention time predictions with DeepLC (Requires optional DeepLC dependency).
161+ add_ion_mobility
162+ Add ion mobility predictions with IM2Deep (Requires optional IM2Deep dependency).
151163 model
152164 Model to use for prediction. Default: "HCD".
153165 model_dir
@@ -157,6 +169,11 @@ def predict_library(
157169 processes
158170 Number of parallel processes for multiprocessing steps. By default, all available.
159171
172+ Yields
173+ ------
174+ predictions: List[ProcessingResult]
175+ Predicted spectra with theoretical m/z and predicted intensity values.
176+
160177 """
161178 if fasta_file and config :
162179 # Use provided proteome, but overwrite fasta_file
@@ -183,6 +200,7 @@ def predict_library(
183200 yield predict_batch (
184201 search_space .filter_psms_by_mz (PSMList (psm_list = list (batch ))),
185202 add_retention_time = add_retention_time ,
203+ add_ion_mobility = add_ion_mobility ,
186204 model = model ,
187205 model_dir = model_dir ,
188206 processes = processes ,
@@ -197,6 +215,7 @@ def correlate(
197215 spectrum_id_pattern : Optional [str ] = None ,
198216 compute_correlations : bool = False ,
199217 add_retention_time : bool = False ,
218+ add_ion_mobility : bool = False ,
200219 model : Optional [str ] = "HCD" ,
201220 model_dir : Optional [Union [str , Path ]] = None ,
202221 ms2_tolerance : float = 0.02 ,
@@ -221,6 +240,8 @@ def correlate(
221240 Compute correlations between predictions and targets.
222241 add_retention_time
223242 Add retention time predictions with DeepLC (Requires optional DeepLC dependency).
243+ add_ion_mobility
244+ Add ion mobility predictions with IM2Deep (Requires optional IM2Deep dependency).
224245 model
225246 Model to use for prediction. Default: "HCD".
226247 model_dir
@@ -245,6 +266,11 @@ def correlate(
245266 rt_predictor = RetentionTime (processes = processes )
246267 rt_predictor .add_rt_predictions (psm_list )
247268
269+ if add_ion_mobility :
270+ logger .info ("Adding ion mobility predictions" )
271+ im_predictor = IonMobility (processes = processes )
272+ im_predictor .add_im_predictions (psm_list )
273+
248274 with Encoder .from_psm_list (psm_list ) as encoder :
249275 ms2pip_parallelized = _Parallelized (
250276 encoder = encoder ,
0 commit comments