Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

64 register readers #67

Merged
merged 8 commits into from
Jun 28, 2024
Merged
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
24 changes: 11 additions & 13 deletions alpharaw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
7 changes: 6 additions & 1 deletion alpharaw/legacy_msdata/mgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions alpharaw/match/psm_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down
29 changes: 20 additions & 9 deletions alpharaw/ms_data_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
13 changes: 9 additions & 4 deletions alpharaw/mzml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
15 changes: 10 additions & 5 deletions alpharaw/sciex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
15 changes: 10 additions & 5 deletions alpharaw/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions docs/reader_modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ readers modules
readers/thermo
readers/sciex
readers/mzml
readers/mgf
7 changes: 7 additions & 0 deletions docs/readers/mgf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
alpharaw.legacy_msdata.mgf
==========================

.. automodule:: alpharaw.legacy_msdata.mgf
:members:
:undoc-members:
:show-inheritance:
5 changes: 4 additions & 1 deletion nbs_tests/legacy_msdata/mgf.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
]
},
{
Expand Down
5 changes: 4 additions & 1 deletion nbs_tests/match/psm_match.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
]
},
{
Expand Down
5 changes: 4 additions & 1 deletion nbs_tests/wrappers/alphatims_wrapper.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
]
},
{
Expand Down
Loading