Skip to content

Data Processing

mzmlpy.elems.data_processing.DataProcessing dataclass

DataProcessing(element: ElementTree.Element)

Bases: _DataTreeWrapper

Named collection of ordered processing methods describing how spectral data was transformed.

id property

id: str

Get the data processing's id attribute.

Raises:

Type Description
ValueError

If the id attribute is missing.

processing_methods property

processing_methods: tuple[ProcessingMethod, ...]

Get the ordered processing methods applied under this data processing.

ns cached property

ns: str

Get XML namespace from the element tag.

serialize

serialize() -> dict[str, object]

Return the element as nested dicts: tag, attributes, text, children.

The result is a fresh copy; changing it does not change the wrapped element.

Source code in src/mzmlpy/elems/dtree_wrapper.py
def serialize(self) -> dict[str, object]:
    """Return the element as nested dicts: ``tag``, ``attributes``, ``text``, ``children``.

    The result is a fresh copy; changing it does not change the wrapped element.
    """
    return {
        "tag": self.element.tag,
        "attributes": dict(self.element.attrib),
        "text": self.element.text,
        "children": [_DataTreeWrapper(child).serialize() for child in self.element],
    }

get_attribute

get_attribute(attr_name: str) -> str | None

Get an attribute value from the element.

Source code in src/mzmlpy/elems/dtree_wrapper.py
def get_attribute(self, attr_name: str) -> str | None:
    """Get an attribute value from the element."""
    return self.element.attrib.get(attr_name)

ProcessingMethod

mzmlpy.elems.data_processing.ProcessingMethod dataclass

ProcessingMethod(element: ElementTree.Element)

Bases: _ParamGroup

A single data processing step applied to the spectral data, with an order index and software reference.

order property

order: int | None

Get this method's position in the processing order, if present.

software_ref property

software_ref: str | None

Get the referenced software's id, if present.

ns cached property

ns: str

Get XML namespace from the element tag.

cv_params cached property

cv_params: tuple[CvParam, ...]

The element's cvParams, in document order.

accessions cached property

accessions: frozenset[str]

All cvParam accessions.

names cached property

names: frozenset[str]

All cvParam names.

user_params cached property

user_params: tuple[UserParam, ...]

The element's userParams, in document order.

ref_params cached property

ref_params: tuple[ReferenceableParamGroupRef, ...]

The element's referenceableParamGroupRefs, in document order.

serialize

serialize() -> dict[str, object]

Return the element as nested dicts: tag, attributes, text, children.

The result is a fresh copy; changing it does not change the wrapped element.

Source code in src/mzmlpy/elems/dtree_wrapper.py
def serialize(self) -> dict[str, object]:
    """Return the element as nested dicts: ``tag``, ``attributes``, ``text``, ``children``.

    The result is a fresh copy; changing it does not change the wrapped element.
    """
    return {
        "tag": self.element.tag,
        "attributes": dict(self.element.attrib),
        "text": self.element.text,
        "children": [_DataTreeWrapper(child).serialize() for child in self.element],
    }

get_attribute

get_attribute(attr_name: str) -> str | None

Get an attribute value from the element.

Source code in src/mzmlpy/elems/dtree_wrapper.py
def get_attribute(self, attr_name: str) -> str | None:
    """Get an attribute value from the element."""
    return self.element.attrib.get(attr_name)

get_cv_param

get_cv_param(id: str) -> CvParam | None

Get a cvParam by accession or name, or None if absent.

Source code in src/mzmlpy/elems/dtree_wrapper.py
def get_cv_param(self, id: str) -> CvParam | None:
    """Get a cvParam by accession or name, or None if absent."""
    for cv_param in self.cv_params:
        if cv_param.accession == id or cv_param.name == id:
            return cv_param
    return None

has_cv_param

has_cv_param(id: str) -> bool

Check if a cvParam with the given accession or name exists.

Source code in src/mzmlpy/elems/dtree_wrapper.py
def has_cv_param(self, id: str) -> bool:
    """Check if a cvParam with the given accession or name exists."""
    return any(cv_param.accession == id or cv_param.name == id for cv_param in self.cv_params)

cv_float

cv_float(id: str) -> float | None

Return a cvParam's value as a float, or None if the term is absent or has no value.

Raises MzmlError naming the term and its bad value if the value is present but not numeric — more actionable than a bare "could not convert string to float".

Source code in src/mzmlpy/elems/dtree_wrapper.py
def cv_float(self, id: str) -> float | None:
    """Return a cvParam's value as a float, or None if the term is absent or has no value.

    Raises MzmlError naming the term and its bad value if the value is present but not
    numeric — more actionable than a bare "could not convert string to float".
    """
    cv_param = self.get_cv_param(id)
    if cv_param is None or cv_param.value is None:
        return None
    try:
        return float(cv_param.value)
    except ValueError as e:
        raise MzmlError(
            f"CV param {cv_param.name or id!r} ({id}) has a non-numeric value {cv_param.value!r}"
        ) from e

cv_int

cv_int(id: str) -> int | None

Return a cvParam's value as an int, or None if absent or valueless (see :meth:cv_float).

Source code in src/mzmlpy/elems/dtree_wrapper.py
def cv_int(self, id: str) -> int | None:
    """Return a cvParam's value as an int, or None if absent or valueless (see :meth:`cv_float`)."""
    cv_param = self.get_cv_param(id)
    if cv_param is None or cv_param.value is None:
        return None
    try:
        return int(cv_param.value)
    except ValueError as e:
        raise MzmlError(
            f"CV param {cv_param.name or id!r} ({id}) has a non-integer value {cv_param.value!r}"
        ) from e

get_user_param

get_user_param(name: str) -> UserParam | None

Get a userParam by name.

Source code in src/mzmlpy/elems/dtree_wrapper.py
def get_user_param(self, name: str) -> UserParam | None:
    """Get a userParam by name."""
    for user_param in self.user_params:
        if user_param.name == name:
            return user_param
    return None

has_user_param

has_user_param(name: str) -> bool

Check if a userParam with the given name exists.

Source code in src/mzmlpy/elems/dtree_wrapper.py
def has_user_param(self, name: str) -> bool:
    """Check if a userParam with the given name exists."""
    return any(user_param.name == name for user_param in self.user_params)

get_ref_param

get_ref_param(
    ref: str,
) -> ReferenceableParamGroupRef | None

Get a referenceable parameter by ref.

Source code in src/mzmlpy/elems/dtree_wrapper.py
def get_ref_param(self, ref: str) -> ReferenceableParamGroupRef | None:
    """Get a referenceable parameter by ref."""
    for ref_param in self.ref_params:
        if ref_param.ref == ref:
            return ref_param
    return None

has_ref_param

has_ref_param(ref: str) -> bool

Check if a referenceable parameter with the given ref exists.

Source code in src/mzmlpy/elems/dtree_wrapper.py
def has_ref_param(self, ref: str) -> bool:
    """Check if a referenceable parameter with the given ref exists."""
    return any(ref_param.ref == ref for ref_param in self.ref_params)