Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

230 basic linting rule e #233

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ repos:
rev: v0.4.9
hooks:
- id: ruff-format
#- id: ruff
- id: ruff
4 changes: 2 additions & 2 deletions alphadia/calibration/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def fit(self, dataframe: pd.DataFrame, plot: bool = False, **kwargs):
logging.error(f"Could not fit estimator {self.name}: {e}")
return

if plot == True:
if plot is True:
self.plot(dataframe, **kwargs)

def predict(self, dataframe, inplace=True):
Expand All @@ -192,7 +192,7 @@ def predict(self, dataframe, inplace=True):

"""

if self.is_fitted == False:
if self.is_fitted is False:
logging.warning(
f"{self.name} prediction was skipped as it has not been fitted yet"
)
Expand Down
6 changes: 4 additions & 2 deletions alphadia/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import re
import json

logger = logging.getLogger()

# alphadia imports
import alphadia
from alphadia.workflow import reporting
Expand All @@ -22,6 +20,10 @@
# third party imports
import argparse


logger = logging.getLogger()


parser = argparse.ArgumentParser(description="Search DIA experiments with alphaDIA")
parser.add_argument(
"--version",
Expand Down
8 changes: 5 additions & 3 deletions alphadia/data/alpharaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import os
import logging

logger = logging.getLogger()

# alphadia imports
from alphadia import utils

from alphadia.data.stats import log_stats

# alpha family imports
from alpharaw import thermo as alpharawthermo
from alpharaw import (
thermo as alpharawthermo,
) # TODO fix: "import resolves to its containing file"
from alpharaw import sciex as alpharawsciex
from alpharaw import mzml as alpharawmzml

Expand All @@ -20,6 +20,8 @@
import numba as nb
import pandas as pd

logger = logging.getLogger()


@nb.njit(parallel=False, fastmath=True)
def search_sorted_left(slice, value):
Expand Down
4 changes: 2 additions & 2 deletions alphadia/data/bruker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import os
import logging

logger = logging.getLogger()

# alphadia imports
from alphadia import utils
from alphadia.data.stats import log_stats
Expand All @@ -20,6 +18,8 @@
from numba.core import types
from numba.experimental import jitclass

logger = logging.getLogger()


class TimsTOFTranspose(alphatims.bruker.TimsTOF):
"""Transposed TimsTOF data structure."""
Expand Down
4 changes: 2 additions & 2 deletions alphadia/fdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import os
import logging

logger = logging.getLogger()

# alphadia imports

# alpha family imports
Expand All @@ -18,6 +16,8 @@

from typing import Union, Optional, List

logger = logging.getLogger()


def perform_fdr(
classifier: sklearn.base.BaseEstimator,
Expand Down
3 changes: 2 additions & 1 deletion alphadia/fragcomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import numpy as np
import pandas as pd

logger = logging.getLogger(__name__)
import numba as nb

logger = logging.getLogger(__name__)


@nb.njit
def get_fragment_overlap(
Expand Down
3 changes: 2 additions & 1 deletion alphadia/libtransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from pathlib import Path
import logging

logger = logging.getLogger()
import os
import typing

Expand All @@ -26,6 +25,8 @@
import numpy as np
import pandas as pd

logger = logging.getLogger()


class ProcessingStep:
def __init__(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions alphadia/numba/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self):
if not isinstance(value, type(getattr(self, key))):
try:
value = type(getattr(self, key))(value)
except:
except Exception as e:
self.reporter.log_string(
f"Parameter {key} has wrong type {type(value)}",
verbosity="error",
Expand All @@ -151,7 +151,7 @@ def __init__(self):
if value.dtype != getattr(self, key).dtype:
try:
value = value.astype(getattr(self, key).dtype)
except:
except Exception as e:
self.reporter.log_string(
f"Parameter {key} has wrong dtype {value.dtype}",
verbosity="error",
Expand Down
5 changes: 2 additions & 3 deletions alphadia/numba/fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from numba.extending import overload_method
import numpy as np

import numba as nb


@nb.experimental.jitclass()
class FragmentContainer:
Expand Down Expand Up @@ -258,9 +260,6 @@ def slice_manual(inst, slices):
return f


import numba as nb


@nb.njit
def get_ion_group_mapping(
ion_precursor,
Expand Down
1 change: 0 additions & 1 deletion alphadia/outputtransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import os

logger = logging.getLogger()

from alphadia import grouping, libtransform, utils
from alphadia import fdr
Expand Down
4 changes: 3 additions & 1 deletion alphadia/peakgroup/kernel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# native imports
import logging

logger = logging.getLogger()
import typing

# alphadia imports
Expand All @@ -14,6 +13,9 @@
import numba as nb


logger = logging.getLogger()


@nb.njit()
def multivariate_normal(x: np.ndarray, mu: np.ndarray, sigma: np.ndarray):
"""multivariate normal distribution, probability density function
Expand Down
4 changes: 3 additions & 1 deletion alphadia/peakgroup/search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# native imports
import logging

