Skip to content

Commit 9b8ea22

Browse files
committed
Add ion mobility information from Sage
1 parent cba05bf commit 9b8ea22

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

psm_utils/io/sage.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ def _get_peptide_spectrum_match(self, psm_dict) -> PSM:
5757
rescoring_features[ft] = psm_dict[ft]
5858
except KeyError:
5959
continue
60+
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+
})
6068

6169
return PSM(
6270
peptidoform=self._parse_peptidoform(
@@ -70,7 +78,7 @@ def _get_peptide_spectrum_match(self, psm_dict) -> PSM:
7078
score=float(psm_dict[self.score_column]),
7179
precursor_mz=self._parse_precursor_mz(psm_dict["expmass"], psm_dict["charge"]),
7280
retention_time=float(psm_dict["rt"]),
73-
ion_mobility=float(psm_dict["ion_mobility"]),
81+
ion_mobility=float(psm_dict["ion_mobility"]) if float(psm_dict["ion_mobility"]) else None,
7482
protein_list=psm_dict["proteins"].split(";"),
7583
source="sage",
7684
rank=int(float(psm_dict["rank"])),
@@ -154,4 +162,4 @@ def __iter__(self) -> Iterable[PSM]:
154162
"poisson",
155163
# "ms1_intensity", # Removed in Sage v0.14
156164
"ms2_intensity",
157-
]
165+
]

tests/test_data/resultsIM.sage.tsv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
psm_id peptide proteins num_proteins filename scannr rank label expmass calcmass charge peptide_len missed_cleavages semi_enzymatic isotope_error precursor_ppm fragment_ppm hyperscore delta_next delta_best rt aligned_rt predicted_rt delta_rt_model ion_mobility predicted_mobility delta_mobility matched_peaks longest_b longest_y longest_y_pct matched_intensity_pct scored_candidates poisson sage_discriminant_score posterior_error spectrum_q peptide_q protein_q ms2_intensity
2+
529791 YVDDTQFVRFDSDAASPR sp|P01889|HLAB_HUMAN;sp|P10321|HLAC_HUMAN 2 G220824_028_Slot2-34_1_6753.mzml index=45761 1 1 2086.9507 2087.9548 3 18 0 0 -1.00335 0.38332784 1.5193833 44.947527657385436 24.626872218188044 0.0 23.004148 0.5305706 0.5301316 0.0004390478 0.96470714 0.9236175 0.041089654 17 2 6 0.33333334 46.215378 33149 -14.997740845471464 0.47067946 -96.47973 0.0000107030855 0.00009881538 0.0006954081 26230.0

tests/test_io/test_sage.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,62 @@
4848
},
4949
)
5050

51+
test_psm_im = PSM(
52+
peptidoform="YVDDTQFVRFDSDAASPR/3",
53+
spectrum_id="index=45761",
54+
run="G220824_028_Slot2-34_1_6753",
55+
collection=None,
56+
spectrum=None,
57+
is_decoy=False,
58+
score=0.47067946,
59+
qvalue=0.0000107030855,
60+
pep=None,
61+
precursor_mz=696.6580583654032,
62+
retention_time=23.004148,
63+
ion_mobility=0.96470714,
64+
protein_list=['sp|P01889|HLAB_HUMAN','sp|P10321|HLAC_HUMAN'],
65+
rank=1,
66+
source="sage",
67+
metadata={},
68+
rescoring_features={
69+
"expmass": 2086.9507,
70+
"calcmass": 2087.9548,
71+
"peptide_len": 18.0,
72+
"missed_cleavages": 0.0,
73+
"isotope_error": -1.00335,
74+
"precursor_ppm": 0.38332784,
75+
"fragment_ppm": 1.5193833,
76+
"hyperscore": 44.947527657385436,
77+
"delta_next": 24.626872218188044,
78+
"delta_best": 0.0,
79+
"delta_rt_model": 0.0004390478,
80+
"aligned_rt": 0.5305706,
81+
"predicted_rt": 0.5301316,
82+
"matched_peaks": 17.0,
83+
"longest_b": 2.0,
84+
"longest_y": 6.0,
85+
"longest_y_pct": 0.33333334,
86+
"matched_intensity_pct": 46.215378,
87+
"scored_candidates": 33149.0,
88+
"poisson": -14.997740845471464,
89+
"ms2_intensity": 26230.0,
90+
"ion_mobility": 0.96470714,
91+
"predicted_mobility": 0.9236175,
92+
"delta_mobility": 0.041089654,
93+
}
94+
)
95+
5196

5297
class TestSageTSVReader:
5398
def test_iter(self):
5499
with SageTSVReader("./tests/test_data/results.sage.tsv") as reader:
55100
for psm in reader:
56101
psm.provenance_data = {}
57102
assert psm == test_psm
103+
with SageTSVReader("./tests/test_data/resultsIM.sage.tsv") as reader:
104+
for psm in reader:
105+
psm.provenance_data = {}
106+
assert psm == test_psm_im
58107

59108

60109
class TestSageParquetReader:

0 commit comments

Comments
 (0)