Skip to content

K-Dense-AI/scientific-agent-skills / skills/pyopenms

pyopenms

Verified

Processes mass spectrometry data with pyOpenMS. Supports proteomics and metabolomics workflows—feature detection, peptide/protein identification, label-free quantification, adduct/accurate-mass annotation, and complex LC-MS/MS pipelines. Supports extensive file formats and algorithms. For simple spectral comparison and small-molecule library matching use matchms.

scripts/extract_chromatograms.py

View on GitHub
#!/usr/bin/env python3
"""
Extract Ion Chromatograms (XIC/EIC) and TIC/BPC

Build chromatograms from MS1 data: total ion chromatogram (TIC), base peak
chromatogram (BPC), and extracted ion chromatograms (XIC) for target m/z values
within a ppm tolerance. Writes a tidy CSV (rt, trace, intensity) and optionally
a PNG plot.

Usage:
    python extract_chromatograms.py data.mzML --tic --bpc --out chrom.csv
    python extract_chromatograms.py data.mzML --mz 300.15 450.22 --ppm 10 --out xic.csv --plot xic.png
"""

import argparse
import os
import sys

try:
    import pyopenms as ms
    import numpy as np
except ImportError:
    print("Error: pyopenms/numpy not installed. Install with: uv pip install pyopenms")
    sys.exit(1)


def collect_ms1(exp):
    rts, mz_arrays, int_arrays = [], [], []
    for spec in exp:
        if spec.getMSLevel() != 1:
            continue
        mz, inten = spec.get_peaks()
        rts.append(spec.getRT())
        mz_arrays.append(mz)
        int_arrays.append(inten)
    return rts, mz_arrays, int_arrays


def main():
    parser = argparse.ArgumentParser(description="Extract TIC/BPC/XIC chromatograms.")
    parser.add_argument("input", help="Input mzML/mzXML")
    parser.add_argument("--tic", action="store_true", help="Compute total ion chromatogram")
    parser.add_argument("--bpc", action="store_true", help="Compute base peak chromatogram")
    parser.add_argument("--mz", type=float, nargs="+", help="Target m/z values for XIC")
    parser.add_argument("--ppm", type=float, default=10.0, help="XIC m/z tolerance in ppm (default 10)")
    parser.add_argument("--out", help="Output CSV (tidy: rt, trace, intensity)")
    parser.add_argument("--plot", help="Output PNG plot")
    args = parser.parse_args()

    if not (args.tic or args.bpc or args.mz):
        parser.error("request at least one of --tic, --bpc, or --mz")
    if not os.path.exists(args.input):
        print(f"Error: file not found: {args.input}")
        sys.exit(1)

    exp = ms.MSExperiment()
    ms.FileHandler().loadExperiment(args.input, exp)
    rts, mz_arrays, int_arrays = collect_ms1(exp)
    if not rts:
        parser.error("no MS1 scans available for TIC/BPC/XIC extraction")
    if args.ppm <= 0 or (args.mz and any(m <= 0 for m in args.mz)):
        parser.error("ppm and target m/z values must be positive")
    rts = np.array(rts)
    print(f"Collected {len(rts)} MS1 scans")

    traces = {}
    if args.tic:
        traces["TIC"] = np.array([a.sum() if len(a) else 0.0 for a in int_arrays])
    if args.bpc:
        traces["BPC"] = np.array([a.max() if len(a) else 0.0 for a in int_arrays])
    if args.mz:
        for target in args.mz:
            tol = target * args.ppm / 1e6
            trace = np.empty(len(rts))
            for i, (mz, inten) in enumerate(zip(mz_arrays, int_arrays)):
                mask = np.abs(mz - target) <= tol
                trace[i] = inten[mask].sum() if mask.any() else 0.0
            traces[f"XIC_{target:.4f}"] = trace
            apex = trace.argmax() if len(trace) else 0
            print(f"  XIC m/z {target:.4f}: apex RT {rts[apex]:.1f}s, max {trace[apex]:.3e}")

    if args.out:
        import csv
        with open(args.out, "w", newline="") as fh:
            w = csv.writer(fh)
            w.writerow(["rt", "trace", "intensity"])
            for name, trace in traces.items():
                for rt, val in zip(rts, trace):
                    w.writerow([f"{rt:.3f}", name, f"{val:.4f}"])
        print(f"Wrote {args.out}")

    if args.plot:
        import matplotlib
        matplotlib.use("Agg")
        import matplotlib.pyplot as plt
        plt.figure(figsize=(10, 5))
        for name, trace in traces.items():
            plt.plot(rts, trace, label=name, linewidth=1)
        plt.xlabel("Retention time (s)")
        plt.ylabel("Intensity")
        plt.legend()
        plt.title("Chromatograms")
        plt.tight_layout()
        plt.savefig(args.plot, dpi=150)
        print(f"Wrote {args.plot}")


if __name__ == "__main__":
    main()
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall