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

Misc fixes 2 #391

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
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 alphadia/constants/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ library_prediction:

# define custom alphabase modifications not part of unimod or alphabase
# also used for decoy channels
custom_modififcations:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s breaking in theory :D alphabase can’t use the custom mods with multiprocessing yet. So it’s not being used (yet)

custom_modifications:
# Dimethyl @K channel decoy
Dimethyl:d12@K:
composition: H(-2)2H(8)13C(2)
Expand Down
6 changes: 3 additions & 3 deletions alphadia/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ def init_alphabase(self):
"""Init alphabase by registering custom modifications."""

# register custom modifications
if "custom_modififcations" in self.config:
n_modifications = len(self.config["custom_modififcations"])
if "custom_modifications" in self.config:
n_modifications = len(self.config["custom_modifications"])
logging.info(f"Registering {n_modifications} custom modifications")

modification.add_new_modifications(self.config["custom_modififcations"])
modification.add_new_modifications(self.config["custom_modifications"])

def load_library(self):
"""
Expand Down
15 changes: 4 additions & 11 deletions alphadia/quadrupole.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# native imports

# alphadia imports
# alpha family imports
import alphatims.utils

# third party imports
import numba as nb
import numpy as np
from numba.experimental import jitclass
Expand All @@ -13,7 +6,7 @@
from alphadia import utils


@alphatims.utils.njit
@nb.njit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check the alphatims function? I wonder why I did this in the first place ( I already see some weird numbs thing happening :D )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the @alphatims.utils.njit decorator

def njit(_func=None, *args, **kwargs):
    import numba
    return numba.njit(_func, *args, **kwargs)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much value

def logistic(x: np.array, mu: float, sigma: float):
"""Numba implementation of the logistic function

Expand Down Expand Up @@ -41,13 +34,13 @@ def logistic(x: np.array, mu: float, sigma: float):
return y


@alphatims.utils.njit
@nb.njit
def logistic_rectangle(mu1, mu2, sigma1, sigma2, x):
y = logistic(x, mu1, sigma1) - logistic(x, mu2, sigma2)
return y


@alphatims.utils.njit
@nb.njit
def linear(x, m, b):
return m * x + b

Expand Down Expand Up @@ -267,7 +260,7 @@ def get_calibrated_cycle(self, treshold=0.01):
return new_cycle


@alphatims.utils.njit
@nb.njit
def quadrupole_transfer_function_single(
quadrupole_calibration_jit, observation_indices, scan_indices, isotope_mz
):
Expand Down
29 changes: 11 additions & 18 deletions alphadia/utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# native imports
import logging
import math
import platform
import re
from ctypes import Structure, c_double

# alphadia imports
# alpha family imports
import alphatims.bruker
import alphatims.utils
import numba as nb
import numpy as np

# third party imports
import pandas as pd
import torch
from matplotlib import patches
Expand Down Expand Up @@ -203,7 +196,7 @@ def plt_limits(mobility_limits, dia_cycle_limits):
return rect


@alphatims.utils.njit()
@nb.njit()
def find_peaks_1d(a, top_n=3):
"""accepts a dense representation and returns the top three peaks"""

Expand Down Expand Up @@ -234,7 +227,7 @@ def find_peaks_1d(a, top_n=3):
return scan, dia_cycle, intensity


@alphatims.utils.njit()
@nb.njit()
def find_peaks_2d(a, top_n=3):
"""accepts a dense representation and returns the top three peaks"""
scan = []
Expand Down Expand Up @@ -268,31 +261,31 @@ def find_peaks_2d(a, top_n=3):
return scan, dia_cycle, intensity


@alphatims.utils.njit()
@nb.njit()
def amean1(array):
out = np.zeros(array.shape[0])
for i in range(len(out)):
out[i] = np.mean(array[i])
return out


@alphatims.utils.njit()
@nb.njit()
def amean0(array):
out = np.zeros(array.shape[1])
for i in range(len(out)):
out[i] = np.mean(array[:, i])
return out


@alphatims.utils.njit()
@nb.njit()
def astd0(array):
out = np.zeros(array.shape[1])
for i in range(len(out)):
out[i] = np.std(array[:, i])
return out


@alphatims.utils.njit()
@nb.njit()
def astd1(array):
out = np.zeros(array.shape[0])
for i in range(len(out)):
Expand Down Expand Up @@ -323,7 +316,7 @@ def get_isotope_column_names(colnames):
return [f"i_{i}" for i in get_isotope_columns(colnames)]


@alphatims.utils.njit()
@nb.njit()
def mass_range(mz_list, ppm_tolerance):
out_mz = np.zeros((len(mz_list), 2), dtype=mz_list.dtype)
out_mz[:, 0] = mz_list - ppm_tolerance * mz_list / (10**6)
Expand All @@ -348,12 +341,12 @@ class Point(Structure):
_fields_ = [("x", c_double), ("y", c_double)]


@alphatims.utils.njit()
@nb.njit()
def tile(a, n):
return np.repeat(a, n).reshape(-1, n).T.flatten()


@alphatims.utils.njit
@nb.njit
def make_slice_1d(start_stop):
"""Numba helper function to create a 1D slice object from a start and stop value.

Expand All @@ -373,7 +366,7 @@ def make_slice_1d(start_stop):
return np.array([[start_stop[0], start_stop[1], 1]], dtype=start_stop.dtype)


@alphatims.utils.njit
@nb.njit
def make_slice_2d(start_stop):
"""Numba helper function to create a 2D slice object from multiple start and stop value.

Expand All @@ -397,7 +390,7 @@ def make_slice_2d(start_stop):
return out


@alphatims.utils.njit
@nb.njit
def fourier_filter(dense_stack, kernel):
"""Numba helper function to apply a gaussian filter to a dense stack.
The filter is applied as convolution wrapping around the edges, calculated in fourier space.
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_custom_modifications():
temp_directory = tempfile.gettempdir()

config = {
"custom_modififcations": {
"custom_modifications": {
"ThisModDoesNotExists@K": {
"composition": "H(10)",
},
Expand Down
Loading