logger = logging.getLogger()
import os

# alphadia imports
Expand All @@ -20,6 +19,9 @@
import pandas as pd


logger = logging.getLogger()


@nb.experimental.jitclass()
class HybridCandidateConfigJIT:
"""
Expand Down
4 changes: 3 additions & 1 deletion alphadia/planning.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# native imports
import logging

logger = logging.getLogger()
import socket
from pathlib import Path
import os
Expand All @@ -28,6 +27,9 @@

from alphabase.constants import modification


logger = logging.getLogger()

modification.add_new_modifications(
{
"Dimethyl:d12@Protein N-term": {"composition": "H(-2)2H(8)13C(2)"},
Expand Down
17 changes: 9 additions & 8 deletions alphadia/plexscoring.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# native imports
import logging

logger = logging.getLogger()
import typing

# alphadia imports
Expand All @@ -24,6 +23,11 @@
import numpy as np
import numba as nb


from alphadia.numba import config

logger = logging.getLogger()

NUM_FEATURES = 46


Expand Down Expand Up @@ -154,9 +158,6 @@ def multiplex_candidates(
return multiplexed_candidates_df


from alphadia.numba import config


@nb.experimental.jitclass()
class CandidateConfigJIT:
collect_fragments: nb.boolean
Expand Down Expand Up @@ -584,14 +585,14 @@ def process(
for i in range(_dense_precursors.shape[1]):
dense_precursors[0, i, 0] = np.sum(_dense_precursors[0, i], axis=0)
for k in range(_dense_precursors.shape[3]):
for l in range(_dense_precursors.shape[4]):
for ll in range(_dense_precursors.shape[4]):
sum = 0
count = 0
for j in range(_dense_precursors.shape[2]):
sum += _dense_precursors[1, i, j, k, l]
if _dense_precursors[1, i, j, k, l] > 0:
sum += _dense_precursors[1, i, j, k, ll]
mschwoer marked this conversation as resolved.
Show resolved Hide resolved
if _dense_precursors[1, i, j, k, ll] > 0:
count += 1
dense_precursors[1, i, 0, k, l] = sum / (count + 1e-6)
dense_precursors[1, i, 0, k, ll] = sum / (count + 1e-6)

# DEBUG only used for debugging
# self.dense_precursors = dense_precursors
Expand Down
2 changes: 1 addition & 1 deletion alphadia/plotting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def lighten_color(color, amount=0.5):

try:
c = mc.cnames[color]
except:
except KeyError:
c = color
c = colorsys.rgb_to_hls(*mc.to_rgb(c))
return colorsys.hls_to_rgb(c[0], 1 - amount * (1 - c[1]), c[2])
Expand Down
2 changes: 1 addition & 1 deletion alphadia/test_data_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _get_filename(self) -> str: # pragma: no cover
"""Get filename from url."""
try:
remotefile = urlopen(self._encoded_url)
except:
except Exception:
print(f"Could not open {self._url} for reading filename")
raise ValueError(
f"Could not open {self._url} for reading filename"
Expand Down
9 changes: 5 additions & 4 deletions alphadia/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import platform
import torch

logger = logging.getLogger()

# alphadia imports

Expand All @@ -20,6 +19,8 @@
import numba as nb
import matplotlib.patches as patches

logger = logging.getLogger()


ISOTOPE_DIFF = 1.0032999999999674

Expand Down Expand Up @@ -307,7 +308,7 @@ def get_isotope_columns(colnames):
if col[:2] == "i_":
try:
isotopes.append(int(col[2:]))
except:
except Exception:
logging.warning(
f"Column {col} does not seem to be a valid isotope column"
)
Expand Down Expand Up @@ -655,10 +656,10 @@ def merge_missing_columns(
Merged left dataframe

"""
if type(on) == str:
if isinstance(on, str):
on = [on]

if type(right_columns) == str:
if isinstance(right_columns, str):
right_columns = [right_columns]

missing_from_left = list(set(right_columns) - set(left_df.columns))
Expand Down
4 changes: 2 additions & 2 deletions alphadia/validate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# native imports
import logging

logger = logging.getLogger()

# alphadia imports

# alpha family imports
Expand All @@ -11,6 +9,8 @@
import pandas as pd
import numpy as np

logger = logging.getLogger()


class Property:
"""Column property base class"""
Expand Down
3 changes: 2 additions & 1 deletion alphadia/workflow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import logging

logger = logging.getLogger()
import typing

# alphadia imports
Expand All @@ -14,6 +13,8 @@

# third party imports

logger = logging.getLogger()

TEMP_FOLDER = ".progress"


Expand Down
Loading
Loading