Skip to content

Commit

Permalink
Merge pull request #238 from MannLabs/linting_VI
Browse files Browse the repository at this point in the history
Linting vi
  • Loading branch information
mschwoer authored Jan 9, 2025
2 parents 9e0e1eb + 5645032 commit 08fcc15
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 38 deletions.
5 changes: 5 additions & 0 deletions alphabase/psm_reader/alphapept_reader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Reader for AlphaPept's *.ms_data.hdf files."""

from pathlib import Path
from typing import Optional, Tuple

Expand Down Expand Up @@ -48,6 +50,8 @@ def parse_ap(precursor: str) -> Tuple[str, str, str, str, int]:


class AlphaPeptReader(PSMReaderBase):
"""Reader for AlphaPept's *.ms_data.hdf files."""

def __init__(
self,
*,
Expand Down Expand Up @@ -105,4 +109,5 @@ def _load_modifications(self, df: pd.DataFrame) -> None:


def register_readers() -> None:
"""Register readers for AlphaPept's *.ms_data.hdf files."""
psm_reader_provider.register_reader("alphapept", AlphaPeptReader)
13 changes: 10 additions & 3 deletions alphabase/psm_reader/dia_psm_reader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Readers for Spectronaut's output library and reports, Swath data and DIANN data."""

from typing import List, Optional

import numpy as np
Expand Down Expand Up @@ -33,6 +35,7 @@ def __init__( # noqa: PLR0913 many arguments in function definition
rt_unit: str = "minute",
**kwargs,
):
"""Initialize SpectronautReader."""
if mod_seq_columns is None:
mod_seq_columns = psm_reader_yaml["spectronaut"]["mod_seq_columns"]

Expand Down Expand Up @@ -69,6 +72,8 @@ def _load_file(self, filename: str) -> pd.DataFrame:


class SwathReader(SpectronautReader):
"""Reader for SWATH or OpenSWATH library TSV/CSV."""

def __init__( # noqa: PLR0913 many arguments in function definition
self,
*,
Expand Down Expand Up @@ -96,6 +101,8 @@ def __init__( # noqa: PLR0913 many arguments in function definition


class DiannReader(SpectronautReader):
"""Reader for DIANN data."""

def __init__( # noqa: PLR0913 many arguments in function definition
self,
*,
Expand All @@ -107,9 +114,7 @@ def __init__( # noqa: PLR0913 many arguments in function definition
rt_unit: str = "minute",
**kwargs,
):
"""Also similar to `MaxQuantReader`,
but different in column_mapping and modification_mapping.
"""
"""Similar to `SpectronautReader` but different in column_mapping and modification_mapping."""
super().__init__(
column_mapping=column_mapping,
modification_mapping=modification_mapping,
Expand Down Expand Up @@ -161,6 +166,7 @@ def __init__( # noqa: PLR0913 many arguments in function definition
rt_unit: str = "minute",
**kwargs,
):
"""Initialize SpectronautReportReader."""
super().__init__(
column_mapping=column_mapping,
modification_mapping=modification_mapping,
Expand Down Expand Up @@ -190,6 +196,7 @@ def _load_file(self, filename: str) -> pd.DataFrame:


def register_readers() -> None:
"""Register readers for Spectronaut's output library and reports, Swath data and DIANN data."""
psm_reader_provider.register_reader("spectronaut", SpectronautReader)
psm_reader_provider.register_reader("speclib_tsv", SpectronautReader)
psm_reader_provider.register_reader("openswath", SwathReader)
Expand Down
3 changes: 3 additions & 0 deletions alphabase/psm_reader/keys.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""Constants for accessing the columns of a PSM dataframe."""

from typing import Any, List, NoReturn


class ConstantsClass(type):
"""A metaclass for classes that should only contain string constants."""

def __setattr__(cls, name: Any, value: Any) -> NoReturn: # noqa: ANN401
"""Raise an error when trying to set an attribute."""
raise TypeError("Constants class cannot be modified")

def get_values(cls) -> List[str]:
Expand Down
14 changes: 12 additions & 2 deletions alphabase/psm_reader/maxquant_reader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Reader for MaxQuant data."""

import copy
import warnings
from typing import List, Optional
Expand Down Expand Up @@ -32,6 +34,7 @@
def replace_parentheses_with_brackets(
modseq: str,
) -> str:
"""Replace parentheses with brackets in the modified sequence."""
mod_depth = 0
for i, aa in enumerate(modseq):
if aa == "(":
Expand Down Expand Up @@ -66,9 +69,9 @@ def parse_mod_seq(
separator to indicate the modification section.
Defaults to '()'
fixed_C : bool
fixed_C57 : bool
If Carbamidomethyl@C is a fixed modification
and not displayed in the sequence. Defaults to True for MaxQuant.
and not displayed in the sequence. Defaults to True.
Returns
-------
Expand Down Expand Up @@ -132,6 +135,8 @@ def parse_mod_seq(


class MaxQuantReader(PSMReaderBase):
"""Reader for MaxQuant data."""

def __init__( # noqa: PLR0913 many arguments in function definition
self,
*,
Expand Down Expand Up @@ -172,6 +177,9 @@ def __init__( # noqa: PLR0913 many arguments in function definition
The columns to find modified sequences,
by default ['Modified sequence']
**kwargs : dict
deprecated
"""
if mod_seq_columns is None:
mod_seq_columns = [
Expand Down Expand Up @@ -205,6 +213,7 @@ def _init_modification_mapping(self) -> None:
def set_modification_mapping(
self, modification_mapping: Optional[dict] = None
) -> None:
"""Set modification mapping."""
super().set_modification_mapping(modification_mapping)
self._add_all_unimod()
self._extend_mod_brackets()
Expand Down Expand Up @@ -300,4 +309,5 @@ def _load_modifications(self, origin_df: pd.DataFrame) -> None:


def register_readers() -> None:
"""Register MaxQuant reader."""
psm_reader_provider.register_reader("maxquant", MaxQuantReader)
8 changes: 8 additions & 0 deletions alphabase/psm_reader/msfragger_reader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""MSFragger reader."""

from typing import List, Optional, Tuple

import numpy as np
Expand Down Expand Up @@ -81,14 +83,19 @@ def _get_mods_from_masses( # noqa: PLR0912, C901 too many branches, too complex


class MSFragger_PSM_TSV_Reader(PSMReaderBase): # noqa: N801 name should use CapWords convention TODO: refactor
"""Reader for MSFragger's psm.tsv file."""

def __init__(
self,
**kwargs,
):
"""Constructor."""
raise NotImplementedError("MSFragger_PSM_TSV_Reader for psm.tsv")


class MSFraggerPepXML(PSMReaderBase):
"""Reader for MSFragger's pep.xml file."""

def __init__( # noqa: PLR0913 many arguments in function definition
self,
*,
Expand Down Expand Up @@ -182,6 +189,7 @@ def _post_process(self) -> None:


def register_readers() -> None:
"""Register MSFragger readers."""
psm_reader_provider.register_reader("msfragger_psm_tsv", MSFragger_PSM_TSV_Reader)
psm_reader_provider.register_reader("msfragger", MSFragger_PSM_TSV_Reader)
psm_reader_provider.register_reader("msfragger_pepxml", MSFraggerPepXML)
9 changes: 9 additions & 0 deletions alphabase/psm_reader/pfind_reader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""pFind reader."""

from typing import Optional, Tuple, Union

import numpy as np
Expand Down Expand Up @@ -49,6 +51,7 @@ def _convert_one_pfind_mod(mod: str) -> Optional[str]: # noqa: C901 too comple


def translate_pFind_mod(mod_str: str) -> Union[str, NAType]: # noqa: N802 name `get_pFind_mods` should be lowercase TODO: used by peptdeep
"""Translate pFind modification string."""
if not mod_str:
return ""
ret_mods = []
Expand All @@ -61,6 +64,7 @@ def translate_pFind_mod(mod_str: str) -> Union[str, NAType]: # noqa: N802 name


def get_pFind_mods(pfind_mod_str: str) -> Tuple[str, str]: # noqa: N802 name `get_pFind_mods` should be lowercase TODO: used by peptdeep
"""Parse pFind modification string."""
pfind_mod_str = pfind_mod_str.strip(";")
if not pfind_mod_str:
return "", ""
Expand All @@ -79,6 +83,7 @@ def get_pFind_mods(pfind_mod_str: str) -> Tuple[str, str]: # noqa: N802 name `g


def parse_pfind_protein(protein: str, *, keep_reverse: bool = True) -> str:
"""Parse pFind protein string."""
proteins = protein.strip("/").split("/")
return ";".join(
[
Expand All @@ -90,6 +95,8 @@ def parse_pfind_protein(protein: str, *, keep_reverse: bool = True) -> str:


class pFindReader(PSMReaderBase): # noqa: N801 name `pFindReader` should use CapWords convention TODO: used by peptdeep, alpharaw
"""Reader for pFind's *.txt files."""

def __init__(
self,
*,
Expand All @@ -99,6 +106,7 @@ def __init__(
keep_decoy: bool = False,
**kwargs,
):
"""Reading PSMs from pFind's *.txt."""
super().__init__(
column_mapping=column_mapping,
modification_mapping=modification_mapping,
Expand Down Expand Up @@ -151,5 +159,6 @@ def _load_modifications(self, pfind_df: pd.DataFrame) -> None:


def register_readers() -> None:
"""Register pFind readers."""
psm_reader_provider.register_reader("pfind", pFindReader)
psm_reader_provider.register_reader("pfind3", pFindReader)
Loading

0 comments on commit 08fcc15

Please sign in to comment.