Skip to content

Commit

Permalink
Merge pull request #76 from wilhelm-lab/fix/tmt_modstring
Browse files Browse the repository at this point in the history
Fix/tmt modstring
  • Loading branch information
picciama authored Sep 19, 2023
2 parents 86695a3 + bcc1355 commit cbf31c8
Show file tree
Hide file tree
Showing 6 changed files with 601 additions and 626 deletions.
1,196 changes: 583 additions & 613 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [


[tool.poetry.dependencies]
python = "^3.8.0"
python = ">=3.8.0,<3.11.0"
click = ">=8.0.0"
rich = ">=10.3.0"
PyYAML = ">=5.4.1"
Expand Down
9 changes: 4 additions & 5 deletions spectrum_fundamentals/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"C[UNIMOD:4]": 2,
"K[UNIMOD:737]": 22,
"K[UNIMOD:2016]": 22,
"K[UNIMOD:2016]": 22,
"K[UNIMOD:214]": 22,
"K[UNIMOD:730]": 22,
"S[UNIMOD:21]": 25,
Expand All @@ -73,16 +72,16 @@
"(ox)": "[UNIMOD:35]",
"(Oxidation (M))": "[UNIMOD:35]",
"(tm)": "[UNIMOD:737]",
"_(tm)": "_[UNIMOD:737]",
"_(tm)": "_[UNIMOD:737]-",
"K(tm)": "K[UNIMOD:737]",
"(i4)": "[UNIMOD:214]",
"_(i4)": "_[UNIMOD:214]",
"_(i4)": "_[UNIMOD:214]-",
"K(i4)": "K[UNIMOD:214]",
"(i8)": "[UNIMOD:730]",
"_(i8)": "_[UNIMOD:730]",
"_(i8)": "_[UNIMOD:730]-",
"K(i8)": "K[UNIMOD:730]",
"(tmp)": "[UNIMOD:2016]",
"_(tmp)": "_[UNIMOD:2016]",
"_(tmp)": "_[UNIMOD:2016]-",
"K(tmp)": "K[UNIMOD:2016]",
"(ph)": "[UNIMOD:21]",
"(Phospho (STY))": "[UNIMOD:21]",
Expand Down
7 changes: 4 additions & 3 deletions spectrum_fundamentals/fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ def _get_modifications(peptide_sequence: str) -> Optional[Tuple[Dict[int, float]
modification_mass = constants.MOD_MASSES
# Handle terminal modifications here
for possible_tmt_mod in constants.TMT_MODS.values():
if peptide_sequence.startswith(possible_tmt_mod): # TMT_6
n_term_tmt = possible_tmt_mod + "-"
if peptide_sequence.startswith(n_term_tmt):
tmt_n_term = 2
modification_deltas.update({0: constants.MOD_MASSES[possible_tmt_mod]})
peptide_sequence = peptide_sequence[len(possible_tmt_mod) :]
peptide_sequence = peptide_sequence[len(n_term_tmt) :]
break

if "(" in peptide_sequence:
Expand Down Expand Up @@ -183,7 +184,7 @@ def initialize_peaks(
for ion_type in range(0, number_of_ion_types): # generate all ion types
# Check for neutral loss here
mass = (ion_type_masses[ion_type] + charge_delta) / charge
min_mass, max_mass = get_min_max_mass(mass_analyzer, mass)
min_mass, max_mass = get_min_max_mass(mass_analyzer, mass, mass_tolerance, unit_mass_tolerance)
fragments_meta_data.append(
{
"ion_type": ion_types[ion_type], # ion type
Expand Down
9 changes: 7 additions & 2 deletions tests/unit_tests/test_fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def test_get_modifications_carbamidomethylation(self):

def test_get_modifications_tmt_tag(self):
"""Test get_modifications."""
assert fragments._get_modifications("[UNIMOD:737]ABC[UNIMOD:4]") == ({0: 229.162932, 2: 57.02146}, 2, "ABC")
assert fragments._get_modifications("[UNIMOD:737]-ABC[UNIMOD:4]") == ({0: 229.162932, 2: 57.02146}, 2, "ABC")

def test_get_modifications_tmtpro_tag(self):
"""Test get_modifications."""
assert fragments._get_modifications("[UNIMOD:2016]ABC[UNIMOD:4]") == ({0: 304.207146, 2: 57.02146}, 2, "ABC")
assert fragments._get_modifications("[UNIMOD:2016]-ABC[UNIMOD:4]") == ({0: 304.207146, 2: 57.02146}, 2, "ABC")


class TestComputeMasses(unittest.TestCase):
Expand Down Expand Up @@ -63,6 +63,11 @@ def test_compute_peptide_masses(self):
seq = "SEQUENC[UNIMOD:4]E"
self.assertEqual(fragments.compute_peptide_mass(seq), 1045.2561516699998)

def test_compute_peptide_masses_tmtpro(self):
"""Test computation of peptide masses with valid input and tmt tag."""
seq = "[UNIMOD:737]-SEQUENC[UNIMOD:4]E"
self.assertEqual(fragments.compute_peptide_mass(seq), 1274.41908367)

def test_compute_peptide_masses_with_invalid_syntax(self):
"""Negative testing of comuptation of peptide mass with unsupported syntax of mod string."""
seq = "SEQUEM(Ox.)CE"
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_mod_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def test_maxquant_to_internal_variable_dehydration_long(self):

def test_maxquant_to_internal_tmt(self):
"""Test maxquant_to_internal_tmt."""
fixed_mods = {"C": "C[UNIMOD:4]", "^_": "_[UNIMOD:737]", "K": "K[UNIMOD:737]"}
fixed_mods = {"C": "C[UNIMOD:4]", "^_": "_[UNIMOD:737]-", "K": "K[UNIMOD:737]"}
self.assertEqual(
mod.maxquant_to_internal(["_ABCDEFGHK_"], fixed_mods), ["[UNIMOD:737]ABC[UNIMOD:4]DEFGHK[UNIMOD:737]"]
mod.maxquant_to_internal(["_ABCDEFGHK_"], fixed_mods), ["[UNIMOD:737]-ABC[UNIMOD:4]DEFGHK[UNIMOD:737]"]
)

def test_maxquant_to_internal_silac(self):
Expand Down

0 comments on commit cbf31c8

Please sign in to comment.