Skip to content

Commit

Permalink
Merge pull request #233 from MannLabs/linting_I
Browse files Browse the repository at this point in the history
Linting i
  • Loading branch information
mschwoer authored Nov 22, 2024
2 parents f2a4154 + dbb5731 commit a666112
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 109 deletions.
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ repos:
rev: v0.4.0
hooks:
- id: ruff-format
# running ruff with rules in pyproject.toml (all files, limited rules)
- id: ruff
args:
- "--fix"

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3 # newer version -> stricter
hooks:
- id: ruff
# running ruff again with rules in ruff-lint-psm-readers.toml (specific files, all rules)
args:
- "--config"
- "ruff-lint-psm-readers.toml"
- "--fix"
exclude: .bumpversion.cfg
8 changes: 2 additions & 6 deletions alphabase/psm_reader/alphapept_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

@numba.njit
def parse_ap(precursor):
"""
Parser to parse peptide strings
"""
"""Parser to parse peptide strings"""
items = precursor.split("_")
decoy = 1 if len(items) == 3 else 0
modseq = items[0]
Expand Down Expand Up @@ -58,9 +56,7 @@ def __init__(
keep_decoy=False,
**kwargs,
):
"""
Reading PSMs from alphapept's *.ms_data.hdf
"""
"""Reading PSMs from alphapept's *.ms_data.hdf"""
super().__init__(
column_mapping=column_mapping,
modification_mapping=modification_mapping,
Expand Down
9 changes: 4 additions & 5 deletions alphabase/psm_reader/dia_psm_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SpectronautReader(MaxQuantReader):
----------
csv_sep : str, optional
Delimiter for TSV/CSV, by default '\t'
"""

def __init__(
Expand Down Expand Up @@ -74,9 +75,7 @@ def __init__(
mod_seq_columns=psm_reader_yaml["spectronaut"]["mod_seq_columns"],
**kwargs,
):
"""
SWATH or OpenSWATH library, similar to `SpectronautReader`
"""
"""SWATH or OpenSWATH library, similar to `SpectronautReader`"""
super().__init__(
column_mapping=column_mapping,
modification_mapping=modification_mapping,
Expand All @@ -100,8 +99,7 @@ def __init__(
rt_unit="minute",
**kwargs,
):
"""
Also similar to `MaxQuantReader`,
"""Also similar to `MaxQuantReader`,
but different in column_mapping and modificatin_mapping
"""
super().__init__(
Expand Down Expand Up @@ -143,6 +141,7 @@ class SpectronautReportReader(MaxQuantReader):
----------
csv_sep : str, optional
Delimiter for TSV/CSV, by default ','
"""

def __init__(
Expand Down
5 changes: 3 additions & 2 deletions alphabase/psm_reader/maxquant_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def parse_mod_seq(
str: modification sites, separated by ';'.
0 for N-term; -1 for C-term; 1 to N for normal modifications.
"""
PeptideModSeq = modseq
underscore_for_ncterm = modseq[0] == "_"
Expand Down Expand Up @@ -170,6 +171,7 @@ def __init__(
mod_seq_columns : list, optional
The columns to find modified sequences,
by default ['Modified sequence']
"""
if mod_seq_columns is None:
mod_seq_columns = ["Modified sequence"]
Expand Down Expand Up @@ -211,8 +213,7 @@ def _add_all_unimod(self):
self.modification_mapping[mod_name] = [unimod]

def _extend_mod_brackets(self):
"""update modification_mapping to include different bracket types."""

"""Update modification_mapping to include different bracket types."""
for key, mod_list in list(self.modification_mapping.items()):
mod_set = set(mod_list)
# extend bracket types of modifications
Expand Down
2 changes: 1 addition & 1 deletion alphabase/psm_reader/msfragger_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import pandas as pd
import pyteomics.pepxml as pepxml
from pyteomics import pepxml

from alphabase.constants.aa import AA_ASCII_MASS
from alphabase.constants.atom import MASS_H, MASS_O
Expand Down
22 changes: 10 additions & 12 deletions alphabase/psm_reader/pfind_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,23 @@ def convert_one_pFind_mod(mod):
site = mod[(idx + 1) : -1]
if len(site) == 1:
return name + "@" + site
elif site == "AnyN-term":
if site == "AnyN-term":
return name + "@" + "Any_N-term"
elif site == "ProteinN-term":
if site == "ProteinN-term":
return name + "@" + "Protein_N-term"
elif site.startswith("AnyN-term"):
if site.startswith("AnyN-term"):
return name + "@" + site[-1] + "^Any_N-term"
elif site.startswith("ProteinN-term"):
if site.startswith("ProteinN-term"):
return name + "@" + site[-1] + "^Protein_N-term"
elif site == "AnyC-term":
if site == "AnyC-term":
return name + "@" + "Any_C-term"
elif site == "ProteinC-term":
if site == "ProteinC-term":
return name + "@" + "Protein_C-term"
elif site.startswith("AnyC-term"):
if site.startswith("AnyC-term"):
return name + "@" + site[-1] + "^Any_C-term"
elif site.startswith("ProteinC-term"):
if site.startswith("ProteinC-term"):
return name + "@" + site[-1] + "^Protein_C-term"
else:
return None
return None


def translate_pFind_mod(mod_str):
Expand All @@ -50,8 +49,7 @@ def translate_pFind_mod(mod_str):
mod = convert_one_pFind_mod(mod)
if not mod or mod not in ap_mod.MOD_INFO_DICT:
return pd.NA
else:
ret_mods.append(mod)
ret_mods.append(mod)
return ";".join(ret_mods)


Expand Down
Loading

0 comments on commit a666112

Please sign in to comment.