Skip to content

mscompress (top-level)

The entry-point module. Re-exports everything from mscompress._core, mscompress.mszx, mscompress.metadata, and mscompress.annotations.

read

read(
    path: Union[str, PathLike, bytes],
    *,
    cache=None,
    cache_spectra: int = CACHE_SPECTRA_AUTO,
) -> Union[MZMLFile, MSZFile, MSZXFile]

Read and parse mzML, MSZ, or MSZX files.

Both cache and cache_spectra are exposed only here; the file constructors deliberately don't expose them. read() is the single entry point for both knobs.

Parameters:

Name Type Description Default
path Union[str, PathLike, bytes]

Path to the file to read.

required
cache Optional[Union[BlockCache, int]]

Shared decompressed-block cache for MSZ/MSZX files. None (default) uses the process-wide default BlockCache; pass a BlockCache to share an explicit pool across files, an int to set a private byte budget, or 0 to disable bounding (legacy unbounded). Ignored for mzML inputs.

None
cache_spectra int

Per-file LRU cap for cached Spectrum objects. CACHE_SPECTRA_AUTO (-1, default) uses the bundled default; 0 disables eviction (legacy unbounded); N > 0 sets an explicit cap.

CACHE_SPECTRA_AUTO

Returns:

Type Description
Union[MZMLFile, MSZFile, MSZXFile]

Union[MZMLFile, MSZFile, MSZXFile]: Parsed file object. A v2 (batch)

Union[MZMLFile, MSZFile, MSZXFile]

.mszx returns an MSZXBatchFile collection instead.

Utility functions

A versatile compression tool for efficient management of mass-spectrometry data.

get_num_threads

get_num_threads() -> int

Get the number of available threads on the system.

Returns:

Type Description
int

Number of usable threads.

get_filesize

get_filesize(path: Union[str, bytes]) -> int

Get the size of a file in bytes.

Parameters:

Name Type Description Default
path Union[str, bytes]

Path to file (string or bytes).

required

Returns:

Type Description
int

Size of the file in bytes.

Raises:

Type Description
FileNotFoundError

If file does not exist.

list_algorithms

list_algorithms() -> list[AlgorithmInfo]

Return a list of available lossy algorithm descriptors from the C registry.

Top-level types

AlgorithmInfo

Bases: TypedDict

Descriptor for a lossy transformation algorithm.

SpectrumDict

Bases: TypedDict

Dictionary representing a spectrum's binary data arrays.

SpectrumTransform

Bases: Protocol

Protocol for spectrum transform callables.

A transform receives a SpectrumDict and returns a SpectrumDict. Both input and output must contain 'mz' and 'intensity' keys with NumPy arrays of equal length.