From c1ca60edc0fcb559a5762862e1f83233d607bb89 Mon Sep 17 00:00:00 2001 From: jalew188 Date: Fri, 21 Jun 2024 14:33:09 +0200 Subject: [PATCH 1/6] #64 use register_readers() to register readers --- docs/reader_modules.rst | 1 + docs/readers/mgf.rst | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 docs/readers/mgf.rst diff --git a/docs/reader_modules.rst b/docs/reader_modules.rst index 1a58965..79737e7 100644 --- a/docs/reader_modules.rst +++ b/docs/reader_modules.rst @@ -8,3 +8,4 @@ readers modules readers/thermo readers/sciex readers/mzml + readers/mgf diff --git a/docs/readers/mgf.rst b/docs/readers/mgf.rst new file mode 100644 index 0000000..de1ec01 --- /dev/null +++ b/docs/readers/mgf.rst @@ -0,0 +1,7 @@ +alpharaw.legacy_msdata.mgf +========================== + +.. automodule:: alpharaw.legacy_msdata.mgf + :members: + :undoc-members: + :show-inheritance: From 73a119298869e9b06d90d34fb991d0bc7338a947 Mon Sep 17 00:00:00 2001 From: jalew188 Date: Fri, 21 Jun 2024 14:33:28 +0200 Subject: [PATCH 2/6] #64 use register_readers() to register readers --- alpharaw/__init__.py | 22 ++++++++++------------ alpharaw/legacy_msdata/mgf.py | 7 ++++++- alpharaw/ms_data_base.py | 26 +++++++++++++++++--------- alpharaw/mzml.py | 13 +++++++++---- alpharaw/sciex.py | 15 ++++++++++----- alpharaw/thermo.py | 15 ++++++++++----- 6 files changed, 62 insertions(+), 36 deletions(-) diff --git a/alpharaw/__init__.py b/alpharaw/__init__.py index b19381b..de5af21 100644 --- a/alpharaw/__init__.py +++ b/alpharaw/__init__.py @@ -6,20 +6,18 @@ def register_readers(): - from .legacy_msdata import mgf # noqa: F401 # TODO remove import side effect - from .ms_data_base import ( - ms_reader_provider, # 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 - ) + from .legacy_msdata.mgf import register_readers as register_mgf_readers + from .mzml import register_readers as register_mzml_readers + + register_mzml_readers() + register_mgf_readers() try: - from .sciex import SciexWiffData # noqa: F401 # TODO remove import side effect - from .thermo import ( - ThermoRawData, # noqa: F401 # TODO remove import side effect - ) + from .sciex import register_readers as register_wiff_readers + from .thermo import register_readers as register_raw_readers + + register_wiff_readers() + register_raw_readers() except (RuntimeError, ImportError): print("[WARN] pythonnet is not installed") diff --git a/alpharaw/legacy_msdata/mgf.py b/alpharaw/legacy_msdata/mgf.py index cf57c18..447ce50 100644 --- a/alpharaw/legacy_msdata/mgf.py +++ b/alpharaw/legacy_msdata/mgf.py @@ -146,4 +146,9 @@ def _set_dataframes(self, raw_data: dict): ) -ms_reader_provider.register_reader("mgf", MGFReader) +def register_readers(): + """ + Register :class:`MGFReader` for file format "mgf" in + :obj:`alpharaw.ms_data_base.ms_reader_provider`. + """ + ms_reader_provider.register_reader("mgf", MGFReader) diff --git a/alpharaw/ms_data_base.py b/alpharaw/ms_data_base.py index 915ec85..3fd2546 100644 --- a/alpharaw/ms_data_base.py +++ b/alpharaw/ms_data_base.py @@ -440,8 +440,9 @@ def index_ragged_list(ragged_list: list) -> np.ndarray: class MSData_HDF(MSData_Base): """ Wrapper of reader for alpharaw's HDF5 spectrum file. - This class is registered as "alpharaw", "raw.hdf", "alpharaw_hdf", "hdf" and "hdf5" - in :obj:`ms_reader_provider` instance. + This class will be registered as file formats (types) + "alpharaw", "raw.hdf", "alpharaw_hdf", "hdf" and "hdf5" + in :obj:`ms_reader_provider` instance by :func:`register_readers`. """ def import_raw(self, _path: str): @@ -495,12 +496,19 @@ def get_reader( ms_reader_provider = MSReaderProvider() """ -MS data register (:class:`.MSReaderProvider`) performs as a factory to -produce different readers for different file formats. +MS data register (:class:`MSReaderProvider`) performs as a factory to +produce different readers for given file formats. """ -ms_reader_provider.register_reader("alpharaw", MSData_HDF) -ms_reader_provider.register_reader("raw.hdf", MSData_HDF) -ms_reader_provider.register_reader("alpharaw_hdf", MSData_HDF) -ms_reader_provider.register_reader("hdf", MSData_HDF) -ms_reader_provider.register_reader("hdf5", MSData_HDF) + +def register_readers(): + """ + Register :class:`MSData_HDF` for file formats (types): + "alpharaw", "raw.hdf", "alpharaw_hdf", "hdf", "hdf5" + in :obj:`ms_reader_provider`. + """ + ms_reader_provider.register_reader("alpharaw", MSData_HDF) + ms_reader_provider.register_reader("raw.hdf", MSData_HDF) + ms_reader_provider.register_reader("alpharaw_hdf", MSData_HDF) + ms_reader_provider.register_reader("hdf", MSData_HDF) + ms_reader_provider.register_reader("hdf5", MSData_HDF) diff --git a/alpharaw/mzml.py b/alpharaw/mzml.py index 9ad2232..e3d5b99 100644 --- a/alpharaw/mzml.py +++ b/alpharaw/mzml.py @@ -11,9 +11,9 @@ class MzMLReader(MSData_Base): """ - Load mzml file as `:class:`MSData_Base` structure. - This reader will be registered as "mzml" - in :obj:`alphraw.ms_data_base.ms_reader_provider`. + Load mzml file as `:class:`alpharaw.ms_data_base.MSData_Base` structure. + This reader will be registered as "mzml" in + :obj:`alphraw.ms_data_base.ms_reader_provider` by :func:`register_readers` """ def __init__(self, centroided: bool = True, save_as_hdf: bool = False, **kwargs): @@ -222,4 +222,9 @@ def parse_mzml_entry(item_dict: dict) -> tuple: ) -ms_reader_provider.register_reader("mzml", MzMLReader) +def register_readers(): + """ + Register :class:`MzMLReader` for file format "mzml" in + :obj:`alpharaw.ms_data_base.ms_reader_provider`. + """ + ms_reader_provider.register_reader("mzml", MzMLReader) diff --git a/alpharaw/sciex.py b/alpharaw/sciex.py index b4b4508..c14b488 100644 --- a/alpharaw/sciex.py +++ b/alpharaw/sciex.py @@ -7,9 +7,9 @@ class SciexWiffData(MSData_Base): """ - Load Sciex Wiff data as :class:`MSData_Base` data structure. + Load Sciex Wiff data as :class:`alpharaw.ms_data_base.MSData_Base` data structure. This reader will be registered as "sciex", "sciex_wiff", and "sciex_raw" - in :obj:`alpharaw.ms_data_base.ms_reader_provider`. + in :obj:`alpharaw.ms_data_base.ms_reader_provider` by :func:`register_readers()`. """ def __init__(self, centroided: bool = True, save_as_hdf: bool = False, **kwargs): @@ -62,6 +62,11 @@ def _import(self, _wiff_file_path: str) -> dict: return data_dict -ms_reader_provider.register_reader("sciex", SciexWiffData) -ms_reader_provider.register_reader("sciex_wiff", SciexWiffData) -ms_reader_provider.register_reader("sciex_raw", SciexWiffData) +def register_readers(): + """ + Register :class:`SciexWiffData` for file formats (types): + "sciex", "sciex_wiff", and "sciex_raw" in :obj:`alpharaw.ms_data_base.ms_reader_provider`. + """ + ms_reader_provider.register_reader("sciex", SciexWiffData) + ms_reader_provider.register_reader("sciex_wiff", SciexWiffData) + ms_reader_provider.register_reader("sciex_raw", SciexWiffData) diff --git a/alpharaw/thermo.py b/alpharaw/thermo.py index 242bed7..e32795a 100644 --- a/alpharaw/thermo.py +++ b/alpharaw/thermo.py @@ -51,9 +51,9 @@ class ThermoRawData(MSData_Base): """ - Loading Thermo Raw data as MSData_Base data structure. - This class is registered "thermo" and "thermo_raw" in - :obj:`alpharaw.ms_data_base.ms_reader_provider`. + Loading Thermo Raw data as :class:`alpharaw.ms_data_base.MSData_Base` data structure. + This class will be registered as file formats "thermo" and "thermo_raw" in + :obj:`alpharaw.ms_data_base.ms_reader_provider` by :func:`register_readers`. """ def __init__( @@ -372,5 +372,10 @@ def _get_mono_and_charge(trailer_data, scan_event): return mono, charge -ms_reader_provider.register_reader("thermo", ThermoRawData) -ms_reader_provider.register_reader("thermo_raw", ThermoRawData) +def register_readers(): + """ + Register :class:`ThermoRawData` for file formats (types): + "thermo" and "thermo_raw" in :obj:`alpharaw.ms_data_base.ms_reader_provider`. + """ + ms_reader_provider.register_reader("thermo", ThermoRawData) + ms_reader_provider.register_reader("thermo_raw", ThermoRawData) From be0cf31280cf951c7ea6778ee10c581c31401c5c Mon Sep 17 00:00:00 2001 From: jalew188 Date: Fri, 21 Jun 2024 14:43:56 +0200 Subject: [PATCH 3/6] #64 register_readers on __init__ --- alpharaw/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/alpharaw/__init__.py b/alpharaw/__init__.py index de5af21..e843c88 100644 --- a/alpharaw/__init__.py +++ b/alpharaw/__init__.py @@ -22,6 +22,9 @@ def register_readers(): print("[WARN] pythonnet is not installed") +register_readers() + + __project__ = "alpharaw" __version__ = "0.4.5" __license__ = "Apache" From 2272dd620e002bad6898b923f7697ac5b26cfd5a Mon Sep 17 00:00:00 2001 From: jalew188 Date: Mon, 24 Jun 2024 08:31:25 +0200 Subject: [PATCH 4/6] #64 remove reader register call in init --- alpharaw/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/alpharaw/__init__.py b/alpharaw/__init__.py index e843c88..03caef5 100644 --- a/alpharaw/__init__.py +++ b/alpharaw/__init__.py @@ -5,7 +5,7 @@ warnings.filterwarnings("ignore") -def register_readers(): +def register_all_readers(): from .legacy_msdata.mgf import register_readers as register_mgf_readers from .mzml import register_readers as register_mzml_readers @@ -22,9 +22,6 @@ def register_readers(): print("[WARN] pythonnet is not installed") -register_readers() - - __project__ = "alpharaw" __version__ = "0.4.5" __license__ = "Apache" From c320b12fd9d530acba6abf945bed8abb9b21a0d6 Mon Sep 17 00:00:00 2001 From: jalew188 Date: Mon, 24 Jun 2024 10:13:28 +0200 Subject: [PATCH 5/6] #64 FIX side effects of using register_readers() --- alpharaw/match/psm_match.py | 4 ++-- nbs_tests/legacy_msdata/mgf.ipynb | 5 ++++- nbs_tests/match/psm_match.ipynb | 5 ++++- nbs_tests/wrappers/alphatims_wrapper.ipynb | 5 ++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/alpharaw/match/psm_match.py b/alpharaw/match/psm_match.py index 0f5572c..be8b5d8 100644 --- a/alpharaw/match/psm_match.py +++ b/alpharaw/match/psm_match.py @@ -9,7 +9,7 @@ get_charged_frag_types, ) -from alpharaw import register_readers +from alpharaw import register_all_readers from alpharaw.dia.normal_dia import NormalDIAGrouper from alpharaw.match.match_utils import ( match_closest_peaks, @@ -24,7 +24,7 @@ ) from alpharaw.utils.ms_path_utils import parse_ms_files_to_dict -register_readers() # TODO remove this import side effect +register_all_readers() # TODO remove this import side effect class PepSpecMatch: diff --git a/nbs_tests/legacy_msdata/mgf.ipynb b/nbs_tests/legacy_msdata/mgf.ipynb index adf706d..4c2e4cc 100644 --- a/nbs_tests/legacy_msdata/mgf.ipynb +++ b/nbs_tests/legacy_msdata/mgf.ipynb @@ -22,7 +22,10 @@ "metadata": {}, "outputs": [], "source": [ - "from alpharaw.legacy_msdata.mgf import *" + "from alpharaw import register_all_readers\n", + "from alpharaw.legacy_msdata.mgf import *\n", + "\n", + "register_all_readers()" ] }, { diff --git a/nbs_tests/match/psm_match.ipynb b/nbs_tests/match/psm_match.ipynb index 5b7ad77..7f872c4 100644 --- a/nbs_tests/match/psm_match.ipynb +++ b/nbs_tests/match/psm_match.ipynb @@ -29,7 +29,10 @@ "metadata": {}, "outputs": [], "source": [ - "from alpharaw.match.psm_match import *" + "from alpharaw import register_all_readers\n", + "from alpharaw.match.psm_match import *\n", + "\n", + "register_all_readers()" ] }, { diff --git a/nbs_tests/wrappers/alphatims_wrapper.ipynb b/nbs_tests/wrappers/alphatims_wrapper.ipynb index 42eb351..0df8f1d 100644 --- a/nbs_tests/wrappers/alphatims_wrapper.ipynb +++ b/nbs_tests/wrappers/alphatims_wrapper.ipynb @@ -22,7 +22,10 @@ "metadata": {}, "outputs": [], "source": [ - "from alpharaw.wrappers.alphatims_wrapper import *" + "from alpharaw import register_all_readers\n", + "from alpharaw.wrappers.alphatims_wrapper import *\n", + "\n", + "register_all_readers()" ] }, { From 6b8156c1db7150a3afdf8ed9a36cfdff9dc04cda Mon Sep 17 00:00:00 2001 From: jalew188 Date: Thu, 27 Jun 2024 15:53:20 +0200 Subject: [PATCH 6/6] ADD register MSData_HDF by default --- alpharaw/ms_data_base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/alpharaw/ms_data_base.py b/alpharaw/ms_data_base.py index 3fd2546..4b09aac 100644 --- a/alpharaw/ms_data_base.py +++ b/alpharaw/ms_data_base.py @@ -512,3 +512,6 @@ def register_readers(): ms_reader_provider.register_reader("alpharaw_hdf", MSData_HDF) ms_reader_provider.register_reader("hdf", MSData_HDF) ms_reader_provider.register_reader("hdf5", MSData_HDF) + + +register_readers()