Skip to content

Commit

Permalink
Merge pull request #49 from MannLabs/48-basic-linting
Browse files Browse the repository at this point in the history
48 basic linting
  • Loading branch information
jalew188 authored Jun 8, 2024
2 parents 4094245 + 706837e commit 4fa470a
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 74 deletions.
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.0
hooks:
- id: ruff-format
# - id: ruff
- id: ruff
12 changes: 6 additions & 6 deletions alpharaw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@


def register_readers():
from .ms_data_base import ms_reader_provider
from .legacy_msdata import mgf
from .mzml import MzMLReader
from .wrappers import alphapept_wrapper
from .ms_data_base import ms_reader_provider # noqa: F401 # TODO remove import side effect
from .legacy_msdata import mgf # noqa: F401 # TODO remove import side effect
from .mzml import MzMLReader # noqa: F401 # TODO remove import side effect
from .wrappers import alphapept_wrapper # noqa: F401 # TODO remove import side effect

try:
from .sciex import SciexWiffData
from .thermo import ThermoRawData
from .sciex import SciexWiffData # noqa: F401 # TODO remove import side effect
from .thermo import ThermoRawData # noqa: F401 # TODO remove import side effect
except (RuntimeError, ImportError):
print("[WARN] pythonnet is not installed")

Expand Down
12 changes: 6 additions & 6 deletions alpharaw/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import alpharaw
from alpharaw.ms_data_base import ms_reader_provider
from alpharaw.legacy_msdata import mgf
from alpharaw.mzml import MzMLReader
from alpharaw.wrappers import alphapept_wrapper
from alpharaw.legacy_msdata import mgf # noqa: F401 # TODO remove import side effect
from alpharaw.mzml import MzMLReader # noqa: F401 # TODO remove import side effect
from alpharaw.wrappers import alphapept_wrapper # noqa: F401 # TODO remove import side effect

try:
from alpharaw.sciex import SciexWiffData
from alpharaw.thermo import ThermoRawData
from alpharaw.sciex import SciexWiffData # noqa: F401 # TODO remove import side effect
from alpharaw.thermo import ThermoRawData # noqa: F401 # TODO remove import side effect
except (RuntimeError, ImportError):
print("[WARN] pythonnet is not installed")

