Skip to content

msmu._tools._precursor_purity

PrecursorPurityCalculator

PrecursorPurityCalculator(tolerance=20, unit_ppm=True)

A class to calculate precursor isolation purity from mzML files or MuData objects. This class can be initialized with a tolerance value and whether to use ppm for the calculation. This class is a wrapper around the OpenMS PrecursorPurity class and provides methods to calculate. pyopenms: https://pyopenms.readthedocs.io/en/latest/py-modindex.html#module-pyopenms.PrecursorPurity

Attributes:

Name Type Description
tolerance float

Tolerance for precursor purity calculation.

unit_ppm bool

Whether to use ppm for tolerance.

mzml Path | None

Path to the mzML file.

exp MSExperiment | None

OpenMS MSExperiment object loaded from the mzML file.

exp_src Path | None

Source path of the loaded MSExperiment.

exp_mtime float | None

Last modified time of the mzML file.

lock Lock

Thread lock for thread-safe access to the MSExperiment.

from_mudata classmethod

from_mudata(mdata, tolerance=20.0, unit_ppm=True)

Initialize PrecursorPurityCalculator from a MuData object.

Parameters:

Name Type Description Default
mdata MuData

MuData object containing PSM data.

required
tolerance float

Tolerance for precursor purity calculation.

20.0
unit_ppm bool

Whether to use ppm for tolerance.

True

PurityResult

PurityResult(purity, scan_num, filename)

to_df

to_df()

Convert the PurityResult to a pandas DataFrame.

Returns:

Type Description
DataFrame

pd.DataFrame: DataFrame containing purity, scan_num, and filename.

compute_precursor_purity

compute_precursor_purity(mzml_paths, tolerance=20.0, unit_ppm=True)

Calculate precursor isolation purity for all MS2 scans in the given mzML file.

Parameters:

Name Type Description Default
mzml_paths str | Path | list

Full path(s) to the mzML file.

required
tolerance float

Tolerance for precursor purity calculation.

20.0
unit_ppm bool

Whether to use ppm for tolerance.

True

Returns:

Type Description
PurityResult

pd.DataFrame: DataFrame with scan numbers and their corresponding purity scores.