@@ -58,13 +58,8 @@ def _get_peptide_spectrum_match(self, psm_dict) -> PSM:
5858 except KeyError :
5959 continue
6060
61- # If ion mobility is not 0.0 (not present), add it to the rescoring features
62- if float (psm_dict ['ion_mobility' ]):
63- rescoring_features .update ({
64- 'ion_mobility' : float (psm_dict ['ion_mobility' ]),
65- 'predicted_mobility' : float (psm_dict ['predicted_mobility' ]),
66- 'delta_mobility' : float (psm_dict ['delta_mobility' ])
67- })
61+ ion_mobility_features = self ._extract_ion_mobility_features (psm_dict )
62+ rescoring_features .update (ion_mobility_features )
6863
6964 return PSM (
7065 peptidoform = self ._parse_peptidoform (
@@ -78,7 +73,7 @@ def _get_peptide_spectrum_match(self, psm_dict) -> PSM:
7873 score = float (psm_dict [self .score_column ]),
7974 precursor_mz = self ._parse_precursor_mz (psm_dict ["expmass" ], psm_dict ["charge" ]),
8075 retention_time = float (psm_dict ["rt" ]),
81- ion_mobility = float ( psm_dict [ "ion_mobility" ]) if float ( psm_dict [ "ion_mobility" ]) else None ,
76+ ion_mobility = rescoring_features . get ( "ion_mobility" , None ) ,
8277 protein_list = psm_dict ["proteins" ].split (";" ),
8378 source = "sage" ,
8479 rank = int (float (psm_dict ["rank" ])),
@@ -101,6 +96,24 @@ def _parse_precursor_mz(expmass: str, charge: Optional[str]) -> Optional[float]:
10196 return (expmass + (mass .nist_mass ["H" ][1 ][0 ] * charge )) / charge
10297 else :
10398 return None
99+
100+ @staticmethod
101+ def _extract_ion_mobility_features (psm_dict : dict ) -> dict :
102+ """
103+ Extract ion mobility features from the PSM dictionary if present and non-zero.
104+ Returns a dict with the relevant keys or an empty dict.
105+ """
106+ try :
107+ ion_mob = float (psm_dict ["ion_mobility" ])
108+ if ion_mob :
109+ return {
110+ "ion_mobility" : ion_mob ,
111+ "predicted_mobility" : float (psm_dict ["predicted_mobility" ]),
112+ "delta_mobility" : float (psm_dict ["delta_mobility" ]),
113+ }
114+ except (KeyError , ValueError ):
115+ pass
116+ return {}
104117
105118 @classmethod
106119 def from_dataframe (cls , dataframe ) -> PSMList :
0 commit comments