Skip to content

Commit

Permalink
Merge pull request #45 from MannLabs/39-code-formatting-2
Browse files Browse the repository at this point in the history
39 code formatting 2
  • Loading branch information
mschwoer authored May 17, 2024
2 parents 29bff4c + aa1c67e commit 850114e
Show file tree
Hide file tree
Showing 46 changed files with 2,862 additions and 2,126 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ current_version = 0.4.5
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
serialize =
serialize =
{major}.{minor}.{patch}
{major}.{minor}.{patch}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ jobs:
cd tests
python download_test_data.py
. ./run_tests.sh
conda deactivate
conda deactivate
2 changes: 1 addition & 1 deletion .github/workflows/pip_installation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
install-script: "loose_pip_install.sh"
install-script: "loose_pip_install.sh"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ requires you to add the ppa to your trusted sources!
1. Install [brew](https://brew.sh).
2. Install mono: `brew install mono`.
3. If the pseudo mono folder `/Library/Frameworks/Mono.framework/Versions` does not exist, create it by running `sudo mkdir -p /Library/Frameworks/Mono.framework/Versions`.
4. Link homebrew mono to pseudo mono folder: `sudo ln -s /opt/homebrew/Cellar/mono/6.12.0.182 /Library/Frameworks/Mono.framework/Versions/Current`. Here, `6.12.0.182` is the brew-installed mono version, please check your installed version. Navigate to `/Library/Frameworks/Mono.framework/Versions` and run `ls -l` to verify that the link `Current` points to `/opt/homebrew/Cellar/mono/6.12.0.182`. If `Current` points to a different installation and/or `/opt/homebrew/Cellar/mono/6.12.0.182` is referenced by a different link, delete the corresponding links and run `sudo ln -s /opt/homebrew/Cellar/mono/6.12.0.182 Current`.
4. Link homebrew mono to pseudo mono folder: `sudo ln -s /opt/homebrew/Cellar/mono/6.12.0.182 /Library/Frameworks/Mono.framework/Versions/Current`. Here, `6.12.0.182` is the brew-installed mono version, please check your installed version. Navigate to `/Library/Frameworks/Mono.framework/Versions` and run `ls -l` to verify that the link `Current` points to `/opt/homebrew/Cellar/mono/6.12.0.182`. If `Current` points to a different installation and/or `/opt/homebrew/Cellar/mono/6.12.0.182` is referenced by a different link, delete the corresponding links and run `sudo ln -s /opt/homebrew/Cellar/mono/6.12.0.182 Current`.
5. Install pythonnet: `pip install pythonnet`.

------------------------------------------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions alpharaw/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
#!python

import warnings

warnings.filterwarnings("ignore")


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

try:
from .sciex import SciexWiffData
from .thermo import ThermoRawData
except (RuntimeError, ImportError):
print("[WARN] pythonnet is not installed")


__project__ = "alpharaw"
__version__ = "0.4.5"
__license__ = "Apache"
__description__ = "An open-source Python package to unify raw MS data access and storage."
__description__ = (
"An open-source Python package to unify raw MS data access and storage."
)
__author__ = "Mann Labs"
__author_email__ = "[email protected]"
__github__ = "https://github.com/MannLabs/alpharaw"
Expand All @@ -28,7 +34,7 @@ def register_readers():
"mass spectrometry",
"raw data",
"data access",
"data storage"
"data storage",
]
__python_version__ = ">=3.8"
__classifiers__ = [
Expand Down
47 changes: 29 additions & 18 deletions alpharaw/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,66 @@
from alpharaw.legacy_msdata import mgf
from alpharaw.mzml import MzMLReader
from alpharaw.wrappers import alphapept_wrapper

try:
from alpharaw.sciex import SciexWiffData
from alpharaw.thermo import ThermoRawData
except (RuntimeError, ImportError):
print("[WARN] pythonnet is not installed")


@click.group(
context_settings=dict(
help_option_names=['-h', '--help'],
help_option_names=["-h", "--help"],
),
invoke_without_command=True
invoke_without_command=True,
)
@click.pass_context
@click.version_option(alpharaw.__version__, "-v", "--version")
def run(ctx, **kwargs):
click.echo(
r'''
___ __ __ ___
r"""
___ __ __ ___
/ _ | / /__ / / ___ _/ _ \___ __ __
/ __ |/ / _ \/ _ \/ _ `/ , _/ _ `/ |/|/ /
/_/ |_/_/ .__/_//_/\_,_/_/|_|\_,_/|__,__/
/_/
/_/ |_/_/ .__/_//_/\_,_/_/|_|\_,_/|__,__/
/_/
....................................................
.{version}.
.{url}.
.{license}.
....................................................
'''.format(
version=alpharaw.__version__.center(50),
url=alpharaw.__github__.center(50),
license=alpharaw.__license__.center(50),
""".format(
version=alpharaw.__version__.center(50),
url=alpharaw.__github__.center(50),
license=alpharaw.__license__.center(50),
)
)
)
if ctx.invoked_subcommand is None:
click.echo(run.get_help(ctx))


@run.command("parse", help="Convert raw files into alpharaw hdf5 (.hdf) format.")
@click.option(
"--raw_type", type=str, default="thermo_raw",
show_default=True, help=f"Only `thermo_raw`, `sciex_wiff` is supported currently.",
"--raw_type",
type=str,
default="thermo_raw",
show_default=True,
help=f"Only `thermo_raw`, `sciex_wiff` is supported currently.",
)
@click.option(
"--raw", multiple=True, default=[],
show_default=True, help="Raw files, can be `--raw raw1 --raw raw2 ...`."
"--raw",
multiple=True,
default=[],
show_default=True,
help="Raw files, can be `--raw raw1 --raw raw2 ...`.",
)
def _parse(raw_type:str, raw:list):
def _parse(raw_type: str, raw: list):
reader = ms_reader_provider.get_reader(raw_type)
if reader is None:
print(f"{raw_type} is not supported, this may be due to the failed installion of PythonNet or other packages")
if reader is None:
print(
f"{raw_type} is not supported, this may be due to the failed installion of PythonNet or other packages"
)
else:
for raw_file in raw:
if not os.path.isfile(raw_file):
Expand Down
41 changes: 21 additions & 20 deletions alpharaw/dia/normal_dia.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,32 @@
from alpharaw.utils.timstof import convert_to_alphatims
from alphatims.bruker import TimsTOF

class NormalDIAGrouper():

class NormalDIAGrouper:
def __init__(self, ms_data: MSData_Base):
self.ms_data = ms_data
self.ms_data.spectrum_df[
"dia_group"
] = ms_data.spectrum_df.precursor_mz.astype(int)
self.ms_data.spectrum_df["dia_group"] = ms_data.spectrum_df.precursor_mz.astype(
int
)

self.dia_group_dfs = self.ms_data.spectrum_df.groupby("dia_group")
self.dia_isolation_dict = {}
for dia_group, df in self.dia_group_dfs:
if dia_group == -1: continue
if dia_group == -1:
continue
self.dia_isolation_dict[dia_group] = (
df.isolation_lower_mz.values[0],
df.isolation_upper_mz.values[0]
df.isolation_upper_mz.values[0],
)
self.dia_groups = np.sort(list(self.dia_isolation_dict.keys()))

def get_ms_data_for_a_group(self,
dia_group:int=-1,
return_alpharaw_data: bool=True,
return_alphatims_data: bool=True,
)->typing.Union[MSData_Base, TimsTOF, typing.Tuple[MSData_Base, TimsTOF]]:
""" Get compressed MS data for isolation window `dia_group`.
def get_ms_data_for_a_group(
self,
dia_group: int = -1,
return_alpharaw_data: bool = True,
return_alphatims_data: bool = True,
) -> typing.Union[MSData_Base, TimsTOF, typing.Tuple[MSData_Base, TimsTOF]]:
"""Get compressed MS data for isolation window `dia_group`.
Args:
dia_group (int, optional): The DIA group, -1 means ms1. Defaults to -1.
Expand All @@ -57,17 +60,15 @@ def get_ms_data_for_a_group(self,
else:
ms_data = MSData_Base()

spec_df, peak_df = remove_unused_peaks(
spec_df, self.ms_data.peak_df
)
spec_df, peak_df = remove_unused_peaks(spec_df, self.ms_data.peak_df)

ms_data.spectrum_df = spec_df
ms_data.peak_df = peak_df
return ms_data

def assign_dia_groups(self,
precursor_mzs
)->typing.DefaultDict[typing.List, typing.List]:
def assign_dia_groups(
self, precursor_mzs
) -> typing.DefaultDict[typing.List, typing.List]:
dia_precursor_groups = defaultdict(list)
for i, mz in enumerate(precursor_mzs):
i_group = np.searchsorted(self.dia_groups, int(mz))
Expand All @@ -81,9 +82,9 @@ def assign_dia_groups(self,
if mz >= isolation_lower and mz <= isolation_upper:
dia_precursor_groups[dia_group].append(i)
continue
dia_group = self.dia_groups[i_group-1]
dia_group = self.dia_groups[i_group - 1]
if dia_group in self.dia_isolation_dict:
isolation_lower, isolation_upper = self.dia_isolation_dict[dia_group]
if mz >= isolation_lower and mz <= isolation_upper:
dia_precursor_groups[dia_group].append(i)
return dia_precursor_groups
return dia_precursor_groups
4 changes: 2 additions & 2 deletions alpharaw/ext/thermo_fisher/THERMO_LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ These License terms are an agreement between you and Thermo Finnigan LLC ("Licen

1.1. You may install and use this Software on any of your computing devices.

1.2. You may distribute this Software to others, but only in combination with other software components and/or programs that you provide and subject to the distribution requirements and restrictions below.
1.2. You may distribute this Software to others, but only in combination with other software components and/or programs that you provide and subject to the distribution requirements and restrictions below.

2. Use Restrictions:

Expand Down Expand Up @@ -48,4 +48,4 @@ If you distribute this Software to others, you agree to:

5.8. LICENSOR’S TOTAL LIABILITY TO YOU FOR DIRECT DAMAGES ARISING UNDER THIS LICENSE IS LIMITED TO U.S. $1.00. YOU CANNOT RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, INDIRECT OR INCIDENTAL DAMAGES, EVEN IF LICENSOR IS EXPRESSLY MADE AWARE OF THE POSSIBILITY THEREOF OR IS NEGLIGENT. THIS LIMITATION APPLIES TO ANYTHING RELATED TO THIS SOFTWARE, SERVICES, CONTENT (INCLUDING CODE) ON THIRD PARTY INTERNET SITES, OR THIRD PARTY PROGRAMS, AND CLAIMS FOR BREACH OF CONTRACT, BREACH OF WARRANTY, GUARANTEE OR CONDITION, STRICT LIABILITY, NEGLIGENCE, OR OTHER TORT TO THE EXTENT PERMITTED BY APPLICABLE LAW.

5.9. Use, duplication or disclosure of this Software by the U.S. Government is subject to the restricted rights applicable to commercial computer software (under FAR 52.227019 and DFARS 252.227-7013 or parallel regulations). The manufacturer for this purpose is Thermo Finnigan LLC, 355 River Oaks Parkway, San Jose, California 95134, U.S.A.
5.9. Use, duplication or disclosure of this Software by the U.S. Government is subject to the restricted rights applicable to commercial computer software (under FAR 52.227019 and DFARS 252.227-7013 or parallel regulations). The manufacturer for this purpose is Thermo Finnigan LLC, 355 River Oaks Parkway, San Jose, California 95134, U.S.A.
Loading

0 comments on commit 850114e

Please sign in to comment.