Skip to content

Chromatogram

mzmlpy.spectra.Chromatogram dataclass

Chromatogram(element: ElementTree.Element)

Bases: _ParamGroup, _BinaryDataArrayMixin

An mzML chromatogram element.

Exposes time and intensity binary arrays, optional precursor and product structures, and a chromatogram_type property (e.g. "tic", "basepeak", "srm").

id property

id: str

Get chromatogram id.

id_dict property

id_dict: dict[str, int | str]

Parse the native id into its key=value components (integer values coerced to int).

default_array_length property

default_array_length: int | None

Get chromatogram default array length, or None if not present.

source_file_ref property

source_file_ref: str | None

Get chromatogram source file reference, or None if not present.

time property

time: NDArray[np.float64] | None

Get time array as a numpy array, or None if not present.

intensity property

intensity: NDArray[np.float64] | None

Get intensity array as a numpy array, or None if not present.

has_precursor property

has_precursor: bool

Check if this chromatogram has a precursor.

precursor property

precursor: Precursor | None

Get a Precursor object for the precursor of this chromatogram, or None if no precursor is present.

has_product property

has_product: bool

Check if this chromatogram has a product.

product property

product: Product | None

Get a Product object for the product of this chromatogram, or None if no product is present.

data_processing_ref property

data_processing_ref: str | None

Get chromatogram data processing reference, or None if not present.

chromatogram_type property

chromatogram_type: (
    Literal[
        "emission",
        "sim",
        "basepeak",
        "pic",
        "tic",
        "absorption",
        "srm",
        "sic",
    ]
    | None
)

Get chromatogram type (e.g. TIC, BPC, etc.) for this chromatogram.

ns cached property

ns: str

Get XML namespace from the element tag.

cv_params cached property

cv_params: list[CvParam]

Parse cvParams from the XML element.

accessions cached property

accessions: set[str]

Get a set of all accession numbers from the cvParams.

names cached property

names: set[str]

Get a set of all names from the cvParams.

user_params property

user_params: list[UserParam]

Parse userParams from the XML element.

ref_params property

ref_params: list[ReferenceableParamGroupRef]

Get a list of all referenceable parameters from the XML element.

binary_arrays property

binary_arrays: list[BinaryDataArray]

Get a list of BinaryDataConverter objects for each binary data array.

get_cvparm

get_cvparm(id: str) -> CvParam | None

Get a cvParam by accession or name.

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

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 ValueError 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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 ValueError 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_cvparm(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 ValueError(
            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
127
128
129
130
131
132
133
134
135
136
137
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_cvparm(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 ValueError(
            f"CV param {cv_param.name or id!r} ({id}) has a non-integer value {cv_param.value!r}"
        ) from e

get_binary_array

get_binary_array(id: str) -> BinaryDataArray | None

Get a BinaryDataConverter object for the binary data array with the specified id.

Source code in src/mzmlpy/spectra.py
252
253
254
255
256
def get_binary_array(self, id: str) -> BinaryDataArray | None:
    """Get a BinaryDataConverter object for the binary data array with the specified id."""
    if self._binary_array_list is not None:
        return self._binary_array_list.get_binary_array(id)
    return None

has_binary_array

has_binary_array(id: str) -> bool

Check if a binary data array with the specified id exists.

Source code in src/mzmlpy/spectra.py
258
259
260
261
262
def has_binary_array(self, id: str) -> bool:
    """Check if a binary data array with the specified id exists."""
    if self._binary_array_list is not None:
        return self._binary_array_list.has_binary_array(id)
    return False

serialize

serialize() -> dict

return the full element content

Source code in src/mzmlpy/elems/dtree_wrapper.py
63
64
65
66
67
68
69
70
def serialize(self) -> dict:
    """return the full element content"""
    return {
        "tag": self.element.tag,
        "attributes": 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
72
73
74
def get_attribute(self, attr_name: str) -> str | None:
    """Get an attribute value from the element."""
    return self.element.attrib.get(attr_name)

has_cvparm

has_cvparm(id: str) -> bool

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

Source code in src/mzmlpy/elems/dtree_wrapper.py
107
108
109
def has_cvparm(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)

get_user_param

get_user_param(name: str) -> UserParam | None

Get a userParam by name.

Source code in src/mzmlpy/elems/dtree_wrapper.py
167
168
169
170
171
172
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
174
175
176
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
187
188
189
190
191
192
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
194
195
196
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)