Skip to content

Commit

Permalink
fix encoding problems: using z_r everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
picciama committed Aug 9, 2024
1 parent 839b514 commit 5b5eb20
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 87 deletions.
79 changes: 45 additions & 34 deletions spectrum_fundamentals/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,6 @@
# we do not annotate fragments wth charge 3+. All fragmets with charge 3+ convert to -1


#############
# ION TYPES #
#############
FORWARD_IONS = ["a", "b", "c"]
BACKWARDS_IONS = ["x", "y", "z", "z●"]
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●,c
"ECD": [BACKWARDS_IONS[-1], FORWARD_IONS[2]], # z●,c
"ETHCD": [BACKWARDS_IONS[1], FORWARD_IONS[1], BACKWARDS_IONS[-1], FORWARD_IONS[2]], # y,b,z●,c
"ETCID": [BACKWARDS_IONS[1], FORWARD_IONS[1], BACKWARDS_IONS[-1], FORWARD_IONS[2]], # y,b,z●,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●,c
"ECD": [BACKWARDS_IONS[-1], FORWARD_IONS[2]], # z●,c
"ETHCD": [BACKWARDS_IONS[1], BACKWARDS_IONS[-1]] + FORWARD_IONS[1:], # y,z●,b,c
"ETCID": [BACKWARDS_IONS[1], BACKWARDS_IONS[-1]] + FORWARD_IONS[1:], # y,z●,b,c
"UVPD": BACKWARDS_IONS[:-1] + FORWARD_IONS, # y,z,x,b,c,a
}

#############
# ALPHABETS #
#############
Expand Down Expand Up @@ -449,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"],
}
15 changes: 2 additions & 13 deletions spectrum_fundamentals/fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ATOM_MASSES,
FRAGMENTATION_TO_IONS_BY_DIRECTION,
FRAGMENTATION_TO_IONS_BY_PAIRS,
ION_DELTAS,
MOD_MASSES,
PARTICLE_MASSES,
)
Expand Down Expand Up @@ -132,19 +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"],
"z●": ATOM_MASSES["O"] - ATOM_MASSES["N"],
}

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
36 changes: 18 additions & 18 deletions tests/unit_tests/data/fragments_meta_data_etd_ecd.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"max_mass": 39.034494842950046
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 1,
"charge": 3,
"mass": 44.68542100033333,
Expand All @@ -24,7 +24,7 @@
"max_mass": 58.048093958160386
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 1,
"charge": 2,
"mass": 66.524493267,
Expand All @@ -40,7 +40,7 @@
"max_mass": 82.04955279357003
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 2,
"charge": 3,
"mass": 83.02773533366667,
Expand All @@ -64,7 +64,7 @@
"max_mass": 115.08889130379143
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 3,
"charge": 3,
"mass": 120.72242333366667,
Expand All @@ -80,15 +80,15 @@
"max_mass": 122.57068088409038
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 2,
"charge": 2,
"mass": 124.037964767,
"min_mass": 124.03548400770467,
"max_mass": 124.04044552629534
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 1,
"charge": 1,
"mass": 132.041710067,
Expand All @@ -104,7 +104,7 @@
"max_mass": 148.08435446319004
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 4,
"charge": 3,
"mass": 154.40498300033335,
Expand All @@ -120,7 +120,7 @@
"max_mass": 171.0980334117304
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 3,
"charge": 2,
"mass": 180.579996767,
Expand All @@ -136,7 +136,7 @@
"max_mass": 185.77979635695002
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 5,
"charge": 3,
"mass": 186.75590433366668,
Expand All @@ -160,15 +160,15 @@
"max_mass": 224.12287753657
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 6,
"charge": 3,
"mass": 229.77010200033337,
"min_mass": 229.76550659829337,
"max_mass": 229.77469740237336
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 4,
"charge": 2,
"mass": 231.10383626700002,
Expand All @@ -184,7 +184,7 @@
"max_mass": 244.13406515565143
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 2,
"charge": 1,
"mass": 247.068653067,
Expand All @@ -200,7 +200,7 @@
"max_mass": 278.1660462291604
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 5,
"charge": 2,
"mass": 279.63021826700003,
Expand All @@ -224,15 +224,15 @@
"max_mass": 341.18877021093147
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 6,
"charge": 2,
"mass": 344.15151476700004,
"min_mass": 344.1446317367047,
"max_mass": 344.1583977972954
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 3,
"charge": 1,
"mass": 360.152717067,
Expand All @@ -248,7 +248,7 @@
"max_mass": 442.23847016451145
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 4,
"charge": 1,
"mass": 461.20039606700004,
Expand All @@ -264,7 +264,7 @@
"max_mass": 555.3247958457914
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 5,
"charge": 1,
"mass": 558.2531600670001,
Expand All @@ -280,7 +280,7 @@
"max_mass": 670.3540393846513
},
{
"ion_type": "z●",
"ion_type": "z_r",
"no": 6,
"charge": 1,
"mass": 687.2957530670001,
Expand Down
Loading

0 comments on commit 5b5eb20

Please sign in to comment.