{"data":{"slug":"github-aipoch-medical-research-skills-scientific-skills-data-analysis-matchms-a648d8152eac","title":"Process and Compare MS\/MS Spectra with Matchms","summary":"Process, clean, and compare mass spectrometry (MS\/MS) spectra with Matchms for reproducible spectral filtering and similarity scoring in metabolomics workflows. The deliverable includes similarity scores and processed spectra in configurable formats.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-matchms-a648d8152eac","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-matchms-a648d8152eac","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-matchms-a648d8152eac.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-matchms-a648d8152eac\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure Python 3.10+ is installed, and install required packages such as `matchms`, `numpy`, and `scipy` before running the script. Edit the in-file `CONFIG` block or documented parameters if the script uses fixed settings.","instructions":"---\nname: matchms\ndescription: Process, clean, and compare mass spectrometry (MS\/MS) spectra with Matchms; use when you need reproducible spectral filtering and similarity scoring for metabolomics workflows.\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n# Matchms Skill\n\n## When to Use\n\n- Use this skill when you need process, clean, and compare mass spectrometry (ms\/ms) spectra with matchms; use when you need reproducible spectral filtering and similarity scoring for metabolomics workflows in a reproducible workflow.\n- Use this skill when a data analytics task needs a packaged method instead of ad-hoc freeform output.\n- Use this skill when the user expects a concrete deliverable, validation step, or file-based result.\n- Use this skill when `scripts\/similarity_pipeline.py` is the most direct path to complete the request.\n- Use this skill when you need the `matchms` package behavior rather than a generic answer.\n\n## Key Features\n\n- Scope-focused workflow aligned to: Process, clean, and compare mass spectrometry (MS\/MS) spectra with Matchms; use when you need reproducible spectral filtering and similarity scoring for metabolomics workflows.\n- Packaged executable path(s): `scripts\/similarity_pipeline.py`.\n- Reference material available in `references\/` for task-specific guidance.\n- Structured execution path designed to keep outputs consistent and reviewable.\n\n## Dependencies\n\n- `Python`: `3.10+`. Repository baseline for current packaged skills.\n- `Third-party packages`: `not explicitly version-pinned in this skill package`. Add pinned versions if this skill needs stricter environment control.\n\n## Example Usage\n\n```bash\ncd \"20260316\/scientific-skills\/Data Analytics\/matchms\"\npython -m py_compile scripts\/similarity_pipeline.py\npython scripts\/similarity_pipeline.py --help\n```\n\nExample run plan:\n1. Confirm the user input, output path, and any required config values.\n2. Edit the in-file `CONFIG` block or documented parameters if the script uses fixed settings.\n3. Run `python scripts\/similarity_pipeline.py` with the validated inputs.\n4. Review the generated output and return the final artifact with any assumptions called out.\n\n## Implementation Details\n\n- Execution model: validate the request, choose the packaged workflow, and produce a bounded deliverable.\n- Input controls: confirm the source files, scope limits, output format, and acceptance criteria before running any script.\n- Primary implementation surface: `scripts\/similarity_pipeline.py`.\n- Reference guidance: `references\/` contains supporting rules, prompts, or checklists.\n- Parameters to clarify first: input path, output path, scope filters, thresholds, and any domain-specific constraints.\n- Output discipline: keep results reproducible, identify assumptions explicitly, and avoid undocumented side effects.\n\n## 1. When to Use\n\nUse this skill when you need to:\n\n- Import and harmonize MS\/MS spectra from common community formats (e.g., MGF\/MSP) before analysis.\n- Clean spectra (peak filtering, intensity normalization) to improve downstream similarity scoring and identification.\n- Compute spectral similarity (Cosine\/Modified Cosine\/Fingerprint-based) for library matching or clustering.\n- Build reproducible, configurable processing pipelines for metabolomics projects.\n- Compare many spectra efficiently (all-vs-all or query-vs-library) and store\/inspect score outputs.\n\n## 2. Key Features\n\n- **Import\/Export support**: Read spectra from mzML, mzXML, MGF, MSP, and JSON (depending on installed readers).\n- **Filtering & harmonization**: Metadata standardization, peak cleaning, intensity normalization, and other reusable filters.\n- **Similarity scoring**:\n  - Cosine similarity (Greedy\/Hungarian variants)\n  - Modified Cosine (accounts for precursor mass shifts)\n  - Fingerprint-based similarities (when molecular fingerprints are available)\n- **Pipeline composition**: Chain filters and scoring steps into repeatable workflows.\n\nAdditional reference material (if present in the repository):\n- Filters: `references\/filtering.md`\n- Similarity: `references\/similarity.md`\n- Workflows: `references\/workflows.md`\n\n## 3. Dependencies\n\n- `matchms` (version depends on your environment; pin in your project, e.g., `matchms>=0.20,<1.0`)\n- `numpy` (e.g., `numpy>=1.20`)\n- `scipy` (e.g., `scipy>=1.7`)\n- `rdkit` (optional; required for chemistry\/fingerprint-related functionality, version varies by distribution)\n\n## 4. Example Usage\n\nA minimal, runnable example that loads spectra from an MGF file and computes pairwise cosine scores:\n\n```python\nfrom matchms.importing import load_from_mgf\nfrom matchms import calculate_scores\nfrom matchms.similarity import CosineGreedy\n\ndef main():\n    # Load spectra from an MGF file\n    spectra = list(load_from_mgf(\"data.mgf\"))\n\n    # Compute similarity scores (all-vs-all)\n    scores = calculate_scores(\n        references=spectra,\n        queries=spectra,\n        similarity_function=CosineGreedy()\n    )\n\n    # Iterate over computed scores\n    for (reference_idx, query_idx, score, n_matches) in scores:\n        print(\n            f\"ref={reference_idx:>3} query={query_idx:>3} \"\n            f\"cosine={score:.4f} matches={n_matches}\"\n        )\n\nif __name__ == \"__main__\":\n    main()\n```\n\n## 5. Implementation Details\n\n- **Data model**: Matchms operates on `Spectrum` objects containing peak m\/z and intensity arrays plus metadata (e.g., precursor m\/z, charge, compound name\/identifier).\n- **Filtering stage**: Typical pipelines apply filters to:\n  - standardize\/repair metadata fields,\n  - remove noise peaks (e.g., by intensity threshold or m\/z window rules),\n  - normalize intensities (commonly to a maximum of 1.0 or to unit norm).\n  See `references\/filtering.md` for filter patterns and recommended sequences.\n- **Cosine similarity (Greedy\/Hungarian)**:\n  - Peaks are matched within an m\/z tolerance (implementation-specific defaults; configure via the similarity class parameters).\n  - **Greedy** matching selects best available peak matches iteratively.\n  - **Hungarian** matching solves an assignment problem to maximize total match score under one-to-one constraints.\n- **Modified Cosine**:\n  - Extends cosine matching by allowing peak alignment with a precursor mass shift, improving matching for related compounds\/adducts.\n  - Typically requires precursor m\/z metadata to be present and consistent.\n- **Fingerprint similarity (optional)**:\n  - Requires molecular fingerprints (often derived via RDKit) and compares spectra\/compounds using fingerprint similarity metrics.\n  - Use when you have structure annotations or can compute fingerprints reliably.\n- **Workflow reproducibility**:\n  - Prefer explicit, ordered filter chains and pinned dependency versions.\n  - Store configuration (tolerances, normalization choices, filters used) alongside results for traceability.\n  See `references\/workflows.md` for pipeline organization guidance.\n","use_cases":["Import and harmonize MS\/MS spectra from common formats like MGF\/MSP before analysis.","Clean spectra with peak filtering and intensity normalization to improve similarity scoring.","Compute spectral similarity scores (Cosine, Modified Cosine, Fingerprint-based) for library matching or clustering.","Build reproducible pipelines for metabolomics projects with configurable processing steps."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/aipoch\/medical-research-skills\/blob\/686e09dfdb45d9fa1a08664f06bb93769b3c9d91\/scientific-skills\/Data%20Analysis\/matchms\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T11:46:31.000000Z","updated_at":"2026-11-24T07:14:56.000000Z","seo_title":"Process and Compare MS\/MS Spectra with Matchms","seo_description":"Use Matchms to process, clean, and compare MS\/MS spectra for reproducible spectral filtering and similarity scoring in metabolomics workflows.","seo_keywords":["process MS\/MS spectra","compare mass spectrometry data","reproducible spectral analysis","metabolomics workflow","matchms similarity scoring"]}}