Skip to content
Closed
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
5 changes: 2 additions & 3 deletions alphabase/constants/aa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import typing

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -29,7 +28,7 @@
AA_Composition: dict = {}


def replace_atoms(atom_replace_dict: typing.Dict):
def replace_atoms(atom_replace_dict: dict):
for aa, row in aa_formula.iterrows():
formula = row["formula"]
atom_comp = dict(parse_formula(formula))
Expand Down Expand Up @@ -81,7 +80,7 @@ def reset_AA_Composition():
reset_AA_Composition()


def reset_AA_atoms(atom_replace_dict: typing.Dict = {}):
def reset_AA_atoms(atom_replace_dict: dict = {}):
reset_elements()
replace_atoms(atom_replace_dict)
reset_AA_mass()
Expand Down
3 changes: 1 addition & 2 deletions alphabase/constants/atom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import re
import typing
from collections import defaultdict

import numpy as np
Expand Down Expand Up @@ -102,7 +101,7 @@ def truncate_isotope(isotopes: np.ndarray, mono_idx: int) -> tuple:
MASS_NH3: int = None


def update_atom_infos(new_atom_info: typing.Dict):
def update_atom_infos(new_atom_info: dict):
"""Update the atom information in CHEM_INFO_DICT.

Args:
Expand Down
10 changes: 5 additions & 5 deletions alphabase/constants/isotope.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def abundance_convolution(
mono1: int,
d2: np.ndarray,
mono2: int,
) -> typing.Tuple[np.ndarray, int]:
) -> tuple[np.ndarray, int]:
"""
If we have two isotope distributions,
we can convolute them into one distribution.
Expand Down Expand Up @@ -60,7 +60,7 @@ def one_element_dist(
n: int,
chem_isotope_dist: NumbaTypedDict,
chem_mono_idx: NumbaTypedDict,
) -> typing.Tuple[np.ndarray, int]:
) -> tuple[np.ndarray, int]:
"""
Calculate the isotope distribution for
an element and its numbers.
Expand Down Expand Up @@ -101,7 +101,7 @@ def one_element_dist(
)


def formula_dist(formula: typing.Union[list, str]) -> typing.Tuple[np.ndarray, int]:
def formula_dist(formula: typing.Union[list, str]) -> tuple[np.ndarray, int]:
"""
Generate the isotope distribution and the mono index for
a given formula (as a list, e.g. `[('H', 2), ('C', 2), ('O', 1)]`).
Expand Down Expand Up @@ -210,8 +210,8 @@ def __init__(

def calc_formula_distribution(
self,
formula: typing.List[typing.Tuple[str, int]],
) -> typing.Tuple[np.ndarray, int]:
formula: list[tuple[str, int]],
) -> tuple[np.ndarray, int]:
"""Calculate isotope abundance distribution for a given formula

Parameters
Expand Down
16 changes: 8 additions & 8 deletions alphabase/constants/modification.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import List, Union
from typing import Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -184,7 +184,7 @@ def load_mod_df(


def calc_modification_mass(
nAA: int, mod_names: List[str], mod_sites: List[int]
nAA: int, mod_names: list[str], mod_sites: list[int]
) -> np.ndarray:
"""
Calculate modification masses for the given peptide length (`nAA`),
Expand Down Expand Up @@ -221,7 +221,7 @@ def calc_modification_mass(


def calc_mod_masses_for_same_len_seqs(
nAA: int, mod_names_list: List[List[str]], mod_sites_list: List[List[int]]
nAA: int, mod_names_list: list[list[str]], mod_sites_list: list[list[int]]
) -> np.ndarray:
"""
Calculate modification masses for the given peptides with same peptide length (`nAA`).
Expand Down Expand Up @@ -258,7 +258,7 @@ def calc_mod_masses_for_same_len_seqs(
return masses


def calc_modification_mass_sum(mod_names: List[str]) -> float:
def calc_modification_mass_sum(mod_names: list[str]) -> float:
"""
Calculate summed mass of the given modification
without knowing the sites and peptide length.
Expand Down Expand Up @@ -314,8 +314,8 @@ def _calc_modloss_with_importance(

def calc_modloss_mass_with_importance(
nAA: int,
mod_names: List,
mod_sites: List,
mod_names: list,
mod_sites: list,
for_nterm_frag: bool,
) -> np.ndarray:
"""
Expand Down Expand Up @@ -390,8 +390,8 @@ def _calc_modloss(mod_losses: np.ndarray) -> np.ndarray:

def calc_modloss_mass(
nAA: int,
mod_names: List,
mod_sites: List,
mod_names: list,
mod_sites: list,
for_nterm_frag: bool,
) -> np.ndarray:
"""
Expand Down
48 changes: 24 additions & 24 deletions alphabase/peptide/fragment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import warnings
from dataclasses import dataclass, field
from typing import Dict, List, Tuple, Union
from typing import Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -316,7 +316,7 @@ def parse_all_frag_type_representation():
parse_all_frag_type_representation()


def sort_charged_frag_types(charged_frag_types: List[str]) -> List[str]:
def sort_charged_frag_types(charged_frag_types: list[str]) -> list[str]:
"""charged frag types are sorted by (no-loss, loss) and then alphabetically"""
has_loss = [
f.replace(FRAGMENT_CHARGE_SEPARATOR, "").count("_") > 0
Expand All @@ -328,8 +328,8 @@ def sort_charged_frag_types(charged_frag_types: List[str]) -> List[str]:


def get_charged_frag_types(
frag_types: List[str], max_frag_charge: int = 2
) -> List[str]:
frag_types: list[str], max_frag_charge: int = 2
) -> list[str]:
"""
Calculate the combination of fragment types and charge states.
Returns a sorted list of charged fragment types.
Expand Down Expand Up @@ -364,8 +364,8 @@ def get_charged_frag_types(


def filter_valid_charged_frag_types(
charged_frag_types: List[str],
) -> List[str]:
charged_frag_types: list[str],
) -> list[str]:
"""
Filters a list of charged fragment types and returns only the valid ones.
A valid charged fragment type must:
Expand Down Expand Up @@ -397,7 +397,7 @@ def filter_valid_charged_frag_types(
return valid_types


def parse_charged_frag_type(charged_frag_type: str) -> Tuple[str, int]:
def parse_charged_frag_type(charged_frag_type: str) -> tuple[str, int]:
"""
Oppsite to `get_charged_frag_types`.

Expand Down Expand Up @@ -440,8 +440,8 @@ def parse_charged_frag_type(charged_frag_type: str) -> Tuple[str, int]:


def init_zero_fragment_dataframe(
peplen_array: np.ndarray, charged_frag_types: List[str], dtype=PEAK_MZ_DTYPE
) -> Tuple[pd.DataFrame, np.ndarray, np.ndarray]:
peplen_array: np.ndarray, charged_frag_types: list[str], dtype=PEAK_MZ_DTYPE
) -> tuple[pd.DataFrame, np.ndarray, np.ndarray]:
"""Initialize a zero dataframe based on peptide length
(nAA) array (peplen_array) and charge_frag_types (column number).
The row number of returned dataframe is np.sum(peplen_array-1).
Expand Down Expand Up @@ -487,7 +487,7 @@ def init_fragment_dataframe_from_other(

def init_fragment_by_precursor_dataframe(
precursor_df,
charged_frag_types: List[str],
charged_frag_types: list[str],
*,
reference_fragment_df: pd.DataFrame = None,
dtype: np.dtype = PEAK_MZ_DTYPE,
Expand Down Expand Up @@ -572,8 +572,8 @@ def update_sliced_fragment_dataframe(
fragment_df: pd.DataFrame,
fragment_df_vals: np.ndarray,
values: np.ndarray,
frag_start_end_list: List[Tuple[int, int]],
charged_frag_types: List[str] = None,
frag_start_end_list: list[tuple[int, int]],
charged_frag_types: list[str] = None,
):
"""
Set the values of the slices `frag_start_end_list=[(start,end),(start,end),...]`
Expand Down Expand Up @@ -616,8 +616,8 @@ def update_sliced_fragment_dataframe(

def get_sliced_fragment_dataframe(
fragment_df: pd.DataFrame,
frag_start_end_list: Union[List, np.ndarray],
charged_frag_types: List = None,
frag_start_end_list: Union[list, np.ndarray],
charged_frag_types: list = None,
) -> pd.DataFrame:
"""
Get the sliced fragment_df from `frag_start_end_list=[(start,end),(start,end),...]`.
Expand Down Expand Up @@ -653,10 +653,10 @@ def get_sliced_fragment_dataframe(


def concat_precursor_fragment_dataframes(
precursor_df_list: List[pd.DataFrame],
fragment_df_list: List[pd.DataFrame],
precursor_df_list: list[pd.DataFrame],
fragment_df_list: list[pd.DataFrame],
*other_fragment_df_lists,
) -> Tuple[pd.DataFrame, ...]:
) -> tuple[pd.DataFrame, ...]:
"""
Since fragment_df is indexed by precursor_df, when we concatenate multiple
fragment_df, the indexed positions will change for in precursor_dfs,
Expand Down Expand Up @@ -914,7 +914,7 @@ def parse_fragment(
top_k: int,
intensities: np.ndarray,
number_of_fragment_types: int,
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
Parse fragments to get fragment numbers, fragment positions and not top k excluded indices in one hit
faster than doing each operation individually, and makes the most of the operations that are done in parallel.
Expand Down Expand Up @@ -979,8 +979,8 @@ def flatten_fragments(
min_fragment_intensity: float = -1,
keep_top_k_fragments: int = 1000,
custom_columns: list = ["type", "number", "position", "charge", "loss_type"],
custom_df: Dict[str, pd.DataFrame] = {},
) -> Tuple[pd.DataFrame, pd.DataFrame]:
custom_df: dict[str, pd.DataFrame] = {},
) -> tuple[pd.DataFrame, pd.DataFrame]:
"""
Converts the tabular fragment format consisting of
the `fragment_mz_df` and the `fragment_intensity_df`
Expand Down Expand Up @@ -1168,10 +1168,10 @@ def compress_fragment_indices(frag_idx):

def remove_unused_fragments(
precursor_df: pd.DataFrame,
fragment_df_list: Tuple[pd.DataFrame, ...],
fragment_df_list: tuple[pd.DataFrame, ...],
frag_start_col: str = "frag_start_idx",
frag_stop_col: str = "frag_stop_idx",
) -> Tuple[pd.DataFrame, Tuple[pd.DataFrame, ...]]:
) -> tuple[pd.DataFrame, tuple[pd.DataFrame, ...]]:
"""Removes unused fragments of removed precursors,
reannotates the `frag_start_col` and `frag_stop_col`

Expand Down Expand Up @@ -1220,7 +1220,7 @@ def remove_unused_fragments(

def create_fragment_mz_dataframe_by_sort_precursor(
precursor_df: pd.DataFrame,
charged_frag_types: List,
charged_frag_types: list,
batch_size: int = 500000,
dtype: np.dtype = PEAK_MZ_DTYPE,
) -> pd.DataFrame:
Expand Down Expand Up @@ -1277,7 +1277,7 @@ def create_fragment_mz_dataframe_by_sort_precursor(

def create_fragment_mz_dataframe(
precursor_df: pd.DataFrame,
charged_frag_types: List,
charged_frag_types: list,
*,
reference_fragment_df: pd.DataFrame = None,
inplace_in_reference: bool = False,
Expand Down
28 changes: 13 additions & 15 deletions alphabase/peptide/mass_calc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List, Tuple

import numpy as np

from alphabase.constants.aa import (
Expand All @@ -17,7 +15,7 @@


def calc_diff_modification_mass(
pep_len: int, mass_diffs: List[float], mass_diff_sites: List[int]
pep_len: int, mass_diffs: list[float], mass_diff_sites: list[int]
) -> np.ndarray:
"""
For open-search, we may also get modification
Expand Down Expand Up @@ -52,7 +50,7 @@ def calc_diff_modification_mass(


def calc_mod_diff_masses_for_same_len_seqs(
nAA: int, aa_mass_diffs_list: List[List[float]], mod_sites_list: List[List[int]]
nAA: int, aa_mass_diffs_list: list[list[float]], mod_sites_list: list[list[int]]
) -> np.ndarray:
"""
Calculate diff modification masses for the given peptide length (`nAA`),
Expand Down Expand Up @@ -96,11 +94,11 @@ def calc_mod_diff_masses_for_same_len_seqs(

def calc_b_y_and_peptide_mass(
sequence: str,
mod_names: List[str],
mod_sites: List[int],
aa_mass_diffs: List[float] = None,
aa_mass_diff_sites: List[int] = None,
) -> Tuple[np.ndarray, np.ndarray, float]:
mod_names: list[str],
mod_sites: list[int],
aa_mass_diffs: list[float] = None,
aa_mass_diff_sites: list[int] = None,
) -> tuple[np.ndarray, np.ndarray, float]:
"""
It is highly recommend to use
`calc_b_y_and_peptide_masses_for_same_len_seqs`
Expand All @@ -124,7 +122,7 @@ def calc_b_y_and_peptide_mass(


def calc_peptide_masses_for_same_len_seqs(
sequences: np.ndarray, mod_list: List[str], mod_diff_list: List[str] = None
sequences: np.ndarray, mod_list: list[str], mod_diff_list: list[str] = None
) -> np.ndarray:
"""
Calculate peptide masses for peptide sequences with same lengths.
Expand Down Expand Up @@ -171,11 +169,11 @@ def calc_peptide_masses_for_same_len_seqs(

def calc_b_y_and_peptide_masses_for_same_len_seqs(
sequences: np.ndarray,
mod_list: List[List[str]],
site_list: List[List[int]],
mod_diff_list: List[List[float]] = None,
mod_diff_site_list: List[List[int]] = None,
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
mod_list: list[list[str]],
site_list: list[list[int]],
mod_diff_list: list[list[float]] = None,
mod_diff_site_list: list[list[int]] = None,
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
Calculate b/y fragment masses and peptide masses
for peptide sequences with same lengths.
Expand Down
9 changes: 5 additions & 4 deletions alphabase/pg_reader/pg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import re
import warnings
from collections.abc import Iterable
from copy import deepcopy
from pathlib import Path
from typing import Any, Dict, Iterable, Optional, Type, Union
from typing import Any, Optional, Union

import pandas as pd

Expand Down Expand Up @@ -93,7 +94,7 @@ def __init__(

self.measurement_regex = self._get_measurement_regex(regex=measurement_regex)

def add_column_mapping(self, column_mapping: Dict) -> None:
def add_column_mapping(self, column_mapping: dict) -> None:
"""Add additional column mappings for the search engine."""
self.column_mapping = {**self.column_mapping, **column_mapping}

Expand Down Expand Up @@ -273,10 +274,10 @@ class PGReaderProvider:

def __init__(self):
"""Initialize PGReaderProvider."""
self.reader_dict: dict[str, Type[PGReaderBase]] = {}
self.reader_dict: dict[str, type[PGReaderBase]] = {}

def register_reader(
self, reader_type: str, reader_class: Type[PGReaderBase]
self, reader_type: str, reader_class: type[PGReaderBase]
) -> None:
"""Register a reader by reader_type."""
self.reader_dict[reader_type.lower()] = reader_class
Expand Down
Loading
Loading