Skip to content

Commit

Permalink
mokapot: Fix setting log levels for Numba and Mokapot correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfG committed Sep 14, 2023
1 parent 4c8d4b1 commit 2f1b838
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ms2rescore/rescoring_engines/mokapot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@

logger = logging.getLogger(__name__)

# Set mokapot logging to WARNING if not in debug mode
if logger.getEffectiveLevel() > logging.DEBUG:
logging.getLogger("mokapot").setLevel(logging.WARNING)

# Keep numba logging to INFO or higher
if logger.getEffectiveLevel() < logging.INFO:
logging.getLogger("numba").setLevel(logging.INFO)


def rescore(
psm_list: psm_utils.PSMList,
Expand Down Expand Up @@ -80,6 +72,8 @@ def rescore(
Additional keyword arguments are passed to the Mokapot :py:func:`~mokapot.brew` function.
"""
_set_log_levels()

# Convert PSMList to Mokapot dataset
lin_psm_data = convert_psm_list(psm_list)
feature_names = list(lin_psm_data.features.columns)
Expand Down Expand Up @@ -223,3 +217,14 @@ def save_model_weights(
def _mz_to_mass(mz: float, charge: int) -> float:
"""Convert m/z to mass."""
return mz * charge - charge * nist_mass["H"][1][0]


def _set_log_levels() -> None:
"""Set log levels for Mokapot and Numba to avoid too-high verbosity."""
# Set mokapot logging to WARNING if not in debug mode
if logger.getEffectiveLevel() > logging.DEBUG:
logging.getLogger("mokapot").setLevel(logging.WARNING)

# Keep Numba logging to INFO or higher
if logger.getEffectiveLevel() < logging.INFO:
logging.getLogger("numba").setLevel(logging.INFO)

0 comments on commit 2f1b838

Please sign in to comment.