Expand Down Expand Up @@ -51,7 +51,7 @@ def run(ctx, **kwargs):
type=str,
default="thermo_raw",
show_default=True,
help=f"Only `thermo_raw`, `sciex_wiff` is supported currently.",
help="Only `thermo_raw`, `sciex_wiff` is supported currently.",
)
@click.option(
"--raw",
Expand Down
1 change: 0 additions & 1 deletion alpharaw/dia/normal_dia.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pandas as pd
import numpy as np
import typing

Expand Down
6 changes: 0 additions & 6 deletions alpharaw/feature/chem.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
# Some legacy chemistry functions
# Maybe replacd with alphabase?

from numba.typed import Dict
from numba import types, njit
import numpy as np
from numba import int32, float32, float64, njit, types
from numba.experimental import jitclass
from numba.typed import Dict

averagine_aa = Dict.empty(key_type=types.unicode_type, value_type=types.float64)

Expand Down
1 change: 0 additions & 1 deletion alpharaw/feature/finding.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pandas as pd
import numpy as np
import numba

from alpharaw.feature.chem import averagine_aa, isotopes, maximum_offset
from alpharaw.feature.hills import (
Expand Down
1 change: 1 addition & 0 deletions alpharaw/feature/hills.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pandas as pd
from alphatims.utils import threadpool
from numba import njit
from alpharaw.feature.centroids import connect_centroids
Expand Down
27 changes: 5 additions & 22 deletions alpharaw/feature/isotope_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@

from alpharaw.feature.chem import (
mass_to_dist,
maximum_offset,
DELTA_M,
DELTA_S,
M_PROTON,
averagine_aa,
isotopes,
Isotope,
)


Expand Down Expand Up @@ -394,13 +390,13 @@ def grow(

y = pattern[seed + relative_pos] # This is a reference peak

l = sortindex_[y]
ll = sortindex_[y]

mass2 = stats[y, 0]
delta_mass2 = stats[y, 1]

start = hill_ptrs[l]
end = hill_ptrs[l + 1]
start = hill_ptrs[ll]
end = hill_ptrs[ll + 1]
idx_ = hill_data[start:end]
int_2 = int_data[idx_]
scans_2 = scan_idx[idx_]
Expand Down Expand Up @@ -564,7 +560,6 @@ def plot_pattern(
pattern: np.ndarray,
sorted_hills: np.ndarray,
centroids: np.ndarray,
hill_data: np.ndarray,
):
"""Helper function to plot a pattern.
Expand All @@ -574,19 +569,17 @@ def plot_pattern(
centroids (np.ndarray): 1D Array containing the masses of the centroids.
hill_data (np.ndarray): Array containing the indices to hills.
"""
import matplotlib.pyplot as plt

f, (ax1, ax2) = plt.subplots(2, 1, sharex=True, figsize=(10, 10))
centroid_dtype = [("mz", float), ("int", float), ("scan_no", int), ("rt", float)]

mzs = []
rts = []
ints = []
for entry in pattern:
hill = sorted_hills[entry]
hill_data = np.array(
[centroids[_[0]][_[1]] for _ in hill], dtype=centroid_dtype
)

int_profile = hill_data["int"]
ax1.plot(hill_data["rt"], hill_data["int"])
ax2.scatter(hill_data["rt"], hill_data["mz"], s=hill_data["int"] / 5e5)

Expand Down Expand Up @@ -947,9 +940,6 @@ def isolate_isotope_pattern(
return champion_trace, champion_charge


from typing import Callable, Union


def get_isotope_patterns(
pre_isotope_patterns: list,
hill_ptrs: np.ndarray,
Expand Down Expand Up @@ -1109,13 +1099,6 @@ def report_(
int_max_idx = np.argmax(isotope_data[:, 2])
mz_most_abundant = isotope_data[:, 0][int_max_idx]

int_max = isotope_data[:, 2][int_max_idx]

rt_start = isotope_data[
int_max_idx, 4
] # This is the start of the most abundant trace
rt_end = isotope_data[int_max_idx, 5]

rt_min_ = min(isotope_data[:, 4])
rt_max_ = max(isotope_data[:, 5])

Expand Down
3 changes: 0 additions & 3 deletions alpharaw/match/match_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import numpy as np
import numba
import pandas as pd
import tqdm
import os

from typing import Tuple

Expand Down
5 changes: 3 additions & 2 deletions alpharaw/match/psm_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

from alpharaw import register_readers

register_readers()

from alphabase.peptide.fragment import (
create_fragment_mz_dataframe,
get_charged_frag_types,
concat_precursor_fragment_dataframes,
)

from alpharaw.ms_data_base import (
Expand All @@ -31,6 +29,9 @@
from alpharaw.dia.normal_dia import NormalDIAGrouper


register_readers() # TODO remove this import side effect


class PepSpecMatch:
"""
Extract fragment ions from MS2 data.
Expand Down
3 changes: 1 addition & 2 deletions alpharaw/match/psm_match_alphatims.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

from alpharaw.wrappers.alphatims_wrapper import AlphaTimsWrapper

from alpharaw.wrappers.alphapept_wrapper import AlphaPept_HDF_MS2_Reader
from alpharaw.wrappers.alphapept_wrapper import AlphaPept_HDF_MS2_Reader # noqa: F401 # TODO remove import side effect

from .psm_match import PepSpecMatch
from ..utils.ms_path_utils import parse_ms_files_to_dict

alphatims_hdf_types = [
"alphatims",
Expand Down
2 changes: 1 addition & 1 deletion alpharaw/mzml.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def parse_mzml_entry(item_dict: dict) -> tuple:
nce = float(filter_string.split("@cid")[1].split(" ")[0])
else:
nce = np.nan
except:
except Exception:
nce = np.nan
return (
rt,
Expand Down
4 changes: 3 additions & 1 deletion alpharaw/raw_access/clr_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import clr
# ruff: noqa: E402 #Module level import not at top of file
import os
import numpy as np

import clr

clr.AddReference("System")
# from System.Runtime.InteropServices import Marshal
# from System import IntPtr, Int64
Expand Down
10 changes: 5 additions & 5 deletions alpharaw/raw_access/pysciexwifffilereader.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# ruff: noqa: E402 #Module level import not at top of file
import os
import sys
import numpy as np
import time

from alpharaw.utils.centroiding import naive_centroid

# require pythonnet, pip install pythonnet on Windows
import clr

clr.AddReference("System")
import System

import System # noqa: F401
from System.Threading import Thread
from System.Globalization import CultureInfo

Expand All @@ -25,8 +25,8 @@
clr.AddReference(os.path.join(ext_dir, "sciex/Clearcore2.Data.dll"))
clr.AddReference(os.path.join(ext_dir, "sciex/WiffOps4Python.dll"))

import Clearcore2
import WiffOps4Python
import Clearcore2 # noqa: F401
import WiffOps4Python # noqa: F401
from WiffOps4Python import WiffOps as DotNetWiffOps
from Clearcore2.Data.AnalystDataProvider import (
AnalystWiffDataProvider,
Expand Down
11 changes: 1 addition & 10 deletions alpharaw/raw_access/pythermorawfilereader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# ruff: noqa: E402 #Module level import not at top of file
import os
import sys
import numpy as np
import time
import warnings

from collections import defaultdict
Expand Down Expand Up @@ -311,13 +309,6 @@ def GetScanEventStringForScanNum(self, scanNumber):
"""This function returns scan event information as a string for the specified scan number."""
return self.source.GetScanEventStringForScanNumber(scanNumber)

def GetStatusLogForRetentionTime(self, rt):
logEntry = self.source.GetStatusLogForRetentionTime(rt)
return dict(zip(logEntry.Labels, logEntry.Values))

def GetStatusLogForScanNum(self, scan):
return self.GetStatusLogForRetentionTime(self.RTFromScanNum(scan))

def GetScanEventForScanNum(self, scanNumber):
return IScanEventBase(self.source.GetScanEventForScanNumber(scanNumber))

Expand Down
3 changes: 0 additions & 3 deletions alpharaw/sciex.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import numpy as np
import pandas as pd
import os
import warnings
import alpharaw.raw_access.pysciexwifffilereader as pysciexwifffilereader
from .ms_data_base import MSData_Base
Expand Down
2 changes: 0 additions & 2 deletions alpharaw/thermo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import numpy as np
import pandas as pd
import platform
import os
import multiprocessing as mp
from functools import partial
from tqdm import tqdm
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "_modidx,py"]

code_url = f"https://github.com/mannlabs/alpharaw/blob/main"
code_url = "https://github.com/mannlabs/alpharaw/blob/main"


def linkcode_resolve(domain, info):
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

[tool.ruff.lint]
select = ["E","F"]
ignore = [
"E501" # Line too long (ruff wraps code, but not docstrings)
]
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# builtin
import setuptools
import re
import os

# local
import alpharaw as package2install
Expand Down

0 comments on commit 4fa470a

Please sign in to comment.