Skip to content

Commit

Permalink
Merge pull request #56 from MannLabs/53-docs-wiff-mzml
Browse files Browse the repository at this point in the history
53 docs wiff mzml
  • Loading branch information
jalew188 authored Jun 18, 2024
2 parents 34fb605 + bd34af7 commit e12ed10
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 10 deletions.
60 changes: 54 additions & 6 deletions alpharaw/mzml.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,50 @@


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`.
"""

def __init__(self, centroided: bool = True, save_as_hdf: bool = False, **kwargs):
"""
Parameters
----------
centroided : bool, optional
If peaks will be centroided after loading,
by default True.
save_as_hdf : bool, optional
Automatically save hdf after load raw data, by default False.
"""
super().__init__(centroided, save_as_hdf, **kwargs)

def _import(
self,
filename: str,
):
mzml_file_path: str,
) -> dict:
"""
Implementation of :func:`alpharaw.ms_data_base.MSData_Base._import` interface,
which will be called by :func:`alpharaw.ms_data_base.MSData_Base.import_raw`,
the main entry of :class:`alpharaw.ms_data_base.MSData_Base` sub-classes.
Parameters
----------
mzml_file_path : str
Absolute or relative path of the mzml file.
For testing purpose, this can be pyteomics `MzML` object as well.
Returns
-------
dict
Spectrum information dict.
"""
self.file_type = "mzml"
if isinstance(filename, str):
reader = mzml.read(filename, use_index=True)
if isinstance(mzml_file_path, str):
reader = mzml.read(mzml_file_path, use_index=True)
else:
reader = filename
reader = mzml_file_path
spec_indices = np.arange(len(reader), dtype=int)

rt_list = []
Expand Down Expand Up @@ -71,7 +106,7 @@ def _import(
isolation_lower_mz_list.append(isolation_lower_mz)
isolation_upper_mz_list.append(isolation_upper_mz)

if isinstance(filename, str):
if isinstance(mzml_file_path, str):
reader.close()

peak_indices = np.empty(len(spec_indices) + 1, np.int64)
Expand All @@ -96,6 +131,19 @@ def _import(


def parse_mzml_entry(item_dict: dict) -> tuple:
"""
Parse mzml entries from pyteomics extracted items.
Parameters
----------
item_dict : dict
pyteomics extracted items
Returns
-------
tuple
items in tuple format.
"""
rt = float(item_dict.get("scanList").get("scan")[0].get("scan start time"))
masses = item_dict.get("m/z array")
intensities = item_dict.get("intensity array")
Expand Down
23 changes: 19 additions & 4 deletions alpharaw/sciex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@

class SciexWiffData(MSData_Base):
"""
Loading Sciex Wiff data as MSData_Base data structure.
Load Sciex Wiff data as :class:`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`.
"""

def __init__(self, centroided: bool = True, save_as_hdf: bool = False, **kwargs):
"""
Parameters
----------
centroided : bool, optional
if peaks will be centroided after loading,
by default True
If peaks will be centroided after loading,
by default True.
save_as_hdf : bool, optional
automatically save hdf after load raw data, by default False.
Automatically save hdf after load raw data, by default False.
"""
super().__init__(centroided, save_as_hdf=save_as_hdf, **kwargs)
if self.centroided:
Expand All @@ -32,6 +34,19 @@ def __init__(self, centroided: bool = True, save_as_hdf: bool = False, **kwargs)
self.file_type = "sciex"

def _import(self, _wiff_file_path: str) -> dict:
"""
Implementation of :func:`alpharaw.ms_data_base.MSData_Base._import` interface.
Parameters
----------
_wiff_file_path : str
Absolute or relative path of the sciex wiff file.
Returns
-------
dict
Spectrum information dict.
"""
wiff_reader = pysciexwifffilereader.WillFileReader(_wiff_file_path)
data_dict = wiff_reader.load_sample(
self.sample_id,
Expand Down

0 comments on commit e12ed10

Please sign in to comment.