Skip to content

Commit

Permalink
fix pre-commit issues
Browse files Browse the repository at this point in the history
  • Loading branch information
WassimG committed Sep 28, 2024
1 parent 15692ac commit cdeb22c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
14 changes: 7 additions & 7 deletions spectrum_fundamentals/annotation/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def annotate_spectra(
unit_mass_tolerance: Optional[str] = None,
custom_mods: Optional[Dict[str, float]] = None,
fragmentation_method: str = "HCD",
annotate_neutral_loss: Optional[bool] = False
annotate_neutral_loss: Optional[bool] = False,
) -> pd.DataFrame:
"""
Annotate a set of spectra.
Expand All @@ -150,7 +150,7 @@ def annotate_spectra(
:param unit_mass_tolerance: unit for the mass tolerance (da or ppm)
:param fragmentation_method: fragmentation method that was used
:param custom_mods: mapping of custom UNIMOD string identifiers ('[UNIMOD:xyz]') to their mass
:param annotate_neutral_losses: flag to indicate whether to annotate neutral losses or not
:param annotate_neutral_loss: flag to indicate whether to annotate neutral losses or not
:return: a Pandas DataFrame containing the annotated spectra with meta data
"""
raw_file_annotations = []
Expand All @@ -163,7 +163,7 @@ def annotate_spectra(
unit_mass_tolerance,
fragmentation_method=fragmentation_method,
custom_mods=custom_mods,
annotate_neutral_losses=annotate_neutral_loss
annotate_neutral_losses=annotate_neutral_loss,
)
if not results:
continue
Expand Down Expand Up @@ -363,7 +363,7 @@ def parallel_annotate(
unit_mass_tolerance: Optional[str] = None,
custom_mods: Optional[Dict[str, float]] = None,
fragmentation_method: str = "HCD",
annotate_neutral_losses: Optional[bool] = False
annotate_neutral_losses: Optional[bool] = False,
) -> Optional[
Union[
Tuple[np.ndarray, np.ndarray, float, int, int, int],
Expand Down Expand Up @@ -401,7 +401,7 @@ def parallel_annotate(
unit_mass_tolerance,
fragmentation_method=fragmentation_method,
custom_mods=custom_mods,
add_neutral_losses= annotate_neutral_losses
add_neutral_losses=annotate_neutral_losses,
)

if (spectrum[index_columns["PEPTIDE_LENGTH_A"]] > 30) or (spectrum[index_columns["PEPTIDE_LENGTH_B"]] > 30):
Expand All @@ -418,7 +418,7 @@ def _annotate_linear_spectrum(
unit_mass_tolerance: Optional[str],
custom_mods: Optional[Dict[str, float]] = None,
fragmentation_method: str = "HCD",
add_neutral_losses: Optional[bool] = False
add_neutral_losses: Optional[bool] = False,
):
"""
Annotate a linear peptide spectrum.
Expand All @@ -444,7 +444,7 @@ def _annotate_linear_spectrum(
unit_mass_tolerance=unit_mass_tolerance,
fragmentation_method=fragmentation_method,
custom_mods=custom_mods,
add_neutral_losses= add_neutral_losses
add_neutral_losses=add_neutral_losses,
)
matched_peaks, count_annotated_nl = match_peaks(
fragments_meta_data,
Expand Down
8 changes: 4 additions & 4 deletions spectrum_fundamentals/fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ def _get_neutral_losses(peptide_sequence, modifications):
if aa in c.AA_Neutral_losses:
if i in modifications:
"""if aa == "M" and modifications[i] == 15.9949146:
nl_b_ions = _add_nl(c.AA_Neutral_losses["M[UNIMOD:35]"], nl_b_ions, i, sequence_length - 1)
nl_y_ions = _add_nl(
c.AA_Neutral_losses["M[UNIMOD:35]"], nl_y_ions, sequence_length - i - 1, sequence_length - 1
)"""
nl_b_ions = _add_nl(c.AA_Neutral_losses["M[UNIMOD:35]"], nl_b_ions, i, sequence_length - 1)
nl_y_ions = _add_nl(
c.AA_Neutral_losses["M[UNIMOD:35]"], nl_y_ions, sequence_length - i - 1, sequence_length - 1
)"""
if aa == "R" and modifications[i] == 0.984016:
nl_b_ions = _add_nl(c.Mod_Neutral_losses["R[UNIMOD:7]"], nl_b_ions, i, sequence_length - 1)
nl_y_ions = _add_nl(
Expand Down
2 changes: 1 addition & 1 deletion spectrum_fundamentals/metrics/percolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def calc(self):
self.metrics_val["ANNOTATED_NL_COUNT"] = self.metadata["ANNOTATED_NL_COUNT"]
self.metrics_val["EXPECTED_NL_COUNT"] = self.metadata["EXPECTED_NL_COUNT"]
if self.drop_miss_cleavage_flag:
self.metrics_val.drop(columns=["missedCleavages","KR"],inplace=True)
self.metrics_val.drop(columns=["missedCleavages", "KR"], inplace=True)
if self.xl:
self.metrics_val["collision_energy_aligned"] = self.metadata["COLLISION_ENERGY"] / 100.0
else:
Expand Down
6 changes: 3 additions & 3 deletions spectrum_fundamentals/mod_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,11 @@ def add_permutations(
whether the modification mass was mistakenly picked as the monoisotopic peak. Mainly used for Citrullination.
:return: list of possible sequence permutations
"""
modified_sequence = modified_sequence.replace('UNIMOD','unimod')
modified_sequence = modified_sequence.replace("UNIMOD", "unimod")
sequence = modified_sequence.replace("[unimod:" + str(unimod_id) + "]", "")
modifications = len(re.findall("unimod:" + str(unimod_id), modified_sequence))
if modifications == 0:
modified_sequence = modified_sequence.replace('unimod','UNIMOD')
modified_sequence = modified_sequence.replace("unimod", "UNIMOD")
return [modified_sequence]
possible_positions = [i for i, ltr in enumerate(sequence) if ltr in residues]
possible_positions.sort(reverse=True)
Expand All @@ -387,7 +387,7 @@ def add_permutations(
modified_sequence = (
modified_sequence[: index + 1] + "[unimod:" + str(unimod_id) + "]" + modified_sequence[index + 1 :]
)
modified_sequence = modified_sequence.replace('unimod','UNIMOD')
modified_sequence = modified_sequence.replace("unimod", "UNIMOD")
modified_sequences_comb.append(modified_sequence)
return modified_sequences_comb

Expand Down
40 changes: 20 additions & 20 deletions tests/unit_tests/test_mod_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,45 +346,45 @@ def test_no_modifications(self):

def test_single_modification(self):
"""Test case with a single modification."""
modified_sequence = "P[unimod:123]EPTIDE"
modified_sequence = "P[UNIMOD:123]EPTIDE"
unimod_id = 123
residues = ["P", "E"]
result = mod.add_permutations(modified_sequence, unimod_id, residues)
expected_result = ["PEPTIDE[unimod:123]", "PEP[unimod:123]TIDE", "PE[unimod:123]PTIDE", "P[unimod:123]EPTIDE"]
expected_result = ["PEPTIDE[UNIMOD:123]", "PEP[UNIMOD:123]TIDE", "PE[UNIMOD:123]PTIDE", "P[UNIMOD:123]EPTIDE"]
self.assertEqual(result, expected_result)

def test_multiple_modifications(self):
"""Test case with multiple modifications."""
modified_sequence = "PEP[unimod:123]TIDE[unimod:123]"
modified_sequence = "PEP[UNIMOD:123]TIDE[UNIMOD:123]"
unimod_id = 123
residues = ["P", "E"]
result = mod.add_permutations(modified_sequence, unimod_id, residues)
expected_result = [
"PEP[unimod:123]TIDE[unimod:123]",
"PE[unimod:123]PTIDE[unimod:123]",
"P[unimod:123]EPTIDE[unimod:123]",
"PE[unimod:123]P[unimod:123]TIDE",
"P[unimod:123]EP[unimod:123]TIDE",
"P[unimod:123]E[unimod:123]PTIDE",
"PEP[UNIMOD:123]TIDE[UNIMOD:123]",
"PE[UNIMOD:123]PTIDE[UNIMOD:123]",
"P[UNIMOD:123]EPTIDE[UNIMOD:123]",
"PE[UNIMOD:123]P[UNIMOD:123]TIDE",
"P[UNIMOD:123]EP[UNIMOD:123]TIDE",
"P[UNIMOD:123]E[UNIMOD:123]PTIDE",
]
self.assertEqual(result, expected_result)

def test_check_monoisotopic_peak_enabled(self):
"""Test case with check_monoisotopic_peak flag enabled."""
modified_sequence = "PEP[unimod:123]TID[unimod:123]E"
modified_sequence = "PEP[UNIMOD:123]TID[UNIMOD:123]E"
unimod_id = 123
residues = ["P", "E"]
result = mod.add_permutations(modified_sequence, unimod_id, residues, allow_one_less_modification=True)
expected_result = [
"PEP[unimod:123]TIDE[unimod:123]",
"PE[unimod:123]PTIDE[unimod:123]",
"P[unimod:123]EPTIDE[unimod:123]",
"PE[unimod:123]P[unimod:123]TIDE",
"P[unimod:123]EP[unimod:123]TIDE",
"P[unimod:123]E[unimod:123]PTIDE",
"PEPTIDE[unimod:123]",
"PEP[unimod:123]TIDE",
"PE[unimod:123]PTIDE",
"P[unimod:123]EPTIDE",
"PEP[UNIMOD:123]TIDE[UNIMOD:123]",
"PE[UNIMOD:123]PTIDE[UNIMOD:123]",
"P[UNIMOD:123]EPTIDE[UNIMOD:123]",
"PE[UNIMOD:123]P[UNIMOD:123]TIDE",
"P[UNIMOD:123]EP[UNIMOD:123]TIDE",
"P[UNIMOD:123]E[UNIMOD:123]PTIDE",
"PEPTIDE[UNIMOD:123]",
"PEP[UNIMOD:123]TIDE",
"PE[UNIMOD:123]PTIDE",
"P[UNIMOD:123]EPTIDE",
]
self.assertEqual(result, expected_result)

0 comments on commit cdeb22c

Please sign in to comment.