Skip to content

Commit

Permalink
Merge pull request #126 from wilhelm-lab/feature/change_iontype_order…
Browse files Browse the repository at this point in the history
…_for_dlmoix

changed order of iontypes in preprocessing
  • Loading branch information
picciama authored Jul 31, 2024
2 parents cbf3bb9 + aac0655 commit 2ca4c8d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
27 changes: 25 additions & 2 deletions spectrum_fundamentals/fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,30 @@ def _xl_sanity_check(noncl_xl: int, peptide_beta_mass: float, xl_pos: float):

def retrieve_ion_types(fragmentation_method: str) -> List[str]:
"""
Retrieve the ion types resulting from a fragmentation method.
Retrieve the ion types resulting from a fragmentation method in the correct order for dlomix predictions.
Given the fragmentation method the function returns all ion types that can result from it.
: param fragmentation_method: fragmentation method used during the MS
: raises ValueError: if fragmentation_method is other than one of HCD, CID, ETD, ECD, ETCID, ETHCD, UVPD
: return: list of possible ion types
"""
fragmentation_method = fragmentation_method.upper()
if fragmentation_method == "HCD" or fragmentation_method == "CID":
return ["y", "b"]
elif fragmentation_method == "ETD" or fragmentation_method == "ECD":
return ["z", "c"]
elif fragmentation_method == "ETCID" or fragmentation_method == "ETHCD":
return ["y", "b", "z", "c"]
elif fragmentation_method == "UVPD":
return ["y", "b", "z", "c", "x", "a"]
else:
raise ValueError(f"Unknown fragmentation method provided: {fragmentation_method}")


def retrieve_ion_types_for_peak_initialization(fragmentation_method: str) -> List[str]:
"""
Retrieve the ion types resulting from a fragmentation method in the correct order for peak initialization.
Given the fragmentation method the function returns all ion types that can result from it.
Expand Down Expand Up @@ -161,7 +184,7 @@ def initialize_peaks(
_xl_sanity_check(noncl_xl, peptide_beta_mass, xl_pos)

max_charge = min(3, charge)
ion_types = retrieve_ion_types(fragmentation_method)
ion_types = retrieve_ion_types_for_peak_initialization(fragmentation_method)
modification_deltas = _get_modifications(sequence, custom_mods=custom_mods)

fragments_meta_data = []
Expand Down
28 changes: 26 additions & 2 deletions tests/unit_tests/test_fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,36 @@ def test_get_ion_types_etd(self):

def test_get_ion_types_etcid(self):
"""Test retrieving ion types for ETCID."""
assert fragments.retrieve_ion_types("ETCID") == ["y", "z", "b", "c"]
assert fragments.retrieve_ion_types("ETCID") == ["y", "b", "z", "c"]

def test_get_ion_types_lower_case(self):
"""Test lower case fragmentation method."""
assert fragments.retrieve_ion_types("uvpd") == ["x", "y", "z", "a", "b", "c"]
assert fragments.retrieve_ion_types("uvpd") == ["y", "b", "z", "c", "x", "a"]

def test_invalid_fragmentation_method(self):
"""Test if error is raised for invalid fragmentation method."""
self.assertRaises(ValueError, fragments.retrieve_ion_types, "XYZ")


class TestFragmentationMethodForPeakInitialization(unittest.TestCase):
"""Class to test the retrieving of the IonTypes for peak initialization."""

def test_get_ion_types_hcd(self):
"""Test retrieving ion types for HCD."""
assert fragments.retrieve_ion_types_for_peak_initialization("HCD") == ["y", "b"]

def test_get_ion_types_etd(self):
"""Test retrieving ion types for ETD."""
assert fragments.retrieve_ion_types_for_peak_initialization("ETD") == ["z", "c"]

def test_get_ion_types_etcid(self):
"""Test retrieving ion types for ETCID."""
assert fragments.retrieve_ion_types_for_peak_initialization("ETCID") == ["y", "z", "b", "c"]

def test_get_ion_types_lower_case(self):
"""Test lower case fragmentation method."""
assert fragments.retrieve_ion_types_for_peak_initialization("uvpd") == ["x", "y", "z", "a", "b", "c"]

def test_invalid_fragmentation_method(self):
"""Test if error is raised for invalid fragmentation method."""
self.assertRaises(ValueError, fragments.retrieve_ion_types_for_peak_initialization, "XYZ")

0 comments on commit 2ca4c8d

Please sign in to comment.