diff --git a/alpharaw/__init__.py b/alpharaw/__init__.py index b19381b..03caef5 100644 --- a/alpharaw/__init__.py +++ b/alpharaw/__init__.py @@ -5,21 +5,19 @@ warnings.filterwarnings("ignore") -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 - ) +def register_all_readers(): + 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/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/alpharaw/ms_data_base.py b/alpharaw/ms_data_base.py index 284730e..ac1eb71 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,22 @@ 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) + + +register_readers() 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) 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: 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()" ] }, {