Matchms

From XuShuwenn/RedAct · View interactive version

Matchms is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Parse MSP (mass spectrometry) files and count spectral data: spectrum count, peak count per spectrum, and total peak count. Use when users ask about mass spectrometry data parsing, spectral counting, or MSP file analysis.

How to use this skill

Skill file

Matchms: Mass Spectrometry Data Parsing

Overview

Matchms is a Python library for mass spectrometry data processing. This skill focuses on loading MSP (NIST Mass Spectral Library) files and extracting spectral information.

Loading MSP Files

from matchms.importing import load_from_msp

# Load MSP file
spectra = list(load_from_msp("/root/input.msp"))

Accessing Spectrum Data

Each spectrum has accessible properties. The MSP Name: field is stored in the compound_name metadata field:

for spectrum in spectra:
    # IMPORTANT: Use 'compound_name' not 'name' for MSP 'Name:' field
    name = spectrum.get("compound_name", "Unknown")
    peaks_mz = spectrum.peaks.mz          # Array of m/z values
    peaks_intensities = spectrum.peaks.intensities  # Array of intensities
    num_peaks = len(spectrum.peaks.mz)    # Number of peaks

Counting Spectra and Peaks

# Total number of spectra
total_spectra = len(spectra)

# Find spectrum with most peaks
max_peaks = 0
spectrum_with_most = None
for spectrum in spectra:
    peak_count = len(spectrum.peaks.mz)
    if peak_count > max_peaks:
        max_peaks = peak_count
        # Use 'compound_name' for the MSP Name: field
        spectrum_with_most = spectrum.get("compound_name", "Unknown")

# Total peaks across all spectra
total_peaks = sum(len(spectrum.peaks.mz) for spectrum in spectra)

Key Reference

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.