Skip to content

Commit f5e97a8

Browse files
linting + actions
1 parent ed148be commit f5e97a8

16 files changed

+398
-132
lines changed

pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,11 @@ version = {attr = "peptacular.__version__"}
3636
[tool.pylint]
3737
max-line-length = 120
3838
fail-under = 9.5
39-
good-names = ["db", "i", "j", "aa", "n", "k", "p", "Na", "Nb", "Nc", "Nx", "Ny", "Nz", "mz"]
40-
extension-pkg-whitelist='pydantic'
39+
good-names = ["db", "i", "j", "aa", "n", "k", "p", "Na", "Nb", "Nc", "Nx", "Ny", "Nz", "mz", "k", "v",
40+
"f", "d", "m", "s", "r"]
41+
extension-pkg-whitelist = 'pydantic'
42+
max-branches = 50 # Increase the number of allowed branches
43+
max-locals = 30 # Increase the number of allowed local variables
44+
max-attributes = 50 # Increase the number of allowed attributes
45+
max-statements = 100 # Increase the number of allowed statements in a function
46+
max-args = 10 # Increase the number of allowed arguments in a function

src/peptacular/digestion.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
"""
1616
from dataclasses import dataclass
17-
from typing import Union, List, Optional, TypeAlias, Literal, Tuple, Generator, Iterable
17+
from typing import Union, List, Optional, Literal, Tuple, Generator, Iterable
1818

1919
from peptacular.spans import Span
2020
from peptacular.constants import PROTEASES_COMPILED
@@ -23,7 +23,7 @@
2323
from peptacular.sequence.sequence_funcs import sequence_to_annotation
2424
from peptacular.util import get_regex_match_indices
2525

26-
DigestReturnType: TypeAlias = Literal["str", "annotation", "span", "str-span", "annotation-span"]
26+
DigestReturnType = Literal["str", "annotation", "span", "str-span", "annotation-span"]
2727

2828
DIGEST_RETURN_TYPING = Union[Generator[str, None, None], Generator[ProFormaAnnotation, None, None],
2929
Generator[Span, None, None], Generator[Tuple[str, Span], None, None],
@@ -113,8 +113,8 @@ def get_left_semi_enzymatic_sequences(sequence: Union[str, ProFormaAnnotation],
113113
else:
114114
raise ValueError(f"Unsupported input type: {type(sequence)}")
115115

116-
s = (0, len(annotation), 0)
117-
spans = build_left_semi_spans(span=s, min_len=min_len, max_len=max_len)
116+
span = (0, len(annotation), 0)
117+
spans = build_left_semi_spans(span=span, min_len=min_len, max_len=max_len)
118118

119119
return _return_digested_sequences(annotation, spans, return_type)
120120

@@ -198,7 +198,8 @@ def get_semi_enzymatic_sequences(sequence: Union[str, ProFormaAnnotation],
198198
.. code-block:: python
199199
200200
# Equivalent to build_left_semi_sequences + build_right_semi_sequences
201-
>>> res = list(get_left_semi_enzymatic_sequences('PEPTIDE')) + list(get_right_semi_enzymatic_sequences('PEPTIDE'))
201+
>>> res = list(get_left_semi_enzymatic_sequences('PEPTIDE'))
202+
>>> res += list(get_right_semi_enzymatic_sequences('PEPTIDE'))
202203
>>> list(get_semi_enzymatic_sequences('PEPTIDE')) == list(res)
203204
True
204205
@@ -366,7 +367,7 @@ def digest(sequence: Union[str, ProFormaAnnotation],
366367
['TIDER', 'TIDERTIDEK', 'TIDERTIDEKTIDE', 'TIDEK', 'TIDEKTIDE', 'TIDE']
367368
368369
# Inlcude spans in the returned values:
369-
>>> list(digest(sequence='TIDERTIDEKTIDE', enzyme_regex='trypsin/P', missed_cleavages=0, return_type='str-span'))
370+
>>> list(digest(sequence='TIDERTIDEKTIDE', enzyme_regex='trypsin/P', return_type='str-span'))
370371
[('TIDER', (0, 5, 0)), ('TIDEK', (5, 10, 0)), ('TIDE', (10, 14, 0))]
371372
372373
# Or specify a regular expression:

src/peptacular/fragmentation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
from dataclasses import dataclass
77
from functools import cached_property
8-
from typing import List, Union, TypeAlias, Literal, Optional, Tuple, Set
8+
from typing import List, Union, Literal, Optional, Tuple, Set
99

1010
from peptacular.proforma.proforma_parser import ProFormaAnnotation
1111
from peptacular.constants import FORWARD_ION_TYPES, BACKWARD_ION_TYPES, INTERNAL_ION_TYPES, TERMINAL_ION_TYPES
@@ -114,7 +114,7 @@ def to_dict(self):
114114
}
115115

116116

117-
FragmentReturnType: TypeAlias = Literal["fragment", "mass", "mz", "label", "mass-label", "mz-label"]
117+
FragmentReturnType = Literal["fragment", "mass", "mz", "label", "mass-label", "mz-label"]
118118
FRAGMENT_RETURN_TYPING = Union[List[Fragment], List[float], List[str], List[tuple[float, str]]]
119119

120120

src/peptacular/glycan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ def parse_glycan_formula(formula: str, sep: str = '') -> ChemComposition:
134134

135135
try:
136136
return _parse_glycan_formula(formula, sep)
137-
except InvalidGlycanFormulaError as e:
138-
raise InvalidGlycanFormulaError(formula, e.msg) from e
137+
except InvalidGlycanFormulaError as err:
138+
raise InvalidGlycanFormulaError(formula, err.msg) from err
139139

140140

141141
def convert_glycan_formula_to_chem_formula(glycan: Union[ChemComposition, str]) -> str:

src/peptacular/isotope.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,9 @@ def _convolve_distributions(dist1: Dict[float, float],
243243
if max_isotopes != sys.maxsize:
244244
sorted_result = sorted(result.items(), key=lambda x: x[1], reverse=True)
245245
# Retain only the top `max_isotopes` isotopes based on abundance
246-
filtered_result = {mass: abundance for mass, abundance in sorted_result[:max_isotopes]}
247-
return filtered_result
248-
else:
249-
return result
246+
return dict(sorted_result[:max_isotopes])
247+
248+
return result
250249

251250

252251
def _calculate_elemental_distribution(element: str,
@@ -287,7 +286,7 @@ def _calculate_elemental_distribution(element: str,
287286
distribution = {0: 1.0}
288287
for _ in range(count):
289288
# Update the distribution by convolving it with the isotopes' distribution each time
290-
isotope_distribution = {mass: abundance for mass, abundance in isotopes}
289+
isotope_distribution = dict(isotopes)
291290
distribution = _convolve_distributions(distribution, isotope_distribution, None, min_abundance_threshold, None)
292291
return distribution
293292

src/peptacular/mods/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
"""
2+
Initialization file for the mods package.
3+
"""
4+
15
from . import mod_db
26
from . import mod_db_setup
37

48
from .mod_db import *
5-
from .mod_db_setup import *
9+
from .mod_db_setup import *

src/peptacular/mods/mod_db.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def _get_comp(db: EntryDb, mod_str: str, orig_str: str) -> str:
5454
if mod_str.startswith('+') or mod_str.startswith('-'):
5555
try:
5656
_ = float(mod_str)
57-
except ValueError:
58-
raise InvalidDeltaMassError(orig_str)
57+
except ValueError as err:
58+
raise InvalidDeltaMassError(orig_str) from err
5959

6060
raise DeltaMassCompositionError(orig_str)
6161

@@ -71,8 +71,8 @@ def _get_comp(db: EntryDb, mod_str: str, orig_str: str) -> str:
7171
if comp is None:
7272
raise InvalidCompositionError(orig_str)
7373
return comp
74-
else:
75-
raise UnknownModificationError(orig_str)
74+
75+
raise UnknownModificationError(orig_str)
7676

7777

7878
def is_unimod_str(unimod_str: str) -> bool:
@@ -136,8 +136,7 @@ def _strip_unimod_str(unimod_str: str) -> str:
136136
unimod_str_lower = unimod_str.lower()
137137
if unimod_str_lower.startswith('unimod:') or unimod_str_lower.startswith('u:'):
138138
return unimod_str.split(':')[1]
139-
else:
140-
return unimod_str
139+
return unimod_str
141140

142141

143142
def parse_unimod_mass(mod_str: str, monoisotopic: bool, precision: Optional[int] = None) -> float:
@@ -301,8 +300,7 @@ def _strip_psi_str(psi_str: str) -> str:
301300
psi_str_lower = psi_str.lower()
302301
if psi_str_lower.startswith('mod:') or psi_str_lower.startswith('m:') or psi_str_lower.startswith('psi-mod:'):
303302
return psi_str.split(':')[1]
304-
else:
305-
return psi_str
303+
return psi_str
306304

307305

308306
def parse_psi_mass(mod_str: str, monoisotopic: bool, precision: Optional[int] = None) -> float:
@@ -433,8 +431,7 @@ def _strip_xlmod_str(xlmod_str: str) -> str:
433431
xlmod_str_lower = xlmod_str.lower()
434432
if xlmod_str_lower.startswith('xlmod:') or xlmod_str_lower.startswith('x:'):
435433
return xlmod_str.split(':')[1]
436-
else:
437-
return xlmod_str
434+
return xlmod_str
438435

439436

440437
def parse_xlmod_mass(mod_str: str, monoisotopic: bool, precision: Optional[int] = None) -> float:
@@ -521,6 +518,9 @@ def parse_xlmod_comp(mod_str: str) -> str:
521518

522519

523520
def is_resid_str(resid_str: str) -> bool:
521+
"""
522+
Check if a string is a RESID id or name.
523+
"""
524524
resid_str_lower = resid_str.lower()
525525
return resid_str_lower.startswith('resid:') or resid_str_lower.startswith('r:')
526526

@@ -529,8 +529,7 @@ def _strip_resid_str(resid_str: str) -> str:
529529
resid_str_lower = resid_str.lower()
530530
if resid_str_lower.startswith('resid:') or resid_str_lower.startswith('r:'):
531531
return resid_str.split(':')[1]
532-
else:
533-
return resid_str
532+
return resid_str
534533

535534

536535
def parse_resid_mass(mod_str: str, monoisotopic: bool, precision: Optional[int] = None) -> float:
@@ -654,8 +653,7 @@ def _strip_gno_str(gno_str: str) -> str:
654653
gno_str_lower = gno_str.lower()
655654
if gno_str_lower.startswith('gno:') or gno_str_lower.startswith('g:'):
656655
return gno_str.split(':')[1]
657-
else:
658-
return gno_str
656+
return gno_str
659657

660658

661659
def parse_gno_mass(mod_str: str, monoisotopic: bool, precision: Optional[int] = None) -> float:

src/peptacular/mods/mod_db_setup.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import warnings
77
from collections import Counter
88
from functools import cached_property
9-
from typing import List, Dict, IO, Any, Union, Iterator
9+
from typing import List, Dict, IO, Any, Union, Iterator, Tuple
1010

1111
from peptacular.constants import ISOTOPIC_ATOMIC_MASSES
1212
from peptacular.chem.chem_util import write_chem_formula, _parse_isotope_component, parse_chem_formula, chem_mass, \
@@ -639,8 +639,8 @@ def _get_xlmod_entries(terms: List[Dict[str, Any]]) -> List[ModEntry]:
639639
delta_formula = write_chem_formula(elem_counter)
640640

641641
try:
642-
delta_monoisotopic_mass_recalc = chem_mass(delta_formula, monoisotopic=True)
643-
delta_average_mass_recalc = chem_mass(delta_formula, monoisotopic=False)
642+
_ = chem_mass(delta_formula, monoisotopic=True)
643+
_ = chem_mass(delta_formula, monoisotopic=False)
644644
except InvalidChemFormulaError as e:
645645
warnings.warn(f'[{DbType.XLMOD}] Error parsing {term_id} {term_name} {delta_formula}, {e}')
646646
delta_formula = None
@@ -710,8 +710,8 @@ def _get_gno_entries(terms: List[Dict[str, Any]]) -> List[ModEntry]:
710710
for symbol, count in tokens:
711711
try:
712712
comp = _glycan_comp(symbol)
713-
except ValueError as e:
714-
warnings.warn(f'[{DbType.GNO}] Error parsing {term_id} {term_name} {val}, {e}')
713+
except ValueError as err:
714+
warnings.warn(f'[{DbType.GNO}] Error parsing {term_id} {term_name} {val}, {err}')
715715
composition = None
716716
break
717717

@@ -724,8 +724,8 @@ def _get_gno_entries(terms: List[Dict[str, Any]]) -> List[ModEntry]:
724724
try:
725725
delta_monoisotopic_mass_recalc = chem_mass(delta_formula, monoisotopic=True)
726726
delta_average_mass_recalc = chem_mass(delta_formula, monoisotopic=False)
727-
except InvalidChemFormulaError as e:
728-
warnings.warn(f'[{DbType.GNO}] Error parsing {term_id} {term_name} {delta_formula}, {e}')
727+
except InvalidChemFormulaError as err:
728+
warnings.warn(f'[{DbType.GNO}] Error parsing {term_id} {term_name} {delta_formula}, {err}')
729729
delta_formula = None
730730

731731
if delta_monoisotopic_mass is not None:
@@ -1084,10 +1084,10 @@ def reload_from_file(self, file: str, use_synonyms: bool = False) -> None:
10841084
try:
10851085
self.reset()
10861086
self.setup(entries, use_synonyms)
1087-
except Exception as e:
1087+
except Exception as err:
10881088
self.id_map, self.name_map, self.synonym_map, self.mono_mass_map, self.avg_mass_map, self.use_synonyms, \
10891089
self.names_sorted, self.entries = old_maps
1090-
raise e
1090+
raise err
10911091

10921092
# print(f'Reloaded {self.entry_type} database from {file}')
10931093
# print('Entries:', len(self))
@@ -1098,10 +1098,11 @@ def _get_names_sorted(self) -> List[str]:
10981098
return sorted(list(synonyms.union(names)), key=lambda x: len(x), reverse=True)
10991099

11001100

1101-
def count_invalid_entries(entries: List[ModEntry]) -> (int, int, int):
1102-
none_mono = 0
1103-
none_avg = 0
1104-
none_comp = 0
1101+
def count_invalid_entries(entries: List[ModEntry]) -> Tuple[int, int, int]:
1102+
"""
1103+
Count the number of invalid entries in a list of ModEntry objects.
1104+
"""
1105+
none_mono, none_avg, none_comp = 0, 0, 0
11051106

11061107
for entry in entries:
11071108
if entry.mono_mass is None:
@@ -1135,6 +1136,9 @@ def count_invalid_entries(entries: List[ModEntry]) -> (int, int, int):
11351136

11361137

11371138
def reload_all_databases_from_online() -> None:
1139+
"""
1140+
Reload all databases from the online sources
1141+
"""
11381142
MONOSACCHARIDES_DB.reload_from_online()
11391143
UNIMOD_DB.reload_from_online()
11401144
PSI_MOD_DB.reload_from_online()
@@ -1144,6 +1148,9 @@ def reload_all_databases_from_online() -> None:
11441148

11451149

11461150
def reload_all_databases() -> None:
1151+
"""
1152+
Reload all databases from the local files
1153+
"""
11471154
reset_all_databases()
11481155
MONOSACCHARIDES_DB.reload_from_file(os.path.join(_obo_path, "monosaccharides_updated.obo"))
11491156
UNIMOD_DB.reload_from_file(os.path.join(_obo_path, "unimod.obo"))
@@ -1154,6 +1161,9 @@ def reload_all_databases() -> None:
11541161

11551162

11561163
def reset_all_databases() -> None:
1164+
"""
1165+
Reset all databases to empty
1166+
"""
11571167
MONOSACCHARIDES_DB.reset()
11581168
UNIMOD_DB.reset()
11591169
PSI_MOD_DB.reset()

src/peptacular/proforma/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
"""
2+
This module provides the main interface for the ProForma package.
3+
"""
4+
15
from . import proforma_dataclasses
26
from . import proforma_parser
37
from . import randomizer
48
from . import input_convert
59

6-
710
from .proforma_dataclasses import *
811
from .proforma_parser import *
912
from .randomizer import *
10-
from .input_convert import *
13+
from .input_convert import *

0 commit comments

Comments
 (0)