mscompress._core (Cython)¶
The C-backed core. These classes are defined in the Cython package; the
canonical signatures and docstrings come from
python/mscompress/_core.pyi.
Files¶
BaseFile
¶
Base class for mzML and MSZ file handlers.
compress_stream
¶
Compress this file and yield the MSZ output as byte chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_size
|
int
|
Number of bytes to read per iteration (default 1MB). |
...
|
Yields:
| Type | Description |
|---|---|
bytes
|
Chunks of compressed MSZ data. |
decompress_stream
¶
Decompress this file and yield the mzML output as byte chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_size
|
int
|
Number of bytes to read per iteration (default 1MB). |
...
|
Yields:
| Type | Description |
|---|---|
bytes
|
Chunks of decompressed mzML data. |
extract_stream
¶
extract_stream(
indicies: Optional[list[int]] = None,
scan_numbers: Optional[list[int]] = None,
ms_level: Optional[int] = None,
chunk_size: int = ...,
) -> Iterator[bytes]
Extract spectra and yield the mzML output as byte chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indicies
|
Optional[list[int]]
|
List of spectrum indices to extract (optional). |
None
|
scan_numbers
|
Optional[list[int]]
|
List of scan numbers to extract (optional). |
None
|
ms_level
|
Optional[int]
|
MS level to extract (optional). |
None
|
chunk_size
|
int
|
Number of bytes to read per iteration (default 1MB). |
...
|
Yields:
| Type | Description |
|---|---|
bytes
|
Chunks of extracted mzML data. |
extract
¶
extract(
output: Union[str, PathLike],
indicies: Optional[list[int]] = None,
scan_numbers: Optional[list[int]] = None,
ms_level: Optional[int] = None,
) -> Union[MZMLFile, MSZFile]
Extract specific spectra from a file to a new mzML or MSZ file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
Union[str, PathLike]
|
Output file path (string or path-like), must end in .msz or .mzML. |
required |
indicies
|
Optional[list[int]]
|
List of spectrum indices to extract (optional). |
None
|
scan_numbers
|
Optional[list[int]]
|
List of scan numbers to extract (optional). |
None
|
ms_level
|
Optional[int]
|
MS level to extract (optional). |
None
|
get_header
¶
Extract the complete mzML header as a raw string.
This function extracts the header portion of an mzML file (everything from the start of the file to the first spectrum element).
Returns:
| Type | Description |
|---|---|
str
|
The raw XML header string. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If header extraction fails. |
extract_metadata
¶
Extract and parse a specific XML tag from the mzML file header.
This method extracts the header portion of an mzML file, searches for a specific XML tag (e.g., 'referenceableParamGroupList', 'cvList', 'fileDescription'), strips any content outside of it, and parses that XML element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag_name
|
str
|
The name of the XML tag to extract (without namespace). |
required |
Returns:
| Type | Description |
|---|---|
Element
|
An xml.etree.ElementTree.Element containing the parsed XML tag. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the tag is not found in the header. |
RuntimeError
|
If header extraction fails. |
ParseError
|
If XML parsing fails. |
MZMLFile
¶
Bases: BaseFile
Handler for mzML format files.
compress
¶
compress(output: Union[str, PathLike]) -> MSZFile
Compress an mzML file to MSZ format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
Union[str, PathLike]
|
Output file path (string or path-like). |
required |
compress_stream
¶
Compress this mzML file and yield the MSZ output as byte chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_size
|
int
|
Number of bytes to read per iteration (default 1MB). |
...
|
Yields:
| Type | Description |
|---|---|
bytes
|
Chunks of compressed MSZ data. |
extract_stream
¶
extract_stream(
indicies: list[int] | None = ...,
scan_numbers: list[int] | None = ...,
ms_level: int | None = ...,
chunk_size: int = ...,
) -> Iterator[bytes]
Extract spectra from this mzML file and yield mzML output as byte chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indicies
|
list[int] | None
|
List of spectrum indices to extract (optional). |
...
|
scan_numbers
|
list[int] | None
|
List of scan numbers to extract (optional). |
...
|
ms_level
|
int | None
|
MS level to extract (optional). |
...
|
chunk_size
|
int
|
Number of bytes to read per iteration (default 1MB). |
...
|
Yields:
| Type | Description |
|---|---|
bytes
|
Chunks of extracted mzML data. |
get_mz_binary
¶
Extract m/z binary array for a spectrum at the given index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Spectrum index. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[Union[float32, float64]]
|
NumPy array of m/z values. |
get_inten_binary
¶
Extract intensity binary array for a spectrum at the given index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Spectrum index. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[Union[float32, float64]]
|
NumPy array of intensity values. |
get_xml
¶
Extract XML element for a spectrum at the given index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Spectrum index. |
required |
Returns:
| Type | Description |
|---|---|
Element
|
ElementTree Element containing spectrum metadata. |
MSZFile
¶
Bases: BaseFile
Handler for MSZ (compressed) format files.
decompress
¶
decompress(output: Union[str, PathLike]) -> MZMLFile
Decompress an MSZ file to mzML format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
Union[str, PathLike]
|
Output file path (string or path-like). |
required |
decompress_stream
¶
Decompress this MSZ file and yield the mzML output as byte chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_size
|
int
|
Number of bytes to read per iteration (default 1MB). |
...
|
Yields:
| Type | Description |
|---|---|
bytes
|
Chunks of decompressed mzML data. |
extract_stream
¶
extract_stream(
indicies: list[int] | None = ...,
scan_numbers: list[int] | None = ...,
ms_level: int | None = ...,
chunk_size: int = ...,
) -> Iterator[bytes]
Extract spectra from this MSZ file and yield mzML output as byte chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indicies
|
list[int] | None
|
List of spectrum indices to extract (optional). |
...
|
scan_numbers
|
list[int] | None
|
List of scan numbers to extract (optional). |
...
|
ms_level
|
int | None
|
MS level to extract (optional). |
...
|
chunk_size
|
int
|
Number of bytes to read per iteration (default 1MB). |
...
|
Yields:
| Type | Description |
|---|---|
bytes
|
Chunks of extracted mzML data. |
get_mz_binary
¶
Extract m/z binary array for a spectrum at the given index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Spectrum index. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[Union[float32, float64]]
|
NumPy array of m/z values. |
get_inten_binary
¶
Extract intensity binary array for a spectrum at the given index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Spectrum index. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[Union[float32, float64]]
|
NumPy array of intensity values. |
get_xml
¶
Extract XML element for a spectrum at the given index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Spectrum index. |
required |
Returns:
| Type | Description |
|---|---|
Element
|
ElementTree Element containing spectrum metadata. |
Spectra¶
Spectrum
¶
Spectrum(
index: int,
scan: int,
ms_level: int,
retention_time: float,
file: BaseFile,
transform: Optional[SpectrumTransform] = None,
)
Represents a single mass spectrum.
Spectra
¶
Spectra(f: BaseFile, df: DataFormat, positions: Division)
Collection of spectra with lazy loading and iteration support.
Allows indexing and iteration over all spectra in a file.
set_transform
¶
set_transform(
transform: Optional[SpectrumTransform],
) -> None
Set a transform function applied lazily to all spectra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
Optional[SpectrumTransform]
|
A callable (SpectrumDict) -> SpectrumDict, or None to clear. |
required |
with_transform
¶
with_transform(
transform: Optional[SpectrumTransform],
) -> Spectra
Return a new Spectra with the given transform, without modifying this one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
Optional[SpectrumTransform]
|
A callable (SpectrumDict) -> SpectrumDict, or None. |
required |
Returns:
| Type | Description |
|---|---|
Spectra
|
A new Spectra instance with the transform set. |
Metadata structures¶
DataFormat
¶
Data format information for mzML/MSZ files.
DataPositions
¶
Position information for data blocks in files.
Division
¶
Division structure containing data positions and scan information.
Configuration¶
RuntimeArguments
¶
Runtime configuration arguments for compression/decompression operations.