Skip to content

Commit

Permalink
adapt unimod database loading, and bugfix modification mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurDeclercq committed Sep 2, 2024
1 parent fab22af commit 0969c35
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions mumble/mumble.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class PSMHandler:
"""Class that contains all information about the input file"""

def __init__(self, aa_combinations=0, fasta_file=None, mass_error=0.02) -> None:
def __init__(self, aa_combinations=0, fasta_file=None, mass_error=0.02, **kwargs) -> None:
"""
Constructor of the class.
Expand All @@ -39,6 +39,7 @@ def __init__(self, aa_combinations=0, fasta_file=None, mass_error=0.02) -> None:
add_aa_combinations=aa_combinations,
fasta_file=fasta_file,
)
self.psm_file_name = None

@staticmethod
def _find_mod_locations(peptidoform):
Expand Down Expand Up @@ -273,12 +274,12 @@ def write_modified_psm_list(self, psm_list, output_file=None, psm_file_type="tsv
"""

if self.psm_file_name and output_file is None:
output_file = self.psm_file_name.stem + "_modified"

elif not self.psm_file_name and output_file is None:
logger.warning("No output file specified")
output_file = "modified_psm_list"

elif output_file is None and self.psm_file_name:
output_file = self.psm_file_name.stem + "_modified"

logger.info(f"Writing modified PSM list to {output_file}")
write_file(psm_list=psm_list, filename=output_file, filetype=psm_file_type)

Expand Down Expand Up @@ -331,12 +332,20 @@ def get_unimod_database(self):

modifications = []
for mod in unimod_db.mods:
if (
not mod.username_of_poster == "unimod"
): # Do not include user submitted modifications
continue
name = mod.ex_code_name
if not name:
name = mod.code_name
if ("Xlink" in name) or ("plex" in name): # Do not include crosslinks
continue
monoisotopic_mass = mod.monoisotopic_mass
for specificity in mod.specificities:
classification = specificity.classification
if classification == "Isotopic label": # Do not include isotopic labels
continue
position = specificity.position_id
aa = specificity.amino_acid
modifications.append(
Expand Down Expand Up @@ -429,20 +438,23 @@ def get_localisation(
for loc, mod in self.check_protein_level(psm, modification_name)
]
)
elif restriction == "N-term" or restriction == "C-term":
if (
restriction == "N-term"
and (psm.peptidoform.properties["n_term"] is None)
and (psm.peptidoform.parsed_sequence[0][0] == residue)
):
loc_list.append(Localised_mass_shift("N-term", modification_name))

elif (
restriction == "C-term"
and (psm.peptidoform.properties["c_term"] is None)
and (psm.peptidoform.parsed_sequence[-1][0] == residue)
):
loc_list.append(Localised_mass_shift("C-term", modification_name))

elif (
restriction == "N-term"
and (psm.peptidoform.properties["n_term"] is None)
and (psm.peptidoform.parsed_sequence[0][0] == residue)
):
loc_list.append(Localised_mass_shift("N-term", modification_name))

elif (
restriction == "C-term"
and (psm.peptidoform.properties["c_term"] is None)
and (psm.peptidoform.parsed_sequence[-1][0] == residue)
):
loc_list.append(Localised_mass_shift("C-term", modification_name))
else:
continue

elif residue in amino_acids_peptide:
loc_list.extend(
Expand Down

0 comments on commit 0969c35

Please sign in to comment.