diff --git a/alphadia/calibration/models.py b/alphadia/calibration/models.py index c508f7c8..a25ac3bb 100644 --- a/alphadia/calibration/models.py +++ b/alphadia/calibration/models.py @@ -1,7 +1,6 @@ import numpy as np - -from sklearn.preprocessing import PolynomialFeatures from sklearn.base import BaseEstimator, RegressorMixin +from sklearn.preprocessing import PolynomialFeatures class LOESSRegression(BaseEstimator, RegressorMixin): diff --git a/alphadia/calibration/property.py b/alphadia/calibration/property.py index 1391651f..0463c427 100644 --- a/alphadia/calibration/property.py +++ b/alphadia/calibration/property.py @@ -2,19 +2,20 @@ import logging import pickle -# alphadia imports -from alphadia.plotting.utils import density_scatter -from alphadia.calibration.models import LOESSRegression +import numpy as np # third party imports import pandas as pd -import numpy as np -from matplotlib import pyplot as plt - import sklearn.base +from matplotlib import pyplot as plt from sklearn.linear_model import LinearRegression -from sklearn.preprocessing import PolynomialFeatures from sklearn.pipeline import Pipeline +from sklearn.preprocessing import PolynomialFeatures + +from alphadia.calibration.models import LOESSRegression + +# alphadia imports +from alphadia.plotting.utils import density_scatter class Calibration: diff --git a/alphadia/cli.py b/alphadia/cli.py index 074a046d..4b78126c 100644 --- a/alphadia/cli.py +++ b/alphadia/cli.py @@ -1,25 +1,21 @@ #!python # native imports +# alpha family imports +# third party imports +import argparse +import json import logging +import os +import re import sys import yaml -import os -import re -import json # alphadia imports import alphadia -from alphadia.workflow import reporting from alphadia import utils - - -# alpha family imports - -# third party imports -import argparse - +from alphadia.workflow import reporting logger = logging.getLogger() diff --git a/alphadia/consensus/utils.py b/alphadia/consensus/utils.py index 084ded8d..0e2ee794 100644 --- a/alphadia/consensus/utils.py +++ b/alphadia/consensus/utils.py @@ -1,5 +1,6 @@ import logging import os + import pandas as pd logger = logging.getLogger() diff --git a/alphadia/data/alpharaw.py b/alphadia/data/alpharaw.py index 299275c1..ca8edc49 100644 --- a/alphadia/data/alpharaw.py +++ b/alphadia/data/alpharaw.py @@ -1,24 +1,26 @@ # native imports +import logging import math import os -import logging -# alphadia imports -from alphadia import utils +import numba as nb -from alphadia.data.stats import log_stats +# third party imports +import numpy as np +import pandas as pd +from alpharaw import mzml as alpharawmzml + +# TODO fix: "import resolves to its containing file" +from alpharaw import sciex as alpharawsciex # alpha family imports 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 +) -# third party imports -import numpy as np -import numba as nb -import pandas as pd +# alphadia imports +from alphadia import utils +from alphadia.data.stats import log_stats logger = logging.getLogger() diff --git a/alphadia/data/bruker.py b/alphadia/data/bruker.py index 5f04a053..8bdff4ba 100644 --- a/alphadia/data/bruker.py +++ b/alphadia/data/bruker.py @@ -1,23 +1,24 @@ # native imports +import logging import math import os -import logging -# alphadia imports -from alphadia import utils -from alphadia.data.stats import log_stats +import alphatims.bruker +import alphatims.tempmmap as tm # alpha family imports import alphatims.utils -import alphatims.bruker -import alphatims.tempmmap as tm +import numba as nb # third party imports import numpy as np -import numba as nb from numba.core import types from numba.experimental import jitclass +# alphadia imports +from alphadia import utils +from alphadia.data.stats import log_stats + logger = logging.getLogger() diff --git a/alphadia/data/stats.py b/alphadia/data/stats.py index 55c9dcc8..94a2f885 100644 --- a/alphadia/data/stats.py +++ b/alphadia/data/stats.py @@ -1,6 +1,7 @@ -import numpy as np import logging +import numpy as np + logger = logging.getLogger() diff --git a/alphadia/fdr.py b/alphadia/fdr.py index a365f467..5c9911cb 100644 --- a/alphadia/fdr.py +++ b/alphadia/fdr.py @@ -1,19 +1,18 @@ # native imports -import os import logging +import os -# alphadia imports - -# alpha family imports -from alphadia import fragcomp +import matplotlib as mpl +import matplotlib.pyplot as plt +import numpy as np # third party imports import pandas as pd -import numpy as np -import matplotlib.pyplot as plt -import matplotlib as mpl import sklearn +# alphadia imports +# alpha family imports +from alphadia import fragcomp logger = logging.getLogger() diff --git a/alphadia/fdrexperimental.py b/alphadia/fdrexperimental.py index 733c6d9b..21c28892 100644 --- a/alphadia/fdrexperimental.py +++ b/alphadia/fdrexperimental.py @@ -1,20 +1,18 @@ # native imports -from abc import ABC, abstractmethod import warnings +from abc import ABC, abstractmethod from copy import deepcopy # alphadia imports - # alpha family imports - # third party imports import numpy as np import torch import torch.nn as nn import torch.optim as optim from sklearn import model_selection -from tqdm import tqdm from torchmetrics.classification import BinaryAUROC +from tqdm import tqdm class Classifier(ABC): diff --git a/alphadia/fdrx/base.py b/alphadia/fdrx/base.py index cd051759..f98161aa 100644 --- a/alphadia/fdrx/base.py +++ b/alphadia/fdrx/base.py @@ -2,18 +2,19 @@ It is flexible with regards to the features, type of classifier and type of identifications (precursors, peptides, proteins). """ -import sklearn.base -import pandas as pd +import logging + import numpy as np -from alphadia.fragcomp import FragmentCompetition -from alphadia.fdrx.stats import get_pep, add_q_values, keep_best +import pandas as pd +import sklearn.base + from alphadia.fdrx.plotting import ( _plot_fdr_curve, _plot_roc_curve, _plot_score_distribution, ) - -import logging +from alphadia.fdrx.stats import add_q_values, get_pep, keep_best +from alphadia.fragcomp import FragmentCompetition logger = logging.getLogger() diff --git a/alphadia/fdrx/plotting.py b/alphadia/fdrx/plotting.py index 050fcb0b..efb8920f 100644 --- a/alphadia/fdrx/plotting.py +++ b/alphadia/fdrx/plotting.py @@ -1,5 +1,5 @@ -import numpy as np import matplotlib.pyplot as plt +import numpy as np import sklearn.metrics diff --git a/alphadia/features.py b/alphadia/features.py index ceb35132..14d2a60d 100644 --- a/alphadia/features.py +++ b/alphadia/features.py @@ -1,14 +1,14 @@ # native imports # alphadia imports -from alphadia import utils -from alphadia.numba import numeric +import numba as nb # alpha family imports - # third party imports import numpy as np -import numba as nb + +from alphadia import utils +from alphadia.numba import numeric @nb.njit diff --git a/alphadia/fragcomp.py b/alphadia/fragcomp.py index 4245682d..bc7fc712 100644 --- a/alphadia/fragcomp.py +++ b/alphadia/fragcomp.py @@ -1,10 +1,11 @@ -from alphadia import utils -from alphatims import utils as timsutils import logging + +import numba as nb import numpy as np import pandas as pd +from alphatims import utils as timsutils -import numba as nb +from alphadia import utils logger = logging.getLogger(__name__) diff --git a/alphadia/grouping.py b/alphadia/grouping.py index 68f89a2f..0069cbf8 100644 --- a/alphadia/grouping.py +++ b/alphadia/grouping.py @@ -5,9 +5,10 @@ # alpha family imports # third party imports +from typing import Any + import numpy as np import pandas as pd -from typing import Any from numpy.typing import NDArray diff --git a/alphadia/libtransform.py b/alphadia/libtransform.py index 64390db8..03e78584 100644 --- a/alphadia/libtransform.py +++ b/alphadia/libtransform.py @@ -1,29 +1,27 @@ # native imports -from pathlib import Path import logging - import os import typing +from pathlib import Path -# alphadia imports -from alphadia import utils, validate +# third party imports +import numpy as np +import pandas as pd # alpha family imports from alphabase.peptide import fragment +from alphabase.peptide.fragment import get_charged_frag_types from alphabase.protein import fasta -from alphabase.spectral_library.flat import SpecLibFlat +from alphabase.protein.fasta import protease_dict from alphabase.spectral_library.base import SpecLibBase -from alphabase.spectral_library.reader import LibraryReaderBase from alphabase.spectral_library.decoy import decoy_lib_provider -from alphabase.peptide.fragment import get_charged_frag_types -from alphabase.protein.fasta import protease_dict - -from peptdeep.protein.fasta import PredictSpecLibFasta +from alphabase.spectral_library.flat import SpecLibFlat +from alphabase.spectral_library.reader import LibraryReaderBase from peptdeep.pretrained_models import ModelManager +from peptdeep.protein.fasta import PredictSpecLibFasta -# third party imports -import numpy as np -import pandas as pd +# alphadia imports +from alphadia import utils, validate logger = logging.getLogger() diff --git a/alphadia/numba/config.py b/alphadia/numba/config.py index e416ed70..a38777d8 100644 --- a/alphadia/numba/config.py +++ b/alphadia/numba/config.py @@ -1,13 +1,12 @@ # native imports # alphadia imports -from alphadia.workflow import reporting - # alpha family imports - # third party imports import numpy as np +from alphadia.workflow import reporting + class JITConfig: """ diff --git a/alphadia/numba/fft.py b/alphadia/numba/fft.py index 6f039c5d..8c93b57e 100644 --- a/alphadia/numba/fft.py +++ b/alphadia/numba/fft.py @@ -1,16 +1,15 @@ -import numpy as np import numba as nb +import numpy as np +from numba.extending import overload +from rocket_fft import pocketfft from rocket_fft.overloads import ( - ndshape_and_axes, - zeropad_or_crop, - increase_shape, - get_fct, decrease_shape, + get_fct, + increase_shape, + ndshape_and_axes, resize, + zeropad_or_crop, ) -from rocket_fft import pocketfft - -from numba.extending import overload class NumbaContextOnly(Exception): diff --git a/alphadia/numba/fragments.py b/alphadia/numba/fragments.py index f220e535..89c9e986 100644 --- a/alphadia/numba/fragments.py +++ b/alphadia/numba/fragments.py @@ -6,8 +6,8 @@ # third party imports import numba as nb -from numba.extending import overload_method import numpy as np +from numba.extending import overload_method @nb.experimental.jitclass() diff --git a/alphadia/numba/numeric.py b/alphadia/numba/numeric.py index 629426c4..e6189c19 100644 --- a/alphadia/numba/numeric.py +++ b/alphadia/numba/numeric.py @@ -5,8 +5,8 @@ # alpha family imports # third party imports -import numpy as np import numba as nb +import numpy as np @nb.njit(parallel=False, fastmath=True) diff --git a/alphadia/outputaccumulator.py b/alphadia/outputaccumulator.py index 1d40f706..9bfad363 100644 --- a/alphadia/outputaccumulator.py +++ b/alphadia/outputaccumulator.py @@ -22,19 +22,17 @@ """ -import numba as nb -import pandas as pd -import numpy as np -import os +import logging import multiprocessing +import os import threading -from tqdm import tqdm +import numba as nb +import numpy as np +import pandas as pd from alphabase.spectral_library import base from alphabase.spectral_library.flat import SpecLibFlat - - -import logging +from tqdm import tqdm logger = logging.getLogger() diff --git a/alphadia/outputtransform.py b/alphadia/outputtransform.py index 2a78e745..5dd2773f 100644 --- a/alphadia/outputtransform.py +++ b/alphadia/outputtransform.py @@ -1,36 +1,29 @@ # native imports import logging import os +from collections.abc import Iterator +import directlfq.config as lfqconfig +import directlfq.normalization as lfqnorm +import directlfq.protein_intensity_estimation as lfqprot_estimation +import directlfq.utils as lfqutils +import numpy as np +import pandas as pd +from alphabase.peptide import precursor +from alphabase.spectral_library import base +from alphabase.spectral_library.base import SpecLibBase +from sklearn.model_selection import train_test_split +from sklearn.neural_network import MLPClassifier +from sklearn.preprocessing import StandardScaler -from alphadia import grouping, libtransform, utils -from alphadia import fdr +from alphadia import fdr, grouping, libtransform, utils +from alphadia.consensus.utils import read_df, write_df from alphadia.outputaccumulator import ( - TransferLearningAccumulator, AccumulationBroadcaster, + TransferLearningAccumulator, ) -from alphadia.consensus.utils import read_df, write_df from alphadia.transferlearning.train import FinetuneManager -import pandas as pd -import numpy as np -from sklearn.preprocessing import StandardScaler -from sklearn.model_selection import train_test_split -from sklearn.neural_network import MLPClassifier - - -from collections.abc import Iterator -from alphabase.spectral_library import base -from alphabase.spectral_library.base import SpecLibBase -from alphabase.peptide import precursor - - -import directlfq.utils as lfqutils -import directlfq.normalization as lfqnorm -import directlfq.protein_intensity_estimation as lfqprot_estimation -import directlfq.config as lfqconfig - - logger = logging.getLogger() diff --git a/alphadia/peakgroup/kernel.py b/alphadia/peakgroup/kernel.py index 4b64b4e3..8cd37e28 100644 --- a/alphadia/peakgroup/kernel.py +++ b/alphadia/peakgroup/kernel.py @@ -1,16 +1,14 @@ # native imports import logging - -# alphadia imports -from alphadia.data import bruker, alpharaw +import numba as nb # alpha family imports - # third party imports import numpy as np -import numba as nb +# alphadia imports +from alphadia.data import alpharaw, bruker logger = logging.getLogger() diff --git a/alphadia/peakgroup/search.py b/alphadia/peakgroup/search.py index 3a0ec6bb..8497c6c4 100644 --- a/alphadia/peakgroup/search.py +++ b/alphadia/peakgroup/search.py @@ -1,15 +1,7 @@ # native imports import logging - import os -# alphadia imports -from alphadia import utils -from alphadia.numba import fragments, numeric, config, fft -from alphadia import validate -from alphadia.peakgroup.kernel import GaussianKernel -from alphadia.peakgroup.utils import assemble_isotope_mz - # alpha family imports import alphatims @@ -18,6 +10,11 @@ import numpy as np import pandas as pd +# alphadia imports +from alphadia import utils, validate +from alphadia.numba import config, fft, fragments, numeric +from alphadia.peakgroup.kernel import GaussianKernel +from alphadia.peakgroup.utils import assemble_isotope_mz logger = logging.getLogger() diff --git a/alphadia/peakgroup/utils.py b/alphadia/peakgroup/utils.py index 192b7410..788c8f7e 100644 --- a/alphadia/peakgroup/utils.py +++ b/alphadia/peakgroup/utils.py @@ -1,8 +1,9 @@ -import numpy as np import numba as nb -from alphadia.numba.fft import NumbaContextOnly +import numpy as np from numba.extending import overload +from alphadia.numba.fft import NumbaContextOnly + def assemble_isotope_mz(mono_mz, charge, isotope_intensity): """ diff --git a/alphadia/planning.py b/alphadia/planning.py index dc7fd485..cc04cd88 100644 --- a/alphadia/planning.py +++ b/alphadia/planning.py @@ -1,31 +1,30 @@ # native imports import logging - -import socket -from pathlib import Path import os +import socket from datetime import datetime +from pathlib import Path -# alphadia imports -from alphadia import libtransform, outputtransform -from alphadia.workflow import peptidecentric, reporting -from alphadia.workflow.config import Config -import alphadia -import alpharaw import alphabase -import peptdeep +import alpharaw import alphatims import directlfq - -# alpha family imports -from alphabase.spectral_library.flat import SpecLibFlat -from alphabase.spectral_library.base import SpecLibBase +import peptdeep # third party imports import torch - from alphabase.constants import modification +from alphabase.spectral_library.base import SpecLibBase + +# alpha family imports +from alphabase.spectral_library.flat import SpecLibFlat + +import alphadia +# alphadia imports +from alphadia import libtransform, outputtransform +from alphadia.workflow import peptidecentric, reporting +from alphadia.workflow.config import Config logger = logging.getLogger() diff --git a/alphadia/plexscoring.py b/alphadia/plexscoring.py index 2521f746..92731ab3 100644 --- a/alphadia/plexscoring.py +++ b/alphadia/plexscoring.py @@ -1,30 +1,26 @@ # native imports import logging +# alpha family imports +import alphatims.utils +import numba as nb +import numpy as np + +# third party imports +import pandas as pd # alphadia imports -from alphadia import validate, utils, features, quadrupole -from alphadia.numba import fragments -from alphadia.data import bruker, alpharaw +from alphadia import features, quadrupole, utils, validate +from alphadia.data import alpharaw, bruker +from alphadia.numba import config, fragments from alphadia.plotting.cycle import plot_cycle from alphadia.plotting.debug import ( plot_fragment_profile, - plot_precursor, plot_fragments, + plot_precursor, plot_template, ) -# alpha family imports -import alphatims.utils - -# third party imports -import pandas as pd -import numpy as np -import numba as nb - - -from alphadia.numba import config - logger = logging.getLogger() NUM_FEATURES = 46 diff --git a/alphadia/plotting/cycle.py b/alphadia/plotting/cycle.py index fef58695..dadaf692 100644 --- a/alphadia/plotting/cycle.py +++ b/alphadia/plotting/cycle.py @@ -1,14 +1,13 @@ # native imports import os -# alphadia imports +import matplotlib.pyplot as plt +import numpy as np +# alphadia imports # alpha family imports - # third party imports from matplotlib import patches -import numpy as np -import matplotlib.pyplot as plt def _generate_patch_collection_nomobility( diff --git a/alphadia/plotting/debug.py b/alphadia/plotting/debug.py index c1c8aa9d..d2d5ec86 100644 --- a/alphadia/plotting/debug.py +++ b/alphadia/plotting/debug.py @@ -1,15 +1,14 @@ # native imports # alphadia imports -from alphadia.plotting import utils -from alphadia import quadrupole - # alpha family imports - # third party imports import matplotlib.pyplot as plt import numpy as np +from alphadia import quadrupole +from alphadia.plotting import utils + def plot_fragment_profile( template, diff --git a/alphadia/plotting/utils.py b/alphadia/plotting/utils.py index 228d2093..526d0b03 100644 --- a/alphadia/plotting/utils.py +++ b/alphadia/plotting/utils.py @@ -5,10 +5,10 @@ # alpha family imports # third party imports -from scipy.stats import gaussian_kde import matplotlib.pyplot as plt import numpy as np import pandas as pd +from scipy.stats import gaussian_kde def lighten_color(color, amount=0.5): @@ -29,9 +29,10 @@ def lighten_color(color, amount=0.5): tuple lightened color """ - import matplotlib.colors as mc import colorsys + import matplotlib.colors as mc + try: c = mc.cnames[color] except KeyError: diff --git a/alphadia/quadrupole.py b/alphadia/quadrupole.py index 9505ea75..8917ecdc 100644 --- a/alphadia/quadrupole.py +++ b/alphadia/quadrupole.py @@ -1,17 +1,17 @@ # native imports # alphadia imports -from alphadia import utils - # alpha family imports import alphatims.utils # third party imports import numba as nb -from numba.experimental import jitclass import numpy as np +from numba.experimental import jitclass from scipy.optimize import curve_fit +from alphadia import utils + @alphatims.utils.njit def logistic(x: np.array, mu: float, sigma: float): diff --git a/alphadia/test_data_downloader.py b/alphadia/test_data_downloader.py index 2e43037d..66e8b740 100644 --- a/alphadia/test_data_downloader.py +++ b/alphadia/test_data_downloader.py @@ -1,13 +1,13 @@ """Download files from sharing links.""" -import os import base64 -import traceback -from abc import ABC, abstractmethod -from urllib.request import urlopen -from urllib.request import urlretrieve import cgi +import os +import traceback import zipfile +from abc import ABC, abstractmethod +from urllib.request import urlopen, urlretrieve + import progressbar diff --git a/alphadia/transferlearning/metrics.py b/alphadia/transferlearning/metrics.py index e05b1338..c10e7454 100644 --- a/alphadia/transferlearning/metrics.py +++ b/alphadia/transferlearning/metrics.py @@ -1,7 +1,7 @@ import numpy as np import pandas as pd -from peptdeep.utils import linear_regression from peptdeep.model.ms2 import calc_ms2_similarity +from peptdeep.utils import linear_regression class TestMetricBase: diff --git a/alphadia/transferlearning/train.py b/alphadia/transferlearning/train.py index 30cbf07d..b72509cd 100644 --- a/alphadia/transferlearning/train.py +++ b/alphadia/transferlearning/train.py @@ -1,28 +1,27 @@ -import torch -import pandas as pd +import logging + import numpy as np -from tqdm import tqdm -from torch.optim.lr_scheduler import LambdaLR +import pandas as pd +import torch from alphabase.peptide.fragment import remove_unused_fragments +from peptdeep.model.charge import ChargeModelForModAASeq +from peptdeep.model.model_interface import CallbackHandler, LR_SchedulerInterface +from peptdeep.pretrained_models import ModelManager +from peptdeep.settings import global_settings +from torch.optim.lr_scheduler import LambdaLR +from tqdm import tqdm from alphadia.transferlearning.metrics import ( - MetricManager, - L1LossTestMetric, - LinearRegressionTestMetric, AbsErrorPercentileTestMetric, - CELossTestMetric, AccuracyTestMetric, - PrecisionRecallTestMetric, + CELossTestMetric, + L1LossTestMetric, + LinearRegressionTestMetric, + MetricManager, Ms2SimilarityTestMetric, + PrecisionRecallTestMetric, ) -from peptdeep.settings import global_settings -from peptdeep.pretrained_models import ModelManager -from peptdeep.model.model_interface import LR_SchedulerInterface, CallbackHandler -from peptdeep.model.charge import ChargeModelForModAASeq -import logging - - logger = logging.getLogger() settings = { diff --git a/alphadia/utils.py b/alphadia/utils.py index 0a64aa0b..8408b584 100644 --- a/alphadia/utils.py +++ b/alphadia/utils.py @@ -1,22 +1,20 @@ # native imports import logging -from ctypes import Structure, c_double -import re import platform -import torch - +import re +from ctypes import Structure, c_double # alphadia imports - # alpha family imports import alphatims.bruker import alphatims.utils +import matplotlib.patches as patches +import numba as nb +import numpy as np # third party imports import pandas as pd -import numpy as np -import numba as nb -import matplotlib.patches as patches +import torch logger = logging.getLogger() diff --git a/alphadia/validate.py b/alphadia/validate.py index d5cb51b0..a8007d5f 100644 --- a/alphadia/validate.py +++ b/alphadia/validate.py @@ -1,13 +1,12 @@ # native imports import logging -# alphadia imports +import numpy as np +# alphadia imports # alpha family imports - # third party imports import pandas as pd -import numpy as np logger = logging.getLogger() diff --git a/alphadia/workflow/base.py b/alphadia/workflow/base.py index c0bacd1e..b06fc5d7 100644 --- a/alphadia/workflow/base.py +++ b/alphadia/workflow/base.py @@ -1,15 +1,14 @@ # native imports -import os import logging +import os +# alpha family imports +from alphabase.spectral_library.base import SpecLibBase # alphadia imports -from alphadia.data import bruker, alpharaw +from alphadia.data import alpharaw, bruker from alphadia.workflow import manager, reporting -# alpha family imports -from alphabase.spectral_library.base import SpecLibBase - # third party imports logger = logging.getLogger() diff --git a/alphadia/workflow/config.py b/alphadia/workflow/config.py index df3de56d..4af78454 100644 --- a/alphadia/workflow/config.py +++ b/alphadia/workflow/config.py @@ -22,13 +22,14 @@ - But we still define the source of the update to be the first experiment that triggered the change. """ -import yaml -from typing import Any import copy import json -import pandas as pd -import numpy as np import logging +from typing import Any + +import numpy as np +import pandas as pd +import yaml logger = logging.getLogger() diff --git a/alphadia/workflow/manager.py b/alphadia/workflow/manager.py index fe3fa199..109280f9 100644 --- a/alphadia/workflow/manager.py +++ b/alphadia/workflow/manager.py @@ -1,24 +1,23 @@ # native imports +import logging import os -import typing import pickle +import typing from copy import deepcopy -import logging -# alphadia imports -import alphadia -from alphadia.calibration.property import calibration_model_provider, Calibration -from alphadia import fdr -from alphadia.workflow import reporting +import numpy as np # alpha family imports - # third party imports import pandas as pd -import numpy as np +import torch import xxhash -import torch +# alphadia imports +import alphadia +from alphadia import fdr +from alphadia.calibration.property import Calibration, calibration_model_provider +from alphadia.workflow import reporting logger = logging.getLogger() diff --git a/alphadia/workflow/peptidecentric.py b/alphadia/workflow/peptidecentric.py index a9c6f7b9..582f6e7c 100644 --- a/alphadia/workflow/peptidecentric.py +++ b/alphadia/workflow/peptidecentric.py @@ -1,22 +1,22 @@ # native imports import logging - -# alphadia imports -from alphadia import plexscoring, utils, fragcomp -from alphadia import fdrexperimental as fdrx -from alphadia.peakgroup import search -from alphadia.workflow import manager, base +# third party imports +import numpy as np +import pandas as pd +import seaborn as sns +from alphabase.peptide.fragment import get_charged_frag_types # alpha family imports from alphabase.spectral_library.base import SpecLibBase from alphabase.spectral_library.flat import SpecLibFlat -from alphabase.peptide.fragment import get_charged_frag_types -# third party imports -import numpy as np -import pandas as pd -import seaborn as sns +from alphadia import fdrexperimental as fdrx + +# alphadia imports +from alphadia import fragcomp, plexscoring, utils +from alphadia.peakgroup import search +from alphadia.workflow import base, manager logger = logging.getLogger() diff --git a/alphadia/workflow/reporting.py b/alphadia/workflow/reporting.py index 1f53ae75..d08ec45d 100644 --- a/alphadia/workflow/reporting.py +++ b/alphadia/workflow/reporting.py @@ -1,23 +1,21 @@ # native imports -import traceback +import base64 +import json import logging import os import time -from datetime import datetime, timedelta +import traceback import typing import warnings -import json -import base64 +from datetime import datetime, timedelta from io import BytesIO # alphadia imports - # alpha family imports - # third party imports import matplotlib -from matplotlib.figure import Figure import numpy as np +from matplotlib.figure import Figure # global variable which tracks if any logger has been initiated # As soon as its instantiated the default logger will be configured with a path to save the log file diff --git a/pyproject.toml b/pyproject.toml index ede85129..666bdd92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,18 +72,10 @@ select = [ "B", # flake8-simplify "SIM", + # isort + "I", ] -# # Pyflakes -# "F", -# # pyupgrade -# "UP", -# # flake8-bugbear -# "B", -# # flake8-simplify -# "SIM", -# # isort -# "I", ignore = [ "E501", # Line too long (ruff wraps code, but not docstrings) "B028", # No explicit `stacklevel` keyword argument found (for warnings) diff --git a/release/pyinstaller/cli_hook.py b/release/pyinstaller/cli_hook.py index c5836304..c412fa6c 100644 --- a/release/pyinstaller/cli_hook.py +++ b/release/pyinstaller/cli_hook.py @@ -1,10 +1,10 @@ import sys - if __name__ == "__main__": - from alphadia import cli import multiprocessing + from alphadia import cli + # catch pyinstaller bug # subprocess.CalledProcessError: Command '['/Applications/alphaDIA.app/Contents/Frameworks/alphadia', '-sS', '-c', 'import platform; print(platform.mac_ver()[0])']' returned non-zero exit status 2. # [36481] Failed to execute script 'cli_hook' due to unhandled exception! diff --git a/tests/e2e_tests/calc_metrics.py b/tests/e2e_tests/calc_metrics.py index e0434d68..11e5b64d 100644 --- a/tests/e2e_tests/calc_metrics.py +++ b/tests/e2e_tests/calc_metrics.py @@ -6,15 +6,14 @@ import os import sys from abc import ABC, abstractmethod +from datetime import datetime from typing import Any -import pandas as pd -import neptune - import matplotlib.pyplot as plt -from datetime import datetime +import neptune +import pandas as pd -from tests.e2e_tests.prepare_test_data import get_test_case, OUTPUT_DIR_NAME +from tests.e2e_tests.prepare_test_data import OUTPUT_DIR_NAME, get_test_case NEPTUNE_PROJECT_NAME = os.environ.get("NEPTUNE_PROJECT_NAME") diff --git a/tests/performance_tests/1_brunner_2022_1ng_all.py b/tests/performance_tests/1_brunner_2022_1ng_all.py index c27529a3..6bd9f948 100644 --- a/tests/performance_tests/1_brunner_2022_1ng_all.py +++ b/tests/performance_tests/1_brunner_2022_1ng_all.py @@ -1,13 +1,11 @@ import logging - - import os import matplotlib +from alphabase.spectral_library.base import SpecLibBase from alphadia.extraction.planning import Plan from alphadia.test_data_downloader import DataShareDownloader -from alphabase.spectral_library.base import SpecLibBase logging.basicConfig( format="%(asctime)s %(levelname)s: %(message)s", datefmt="%Y-%m-%d %H:%M:%S" diff --git a/tests/performance_tests/diann_psm_extraction.py b/tests/performance_tests/diann_psm_extraction.py index 38dc4392..29118a7d 100644 --- a/tests/performance_tests/diann_psm_extraction.py +++ b/tests/performance_tests/diann_psm_extraction.py @@ -1,23 +1,20 @@ import logging - -from alphadia.test_data_downloader import DataShareDownloader - import os -import neptune.new as neptune import pathlib import socket +import neptune.new as neptune -from alphadia.extraction.planning import Plan from alphadia.extraction.calibration import RunCalibration +from alphadia.extraction.candidateselection import MS1CentricCandidateSelection from alphadia.extraction.data import TimsTOFDIA +from alphadia.extraction.planning import Plan from alphadia.extraction.scoring import ( + MS2ExtractionWorkflow, fdr_correction, unpack_fragment_info, - MS2ExtractionWorkflow, ) -from alphadia.extraction.candidateselection import MS1CentricCandidateSelection - +from alphadia.test_data_downloader import DataShareDownloader logging.basicConfig( format="%(asctime)s %(levelname)s: %(message)s", datefmt="%Y-%m-%d %H:%M:%S" diff --git a/tests/performance_tests/fdr_test.py b/tests/performance_tests/fdr_test.py index 609862ce..e717e440 100644 --- a/tests/performance_tests/fdr_test.py +++ b/tests/performance_tests/fdr_test.py @@ -1,14 +1,15 @@ # setup basic argpasrse comand line script to run the fdr test # with the options --threads and --size between 0 and 100% -import matplotlib import argparse import tempfile -import pandas as pd -import torch -import numpy as np import time + +import matplotlib import neptune +import numpy as np +import pandas as pd +import torch import alphadia from alphadia import fdr, fdrexperimental diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index f4097b3f..17201d33 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -1,11 +1,12 @@ -import pytest import os import re -import pandas as pd -import numpy as np -import matplotlib import tempfile +import matplotlib +import numpy as np +import pandas as pd +import pytest + matplotlib.use("Agg") from matplotlib import pyplot as plt diff --git a/tests/unit_tests/test_calibration_models.py b/tests/unit_tests/test_calibration_models.py index cf5ffea8..12a83eb9 100644 --- a/tests/unit_tests/test_calibration_models.py +++ b/tests/unit_tests/test_calibration_models.py @@ -1,5 +1,6 @@ -import pytest import numpy as np +import pytest + from alphadia.calibration.models import LOESSRegression diff --git a/tests/unit_tests/test_calibration_property.py b/tests/unit_tests/test_calibration_property.py index 8291edb6..cadee274 100644 --- a/tests/unit_tests/test_calibration_property.py +++ b/tests/unit_tests/test_calibration_property.py @@ -1,14 +1,13 @@ -from alphadia.calibration.property import Calibration -from sklearn.linear_model import LinearRegression -from alphadia.calibration.models import LOESSRegression +import os +import tempfile import numpy as np import pandas as pd - import pytest +from sklearn.linear_model import LinearRegression -import tempfile -import os +from alphadia.calibration.models import LOESSRegression +from alphadia.calibration.property import Calibration def test_uninitialized_calibration(): diff --git a/tests/unit_tests/test_config_updater.py b/tests/unit_tests/test_config_updater.py index 9f783c43..61696e0a 100644 --- a/tests/unit_tests/test_config_updater.py +++ b/tests/unit_tests/test_config_updater.py @@ -1,6 +1,7 @@ -import yaml from io import StringIO + import pandas as pd +import yaml from alphadia.workflow.config import Config, get_update_table diff --git a/tests/unit_tests/test_consensus.py b/tests/unit_tests/test_consensus.py index 65aa5b19..10558525 100644 --- a/tests/unit_tests/test_consensus.py +++ b/tests/unit_tests/test_consensus.py @@ -1,7 +1,9 @@ -import pytest -import pandas as pd import os + +import pandas as pd +import pytest from conftest import random_tempfolder + from alphadia.consensus.utils import read_df, write_df diff --git a/tests/unit_tests/test_data.py b/tests/unit_tests/test_data.py index 57509738..d2fa02d5 100644 --- a/tests/unit_tests/test_data.py +++ b/tests/unit_tests/test_data.py @@ -1,7 +1,7 @@ -from alphadia.data import bruker, alpharaw - -import pytest import numpy as np +import pytest + +from alphadia.data import alpharaw, bruker def test_transpose(): diff --git a/tests/unit_tests/test_fdr.py b/tests/unit_tests/test_fdr.py index 8246b43f..8042ce7d 100644 --- a/tests/unit_tests/test_fdr.py +++ b/tests/unit_tests/test_fdr.py @@ -1,19 +1,17 @@ import os +import tempfile import warnings + +import matplotlib import numpy as np import pandas as pd import pytest -import tempfile +import torch from alphadia import fdr from alphadia import fdrexperimental as fdrx from alphadia.workflow import manager - -import torch - -import matplotlib - feature_columns = [ "base_width_mobility", "base_width_rt", diff --git a/tests/unit_tests/test_fdrx_base.py b/tests/unit_tests/test_fdrx_base.py index 1a918bb9..75694a7f 100644 --- a/tests/unit_tests/test_fdrx_base.py +++ b/tests/unit_tests/test_fdrx_base.py @@ -1,9 +1,11 @@ +from unittest.mock import patch + import numpy as np import pandas as pd -from unittest.mock import patch -from alphadia.fdrx.base import TargetDecoyFDR from sklearn.linear_model import LogisticRegression +from alphadia.fdrx.base import TargetDecoyFDR + @patch("matplotlib.pyplot.show") def test_target_decoy_fdr(mock_show): diff --git a/tests/unit_tests/test_fdrx_plotting.py b/tests/unit_tests/test_fdrx_plotting.py index f2211ca7..1e1ee39e 100644 --- a/tests/unit_tests/test_fdrx_plotting.py +++ b/tests/unit_tests/test_fdrx_plotting.py @@ -1,10 +1,12 @@ -import numpy as np -import matplotlib.pyplot as plt from unittest.mock import patch + +import matplotlib.pyplot as plt +import numpy as np + from alphadia.fdrx.plotting import ( - _plot_score_distribution, - _plot_roc_curve, _plot_fdr_curve, + _plot_roc_curve, + _plot_score_distribution, ) diff --git a/tests/unit_tests/test_fdrx_stats.py b/tests/unit_tests/test_fdrx_stats.py index b51c4d48..929b52f1 100644 --- a/tests/unit_tests/test_fdrx_stats.py +++ b/tests/unit_tests/test_fdrx_stats.py @@ -1,6 +1,7 @@ -from alphadia.fdrx.stats import keep_best, get_pep, add_q_values, fdr_to_q_values -import pandas as pd import numpy as np +import pandas as pd + +from alphadia.fdrx.stats import add_q_values, fdr_to_q_values, get_pep, keep_best def test_keep_best(): diff --git a/tests/unit_tests/test_finetunemetrics.py b/tests/unit_tests/test_finetunemetrics.py index 5c03e52f..b2af071b 100644 --- a/tests/unit_tests/test_finetunemetrics.py +++ b/tests/unit_tests/test_finetunemetrics.py @@ -2,19 +2,21 @@ Test the metrics module. """ +from math import isclose + import numpy as np +from scipy import linalg, stats +from sklearn.metrics import accuracy_score, log_loss, precision_score, recall_score + from alphadia.transferlearning.metrics import ( - LinearRegressionTestMetric, AbsErrorPercentileTestMetric, - L1LossTestMetric, - CELossTestMetric, AccuracyTestMetric, - PrecisionRecallTestMetric, + CELossTestMetric, + L1LossTestMetric, + LinearRegressionTestMetric, MetricManager, + PrecisionRecallTestMetric, ) -from scipy import stats, linalg -from math import isclose -from sklearn.metrics import log_loss, accuracy_score, precision_score, recall_score def get_regression_test_input(): diff --git a/tests/unit_tests/test_fragcomp.py b/tests/unit_tests/test_fragcomp.py index 64a874bf..ce8d24cb 100644 --- a/tests/unit_tests/test_fragcomp.py +++ b/tests/unit_tests/test_fragcomp.py @@ -1,7 +1,8 @@ -from alphadia import fragcomp import numpy as np import pandas as pd +from alphadia import fragcomp + def test_fragment_overlap(): frag_mz_1 = np.array([100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) diff --git a/tests/unit_tests/test_grouping.py b/tests/unit_tests/test_grouping.py index 57fda6c5..2b5acf02 100644 --- a/tests/unit_tests/test_grouping.py +++ b/tests/unit_tests/test_grouping.py @@ -1,6 +1,7 @@ -import pytest import numpy as np import pandas as pd +import pytest + from alphadia import grouping diff --git a/tests/unit_tests/test_libtransform.py b/tests/unit_tests/test_libtransform.py index 426de399..7326171c 100644 --- a/tests/unit_tests/test_libtransform.py +++ b/tests/unit_tests/test_libtransform.py @@ -1,4 +1,5 @@ import tempfile + import numpy as np from alphadia import libtransform diff --git a/tests/unit_tests/test_numba.py b/tests/unit_tests/test_numba.py index 9ad30275..c9c40f02 100644 --- a/tests/unit_tests/test_numba.py +++ b/tests/unit_tests/test_numba.py @@ -2,16 +2,14 @@ # local from alphadia import utils -from alphadia.numba.fragments import get_ion_group_mapping - from alphadia.numba.fft import convolve_fourier - +from alphadia.numba.fragments import get_ion_group_mapping from alphadia.numba.numeric import ( - symetric_limits_1d, - symetric_limits_2d, - save_corrcoeff, fragment_correlation, fragment_correlation_different, + save_corrcoeff, + symetric_limits_1d, + symetric_limits_2d, ) diff --git a/tests/unit_tests/test_numba_fft.py b/tests/unit_tests/test_numba_fft.py index 20065e34..acfd4241 100644 --- a/tests/unit_tests/test_numba_fft.py +++ b/tests/unit_tests/test_numba_fft.py @@ -1,8 +1,8 @@ -import pytest -import numpy as np import numba as nb +import numpy as np +import pytest -from alphadia.numba.fft import rfft2, irfft2, convolve_fourier +from alphadia.numba.fft import convolve_fourier, irfft2, rfft2 @pytest.mark.parametrize("shape", [(100, 2), (2, 100), (100, 100)]) diff --git a/tests/unit_tests/test_numba_numeric.py b/tests/unit_tests/test_numba_numeric.py index ea7ee94b..c6510897 100644 --- a/tests/unit_tests/test_numba_numeric.py +++ b/tests/unit_tests/test_numba_numeric.py @@ -1,4 +1,5 @@ import numpy as np + from alphadia.numba.numeric import search_sorted_left diff --git a/tests/unit_tests/test_outputaccumulator.py b/tests/unit_tests/test_outputaccumulator.py index 063687d0..5e51d99f 100644 --- a/tests/unit_tests/test_outputaccumulator.py +++ b/tests/unit_tests/test_outputaccumulator.py @@ -1,11 +1,13 @@ import os +import shutil import tempfile + import numpy as np import pandas as pd -from conftest import mock_precursor_df, mock_fragment_df -from alphadia import outputtransform from alphabase.spectral_library.base import SpecLibBase -import shutil +from conftest import mock_fragment_df, mock_precursor_df + +from alphadia import outputtransform def prepare_input_data(): diff --git a/tests/unit_tests/test_outputtransform.py b/tests/unit_tests/test_outputtransform.py index bc492f11..350432e9 100644 --- a/tests/unit_tests/test_outputtransform.py +++ b/tests/unit_tests/test_outputtransform.py @@ -1,10 +1,12 @@ -import tempfile -from alphadia import outputtransform -import pandas as pd -import numpy as np import os import shutil -from conftest import mock_precursor_df, mock_fragment_df +import tempfile + +import numpy as np +import pandas as pd +from conftest import mock_fragment_df, mock_precursor_df + +from alphadia import outputtransform def test_output_transform(): diff --git a/tests/unit_tests/test_peakgroup_kernel.py b/tests/unit_tests/test_peakgroup_kernel.py index a60a6ea3..d37c8d45 100644 --- a/tests/unit_tests/test_peakgroup_kernel.py +++ b/tests/unit_tests/test_peakgroup_kernel.py @@ -1,5 +1,6 @@ import numpy as np import pytest + from alphadia.peakgroup.kernel import GaussianKernel, multivariate_normal diff --git a/tests/unit_tests/test_peakgroup_utils.py b/tests/unit_tests/test_peakgroup_utils.py index 5387e00a..28878880 100644 --- a/tests/unit_tests/test_peakgroup_utils.py +++ b/tests/unit_tests/test_peakgroup_utils.py @@ -1,8 +1,9 @@ -from alphadia.peakgroup.utils import assemble_isotope_mz import numba as nb import numpy as np import pytest +from alphadia.peakgroup.utils import assemble_isotope_mz + @nb.njit def wrap_assemble_isotope_mz(mz, charge, intensities): diff --git a/tests/unit_tests/test_planning.py b/tests/unit_tests/test_planning.py index 8b8c5cd9..b8bb38c8 100644 --- a/tests/unit_tests/test_planning.py +++ b/tests/unit_tests/test_planning.py @@ -1,9 +1,11 @@ +import os import tempfile + import pytest -import os +from alphabase.constants import _const + from alphadia import planning from alphadia.test_data_downloader import DataShareDownloader -from alphabase.constants import _const @pytest.mark.slow diff --git a/tests/unit_tests/test_plotting.py b/tests/unit_tests/test_plotting.py index c1b78552..87a7c308 100644 --- a/tests/unit_tests/test_plotting.py +++ b/tests/unit_tests/test_plotting.py @@ -1,9 +1,8 @@ import matplotlib import numpy as np -from alphadia.plotting.utils import lighten_color - from alphadia.plotting.cycle import plot_cycle +from alphadia.plotting.utils import lighten_color def test_lighten_color(): diff --git a/tests/unit_tests/test_quadrupole.py b/tests/unit_tests/test_quadrupole.py index c8876338..b3a13bb0 100644 --- a/tests/unit_tests/test_quadrupole.py +++ b/tests/unit_tests/test_quadrupole.py @@ -1,13 +1,13 @@ +# global +import numpy as np +import pytest + from alphadia.quadrupole import ( SimpleQuadrupole, logistic_rectangle, quadrupole_transfer_function_single, ) -# global -import numpy as np -import pytest - @pytest.fixture() def get_fake_quadrupole(): diff --git a/tests/unit_tests/test_reporting.py b/tests/unit_tests/test_reporting.py index 8af88641..a6e1aba2 100644 --- a/tests/unit_tests/test_reporting.py +++ b/tests/unit_tests/test_reporting.py @@ -1,12 +1,12 @@ -from matplotlib import pyplot as plt -import numpy as np -import os import logging -import time +import os import sys -import pytest +import time +import numpy as np +import pytest from conftest import random_tempfolder +from matplotlib import pyplot as plt from alphadia.workflow import reporting diff --git a/tests/unit_tests/test_utils.py b/tests/unit_tests/test_utils.py index 64bce9a3..bc10da03 100644 --- a/tests/unit_tests/test_utils.py +++ b/tests/unit_tests/test_utils.py @@ -4,23 +4,22 @@ # builtin # local +# global +import numpy as np +import pandas as pd +import pytest + from alphadia.utils import ( amean0, amean1, calculate_score_groups, - wsl_to_windows, - windows_to_wsl, - merge_missing_columns, get_torch_device, + merge_missing_columns, + windows_to_wsl, + wsl_to_windows, ) -# global -import numpy as np -import pandas as pd -import pytest - - @pytest.mark.parametrize("use_gpu", [True, False]) def test_get_torch_device(use_gpu): # given diff --git a/tests/unit_tests/test_workflow.py b/tests/unit_tests/test_workflow.py index be8de860..0a3362d4 100644 --- a/tests/unit_tests/test_workflow.py +++ b/tests/unit_tests/test_workflow.py @@ -1,16 +1,17 @@ -import tempfile import os import shutil +import tempfile +from pathlib import Path + import numpy as np import pandas as pd -import yaml import pytest -from pathlib import Path - -from alphadia.calibration.property import Calibration +import yaml from sklearn.linear_model import LinearRegression + from alphadia.calibration.models import LOESSRegression -from alphadia.workflow import manager, base +from alphadia.calibration.property import Calibration +from alphadia.workflow import base, manager def test_base_manager():