LC-MS/MS run in open mzML format: SILAC-labelled HEK cell lysate on a Q Exactive, 8,098 spectra (quantitation test dataset): sample notebook

A worked notebook for LC-MS/MS run in open mzML format: SILAC-labelled HEK cell lysate on a Q Exactive, 8,098 spectra (quantitation test dataset), with 3 code cells and the output each one printed. On Scigantic it opens in a hosted JupyterLab with the dataset already mounted, so nothing is downloaded first.

Provider
Oliver Schilling, Florian Christoph Sigloch, Stefan Tholen (University of Freiburg); mirrored by Scigantic
License
CC-BY-4.0
Size
1 data file, 219,336,664 bytes
Stored at
Amazon S3, s3://scigantic-zenodo-1051552 (us-east-1)
Access
Free and public. No account with the data provider is needed.

The notebook

An LC-MS/MS run in open mzML

One run of a SILAC-labelled human embryonic kidney (HEK) cell lysate on a Thermo Q Exactive (light and heavy K6R6), converted from Thermo RAW with ProteoWizard and cut to the 2,000 to 3,000 s window of the run. 770 MS1 scans (profile mode) and 7,328 MS2 scans (centroided, HCD at collision energy 25). mzML is the open XML format for mass spectrometer output; this file is the open counterpart of the Thermo .raw archive on this portal.

Source: Schilling, Sigloch and Tholen, Zenodo 10.5281/zenodo.1051552, CC BY 4.0, mounted read-only at /mnt/archive.

Start here. Click the grey cell below and press Shift+Enter. It streams the file up to one scan and prints what the instrument recorded for it. Then change SCAN (0 to 8097) and run it again.

import os, xml.etree.ElementTree as ET
ROOT = os.environ.get("SCIGANTIC_MOUNT_PATH", "/mnt/archive")
SCAN = 1000

NS = "{http://psi.hupo.org/ms/mzml}"
for _, el in ET.iterparse(f"{ROOT}/HEK_SILAC-K6R6_ST905_part.mzml"):
    if el.tag == NS + "spectrum":
        if int(el.get("index")) == SCAN:
            cv = {c.get("name"): (c.get("value"), c.get("unitName")) for c in el.iter(NS + "cvParam")}
            print(el.get("id"))
            print(f"MS{cv['ms level'][0]} at {float(cv['scan start time'][0]):.1f} {cv['scan start time'][1]}s, {el.get('defaultArrayLength')} points")
            print("precursor m/z", cv.get("selected ion m/z", ("-",))[0], "charge", cv.get("charge state", ("-",))[0])
            break
        el.clear()

One pass over the whole file

The file is a plain without an offset index, so readers cannot jump to a scan; stream it once. Arrays are not compressed here: base64, then numpy.frombuffer, with m/z as 64-bit and intensity as 32-bit floats. Retention times are in seconds. The pass takes about a minute.

import base64, zlib
import numpy as np, pandas as pd

NS = "{http://psi.hupo.org/ms/mzml}"

def arrays(spec):
    out = {}
    for bda in spec.iter(NS + "binaryDataArray"):
        names = {c.get("name") for c in bda.iter(NS + "cvParam")}
        raw = base64.b64decode(bda.find(NS + "binary").text or "")
        if "zlib compression" in names:
            raw = zlib.decompress(raw)
        out["mz" if "m/z array" in names else "intensity"] = np.frombuffer(raw, "<f8" if "64-bit float" in names else "<f4")
    return out

rows, ms1 = [], None
for _, el in ET.iterparse(f"{ROOT}/HEK_SILAC-K6R6_ST905_part.mzml"):
    if el.tag != NS + "spectrum":
        continue
    cv = {c.get("name"): c.get("value") for c in el.iter(NS + "cvParam")}
    rows.append({"level": int(cv["ms level"]), "rt_s": float(cv["scan start time"]), "tic": float(cv["total ion current"]),
                 "charge": int(cv["charge state"]) if "charge state" in cv else None})
    if ms1 is None and cv["ms level"] == "1" and float(cv["scan start time"]) > 2500:
        ms1 = arrays(el)
    el.clear()
scans = pd.DataFrame(rows)
print(scans.level.value_counts().sort_index().to_dict(), "scans;", scans[scans.level == 2].charge.dropna().astype(int).value_counts().sort_index().to_dict(), "MS2 by charge")

Output:

{1: 770, 2: 7328} scans; {2: 3038, 3: 2955, 4: 983, 5: 253, 6: 69, 7: 22, 8: 8} MS2 by charge
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 2, figsize=(9, 3), dpi=80)
s1 = scans[scans.level == 1]
axes[0].plot(s1.rt_s, s1.tic, lw=0.8, color="#043874")
axes[0].set_xlabel("retention time (s)"); axes[0].set_title("MS1 total ion current")
axes[1].plot(ms1["mz"], ms1["intensity"], lw=0.5, color="#dc6c04")
axes[1].set_xlabel("m/z"); axes[1].set_title("One MS1 scan (profile)")
plt.tight_layout(); plt.show()

Notes

Run it

Open this notebook to run it, see the dataset page for the full description, or browse the full catalog.