Skip to content

Commit

Permalink
Merge pull request #132 from wilhelm-lab/feature/z_radicals
Browse files Browse the repository at this point in the history
Feature/z radicals
  • Loading branch information
picciama authored Aug 9, 2024
2 parents 39c18f5 + 5b5eb20 commit 0efcfc0
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 184 deletions.
47 changes: 47 additions & 0 deletions spectrum_fundamentals/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
VEC_LENGTH_CMS2 = (SEQ_LEN - 1) * 2 * 3 * 2
# peptide of length 30 can have 29 b, y, b_short, y_short, b_long and y_long ions, each with charge 1+, 2+ and 3+
# we do not annotate fragments wth charge 3+. All fragmets with charge 3+ convert to -1


#############
# ALPHABETS #
#############
Expand Down Expand Up @@ -413,3 +415,48 @@ class RescoreType(Enum):

PROSIT = "prosit"
ANDROMEDA = "andromeda"


#############
# ION TYPES #
#############
FORWARD_IONS = ["a", "b", "c"]
BACKWARDS_IONS = ["x", "y", "z", "z_r"] #
IONS = FORWARD_IONS + BACKWARDS_IONS

FRAGMENTATION_TO_IONS_BY_PAIRS = {
"HCD": [BACKWARDS_IONS[1], FORWARD_IONS[1]], # y,b
"CID": [BACKWARDS_IONS[1], FORWARD_IONS[1]], # y,b
"ETD": [BACKWARDS_IONS[-1], FORWARD_IONS[2]], # z_r,c
"ECD": [BACKWARDS_IONS[-1], FORWARD_IONS[2]], # z_r,c
"ETHCD": [BACKWARDS_IONS[1], FORWARD_IONS[1], BACKWARDS_IONS[-1], FORWARD_IONS[2]], # y,b,z_r,c
"ETCID": [BACKWARDS_IONS[1], FORWARD_IONS[1], BACKWARDS_IONS[-1], FORWARD_IONS[2]], # y,b,z_r,c
"UVPD": [
BACKWARDS_IONS[0],
FORWARD_IONS[0],
BACKWARDS_IONS[1],
FORWARD_IONS[1],
BACKWARDS_IONS[2],
FORWARD_IONS[2],
], # y,b,z,c,x,a
}

FRAGMENTATION_TO_IONS_BY_DIRECTION = {
"HCD": [BACKWARDS_IONS[1], FORWARD_IONS[1]], # y,b
"CID": [BACKWARDS_IONS[1], FORWARD_IONS[1]], # y,b
"ETD": [BACKWARDS_IONS[-1], FORWARD_IONS[2]], # z_r,c
"ECD": [BACKWARDS_IONS[-1], FORWARD_IONS[2]], # z_r,c
"ETHCD": [BACKWARDS_IONS[1], BACKWARDS_IONS[-1]] + FORWARD_IONS[1:], # y,z_r,b,c
"ETCID": [BACKWARDS_IONS[1], BACKWARDS_IONS[-1]] + FORWARD_IONS[1:], # y,z_r,b,c
"UVPD": BACKWARDS_IONS[:-1] + FORWARD_IONS, # y,z,x,b,c,a
}

ION_DELTAS = {
"a": -ATOM_MASSES["O"] - ATOM_MASSES["C"],
"b": 0.0,
"c": 3 * ATOM_MASSES["H"] + ATOM_MASSES["N"],
"x": 2 * ATOM_MASSES["O"] + ATOM_MASSES["C"],
"y": ATOM_MASSES["O"] + 2 * ATOM_MASSES["H"],
"z": ATOM_MASSES["O"] - ATOM_MASSES["N"] - ATOM_MASSES["H"],
"z_r": ATOM_MASSES["O"] - ATOM_MASSES["N"],
}
47 changes: 16 additions & 31 deletions spectrum_fundamentals/fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
import numpy as np
import pandas as pd

from .constants import AA_MASSES, ATOM_MASSES, MOD_MASSES, PARTICLE_MASSES
from .constants import (
AA_MASSES,
ATOM_MASSES,
FRAGMENTATION_TO_IONS_BY_DIRECTION,
FRAGMENTATION_TO_IONS_BY_PAIRS,
ION_DELTAS,
MOD_MASSES,
PARTICLE_MASSES,
)
from .mod_string import internal_without_mods

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -95,16 +103,10 @@ def retrieve_ion_types(fragmentation_method: str) -> List[str]:
: 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:
ions = FRAGMENTATION_TO_IONS_BY_PAIRS.get(fragmentation_method, [])
if not ions:
raise ValueError(f"Unknown fragmentation method provided: {fragmentation_method}")
return ions


def retrieve_ion_types_for_peak_initialization(fragmentation_method: str) -> List[str]:
Expand All @@ -118,16 +120,10 @@ def retrieve_ion_types_for_peak_initialization(fragmentation_method: str) -> Lis
: 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", "z", "b", "c"]
elif fragmentation_method == "UVPD":
return ["x", "y", "z", "a", "b", "c"]
else:
ions = FRAGMENTATION_TO_IONS_BY_DIRECTION.get(fragmentation_method, [])
if not ions:
raise ValueError(f"Unknown fragmentation method provided: {fragmentation_method}")
return ions


def get_ion_delta(ion_types: List[str]) -> np.ndarray:
Expand All @@ -137,18 +133,7 @@ def get_ion_delta(ion_types: List[str]) -> np.ndarray:
:param ion_types: type of ions for which mass should be calculated
:return: numpy array with masses of the ions
"""
ion_type_offsets = {
"a": -ATOM_MASSES["O"] - ATOM_MASSES["C"],
"b": 0.0,
"c": 3 * ATOM_MASSES["H"] + ATOM_MASSES["N"],
"x": 2 * ATOM_MASSES["O"] + ATOM_MASSES["C"],
"y": ATOM_MASSES["O"] + 2 * ATOM_MASSES["H"],
"z": ATOM_MASSES["O"] - ATOM_MASSES["N"] - ATOM_MASSES["H"],
}
# I think list comprehension is fastest way
deltas = np.array([ion_type_offsets[ion_type] for ion_type in ion_types]).reshape(len(ion_types), 1)

return deltas
return np.array([ION_DELTAS[ion_type] for ion_type in ion_types]).reshape(len(ion_types), 1)


def initialize_peaks(
Expand Down
Loading

0 comments on commit 0efcfc0

Please sign in to comment.