Skip to content

Metadata

Software

mzmlpy.elems.software.Software dataclass

Software(element: ElementTree.Element)

Bases: _ParamGroup

Software used to acquire or process the data, identified by id and version.

id property

id: str

Get the software's id attribute.

Raises:

Type Description
ValueError

If the id attribute is missing.

version property

version: str | None

Get the software's version string, if present.

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.

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)

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

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)

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_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)

Sample

mzmlpy.elems.sample.Sample dataclass

Sample(element: ElementTree.Element)

Bases: _ParamGroup

A sample analyzed in the experiment, described by id, optional name, and CV parameters.

id property

id: str

Get the sample's id attribute.

Raises:

Type Description
ValueError

If the id attribute is missing.

name property

name: str | None

Get the sample's name, if present.

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.

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)

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

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)

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_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)

Run

mzmlpy.elems.run.Run dataclass

Run(element: ElementTree.Element)

Bases: _ParamGroup

The mzML run element containing instrument configuration, sample, and acquisition timestamp references.

id property

id: str | None

Get the run's id attribute.

default_instrument_configuration_ref property

default_instrument_configuration_ref: str | None

Get the id of the default instrument configuration for this run, if present.

default_source_file_ref property

default_source_file_ref: str | None

Get the id of the default source file for this run, if present.

sample_ref property

sample_ref: str | None

Get the id of the sample analyzed in this run, if present.

start_time_stamp property

start_time_stamp: datetime.datetime | None

Get the run's acquisition start time, if present and parseable.

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.

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)

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

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)

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_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)

ScanSetting

mzmlpy.elems.scan_setting.ScanSetting dataclass

ScanSetting(element: ElementTree.Element)

Bases: _ParamGroup

Scan acquisition settings including source file references and target m/z lists.

id property

id: str

Get the scan setting's id attribute.

Raises:

Type Description
ValueError

If the id attribute is missing.

source_file_refs property

source_file_refs: tuple[SourceFileRef, ...]

Get the referenced source files' ids for this scan setting.

targets property

targets: tuple[Target, ...]

Get the targeted m/z entries for this scan setting.

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.

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)

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

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)

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_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)

Target

mzmlpy.elems.scan_setting.Target dataclass

Target(element: ElementTree.Element)

Bases: _ParamGroup

A targeted m/z entry within a scan settings target list.

mz property

mz: float | None

Get the targeted m/z value, if present.

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.

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)

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

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)

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_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)

SourceFileRef

mzmlpy.elems.scan_setting.SourceFileRef dataclass

SourceFileRef(ref: str)

A reference to a source file by its id string.

ReferenceableParamGroup

mzmlpy.elems.referenceable_param_group.ReferenceableParamGroup dataclass

ReferenceableParamGroup(element: ElementTree.Element)

Bases: _ParamGroup

A named group of CV and user parameters that can be referenced by other elements to avoid repetition.

id property

id: str

Get the param group's id attribute, used by other elements to reference it.

Raises:

Type Description
ValueError

If the id attribute is missing.

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.

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)

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

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)

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_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)

ReferenceableParamGroupRef

mzmlpy.elems.params.ReferenceableParamGroupRef dataclass

ReferenceableParamGroupRef(ref: str)

A reference to a referenceable parameter group by its id string.