Skip to content

Commit

Permalink
don't use keys to test if in dict + reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
paretje committed Jul 9, 2024
1 parent 2195aa2 commit a8f5b15
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions psm_utils/io/xtandem.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
[+39,99545]
"""


from __future__ import annotations

import logging
Expand Down Expand Up @@ -155,24 +154,26 @@ def _parse_entry(self, entry, run: str) -> list:
peptide_entry = protein_entry["peptide"]
peptidoform = self._parse_peptidoform(peptide_entry, entry["z"])

if peptidoform not in pepform_to_psms.keys():
if peptidoform not in pepform_to_psms:
psm = PSM(
peptidoform = self._parse_peptidoform(peptide_entry, entry["z"]),
spectrum_id = entry["support"]["fragment ion mass spectrum"]["note"],
is_decoy = protein_entry["label"].startswith(self.decoy_prefix),
score = -np.log(peptide_entry[self.score_key])
if self.score_key == "expect"
else peptide_entry[self.score_key],
precursor_mz = entry["mh"] / entry["z"],
retention_time = entry["rt"],
run = run,
protein_list = [ protein_entry["note"] ],
source = "X!Tandem",
provenance_data = {
peptidoform=self._parse_peptidoform(peptide_entry, entry["z"]),
spectrum_id=entry["support"]["fragment ion mass spectrum"]["note"],
is_decoy=protein_entry["label"].startswith(self.decoy_prefix),
score=(
-np.log(peptide_entry[self.score_key])
if self.score_key == "expect"
else peptide_entry[self.score_key]
),
precursor_mz=entry["mh"] / entry["z"],
retention_time=entry["rt"],
run=run,
protein_list=[protein_entry["note"]],
source="X!Tandem",
provenance_data={
"xtandem_filename": str(self.filename),
"xtandem_id": str(entry["id"]),
},
metadata = {
metadata={
"xtandem_hyperscore": str(peptide_entry["hyperscore"]),
"xtandem_delta": str(peptide_entry["delta"]),
"xtandem_nextscore": str(peptide_entry["nextscore"]),
Expand All @@ -181,7 +182,7 @@ def _parse_entry(self, entry, run: str) -> list:
pepform_to_psms[peptidoform] = psm
else:
pepform_to_psms[peptidoform].protein_list.append(protein_entry["note"])

return list(pepform_to_psms.values())

def _parse_run(self, filepath):
Expand Down

0 comments on commit a8f5b15

Please sign in to comment.