Skip to content

Lookup

mzmlpy.lookup.SpectrumLookup

SpectrumLookup(
    file_object: FileInterface,
    count: int | None = None,
    id_regex: str | None = None,
)

Bases: BaseLookup[Spectrum]

Lookup interface for spectra.

Source code in src/mzmlpy/lookup.py
14
15
16
17
def __init__(self, file_object: FileInterface, count: int | None = None, id_regex: str | None = None) -> None:
    self.file_object = file_object
    self._count = count
    self._id_regex = id_regex

count property

count: int | None

Get count of items.

get_by_index

get_by_index(index: int | str) -> T

Get item by index.

Source code in src/mzmlpy/lookup.py
38
39
40
41
42
def get_by_index(self, index: int | str) -> T:
    """Get item by index."""
    if isinstance(index, str):
        index = int(index)
    return self._get_by_index_impl(index)

get_by_id

get_by_id(identifier: str) -> T

Get item by ID.

Source code in src/mzmlpy/lookup.py
44
45
46
def get_by_id(self, identifier: str) -> T:
    """Get item by ID."""
    return self._get_by_id_impl(identifier)

get_by_slice

get_by_slice(slice_obj: slice) -> list[T]

Get items by slice notation.

Source code in src/mzmlpy/lookup.py
48
49
50
51
52
53
54
55
56
def get_by_slice(self, slice_obj: slice) -> list[T]:
    """Get items by slice notation."""
    if self.count is None:
        # Don't know count - must iterate all and slice
        items: list[T] = list(self)
        return items[slice_obj]
    # Know count - use slice.indices() to handle all cases
    start, stop, step = slice_obj.indices(self.count)
    return [self.get_by_index(i) for i in range(start, stop, step)]

next

next() -> T

Get next item using iterator.

Source code in src/mzmlpy/lookup.py
83
84
85
def next(self) -> T:
    """Get next item using iterator."""
    return next(iter(self))

mzmlpy.lookup.ChromatogramLookup

ChromatogramLookup(
    file_object: FileInterface,
    count: int | None = None,
    id_regex: str | None = None,
)

Bases: BaseLookup[Chromatogram]

Lookup interface for chromatograms.

Source code in src/mzmlpy/lookup.py
14
15
16
17
def __init__(self, file_object: FileInterface, count: int | None = None, id_regex: str | None = None) -> None:
    self.file_object = file_object
    self._count = count
    self._id_regex = id_regex

TIC property

Access Total Ion Chromatogram.

count property

count: int | None

Get count of items.

get_by_index

get_by_index(index: int | str) -> T

Get item by index.

Source code in src/mzmlpy/lookup.py
38
39
40
41
42
def get_by_index(self, index: int | str) -> T:
    """Get item by index."""
    if isinstance(index, str):
        index = int(index)
    return self._get_by_index_impl(index)

get_by_id

get_by_id(identifier: str) -> T

Get item by ID.

Source code in src/mzmlpy/lookup.py
44
45
46
def get_by_id(self, identifier: str) -> T:
    """Get item by ID."""
    return self._get_by_id_impl(identifier)

get_by_slice

get_by_slice(slice_obj: slice) -> list[T]

Get items by slice notation.

Source code in src/mzmlpy/lookup.py
48
49
50
51
52
53
54
55
56
def get_by_slice(self, slice_obj: slice) -> list[T]:
    """Get items by slice notation."""
    if self.count is None:
        # Don't know count - must iterate all and slice
        items: list[T] = list(self)
        return items[slice_obj]
    # Know count - use slice.indices() to handle all cases
    start, stop, step = slice_obj.indices(self.count)
    return [self.get_by_index(i) for i in range(start, stop, step)]

next

next() -> T

Get next item using iterator.

Source code in src/mzmlpy/lookup.py
83
84
85
def next(self) -> T:
    """Get next item using iterator."""
    return next(iter(self))