Turn any AI agent into an AI Scientist. The #1 Agent Skills library for science, used by 250,000+ scientists worldwide. 177 ready-to-use validated skills plus 100+ scientific databases covering biology, chemistry, medicine, and drug discovery. Compatible with Cursor, Claude Code, Codex, Pi, Antigravity, and the open Agent Skills standard.
Python agent-skillsai-scientistbioinformaticschemoinformaticsclaudeclaude-skillsclaudecodeclinical-researchcomputational-biologydata-analysisdrug-discoverygenomicsmaterials-sciencemetabolomicsproteomicsscientific-computingscientific-visualization
Update PyOpenMS skill
Timothy Kassisb8fea8f1a256
diff --git a/skills/pyopenms/SKILL.md b/skills/pyopenms/SKILL.mdindex 48ccdd67..faf4697d 100644--- a/skills/pyopenms/SKILL.md+++ b/skills/pyopenms/SKILL.md@@ -1,214 +1,177 @@---name: pyopenms-description: Complete mass spectrometry analysis platform. Use for proteomics workflows feature detection, peptide identification, protein quantification, and complex LC-MS/MS pipelines. Supports extensive file formats and algorithms. Best for proteomics, comprehensive MS data processing. For simple spectral comparison and metabolite ID use matchms.+description: Complete mass spectrometry analysis platform. Use for proteomics and metabolomics workflows—feature detection, peptide/protein identification, label-free and isobaric 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.license: 3 clause BSD license-metadata: {"version": "1.0", "skill-author": "K-Dense Inc."}+allowed-tools: Read Write Edit Bash+compatibility: Requires Python 3.9+ and uv. Examples and scripts target pyOpenMS 3.5.0.+metadata: {"version": "2.0", "skill-author": "K-Dense Inc."}---# PyOpenMS## Overview-PyOpenMS provides Python bindings to the OpenMS library for computational mass spectrometry, enabling analysis of proteomics and metabolomics data. Use for handling mass spectrometry file formats, processing spectral data, detecting features, identifying peptides/proteins, and performing quantitative analysis.+PyOpenMS provides Python bindings to the OpenMS library for computational mass+spectrometry, enabling analysis of proteomics and metabolomics data. Use it to+read/write MS file formats, process raw spectra, detect and quantify features,+identify peptides and proteins, and run end-to-end LC-MS/MS pipelines.-## Installation+**This skill ships ready-to-run scripts in `scripts/`** covering the most common+high-level workflows. Prefer running a script over writing new code—each is a+parameterized CLI tool that handles loading, processing, and export. Drop into the+Python API (and the `references/`) only when no script fits.-Install using uv:+## Installation```bashuv pip install pyopenms```-Verify installation:--```python-import pyopenms-print(pyopenms.__version__)-```--## Core Capabilities--PyOpenMS organizes functionality into these domains:--### 1. File I/O and Data Formats--Handle mass spectrometry file formats and convert between representations.--**Supported formats**: mzML, mzXML, TraML, mzTab, FASTA, pepXML, protXML, mzIdentML, featureXML, consensusXML, idXML--Basic file reading:+Verify (note: `__version__` works, but the bundled binary prints a one-line+memory-status notice on import that is harmless):```pythonimport pyopenms as ms--# Read mzML file-exp = ms.MSExperiment()-ms.MzMLFile().load("data.mzML", exp)--# Access spectra-for spectrum in exp:- mz, intensity = spectrum.get_peaks()- print(f"Spectrum: {len(mz)} peaks")-```--**For detailed file handling**: See `references/file_io.md`--### 2. Signal Processing--Process raw spectral data with smoothing, filtering, centroiding, and normalization.--Basic spectrum processing:--```python-# Smooth spectrum with Gaussian filter-gaussian = ms.GaussFilter()-params = gaussian.getParameters()-params.setValue("gaussian_width", 0.1)-gaussian.setParameters(params)-gaussian.filterExperiment(exp)-```--**For algorithm details**: See `references/signal_processing.md`--### 3. Feature Detection--Detect and link features across spectra and samples for quantitative analysis.--```python-# Detect features-ff = ms.FeatureFinder()-ff.run("centroided", exp, features, params, ms.FeatureMap())+print(ms.__version__) # 3.5.0```-**For complete workflows**: See `references/feature_detection.md`+## Scripts (start here)++Run with `python scripts/<name>.py --help` for full options. All accept standard+MS file formats and write featureXML/consensusXML/CSV/mzTab/PNG as appropriate.++### Inspect & convert+| Script | What it does |+|--------|--------------|+| `inspect_ms_data.py` | Summarize any mzML/mzXML/featureXML/consensusXML/idXML (counts, RT/m/z ranges, TIC, metadata); optional per-spectrum CSV. |+| `convert_format.py` | Convert between mzML/mzXML/MGF with optional MS-level, RT, and intensity filtering. |+| `process_spectra.py` | Configurable signal-processing chain: smoothing (Gauss/SGolay), centroiding (PeakPickerHiRes), normalization, S/N and intensity thresholds. |++### Feature detection & quantification+| Script | What it does |+|--------|--------------|+| `detect_features_metabo.py` | Untargeted metabolomics feature finding: MassTraceDetection → ElutionPeakDetection → FeatureFindingMetabo. |+| `detect_features_centroided.py` | Peptide/centroided feature detection via FeatureFinderAlgorithmPicked. |+| `align_link_quantify.py` | Multi-sample pipeline: detect (or load) features → RT alignment → consensus linking → quant matrix CSV. |+| `consensus_to_matrix.py` | consensusXML → wide intensity matrix + metadata, with optional median/quantile normalization and long format. |++### Annotation+| Script | What it does |+|--------|--------------|+| `detect_adducts.py` | Group adducts/charge variants of the same neutral mass (MetaboliteFeatureDeconvolution). |+| `accurate_mass_search.py` | Annotate features against HMDB by accurate mass (AccurateMassSearchEngine → mzTab/CSV). |+| `export_gnps_sirius.py` | Export GNPS FBMN inputs (MGF + quant table) or a SIRIUS `.ms` file. |++### Identification+| Script | What it does |+|--------|--------------|+| `process_identifications.py` | Re-index against FASTA, estimate FDR/q-values, filter (FDR/length/best-per-spectrum), export idXML + CSV. |++### Chemistry+| Script | What it does |+|--------|--------------|+| `mass_calculator.py` | Monoisotopic/average mass, charged m/z, formula, and isotope pattern for peptides or empirical formulas. |+| `digest_protein.py` | In-silico protease digestion of FASTA/sequence → theoretical peptides with masses and m/z. |+| `theoretical_spectrum.py` | Generate annotated theoretical fragment spectra (b/y/a/c/x/z, losses) for a peptide. |++### Targeted & visualization+| Script | What it does |+|--------|--------------|+| `extract_chromatograms.py` | Build TIC/BPC and XIC traces for target m/z (CSV + optional plot). |+| `plot_ms_data.py` | Quick plots: single spectrum, TIC, 2D feature map, MS1 signal map. |++### Common script recipes-### 4. Peptide and Protein Identification+```bash+# Inspect a file+python scripts/inspect_ms_data.py sample.mzML --spectra-csv spectra.csv-Integrate with search engines and process identification results.+# Untargeted metabolomics: features for one sample+python scripts/detect_features_metabo.py sample.mzML --out-csv features.csv-**Supported engines**: Comet, Mascot, MSGFPlus, XTandem, OMSSA, Myrimatch+# Full multi-sample quantification study+python scripts/align_link_quantify.py s1.mzML s2.mzML s3.mzML --out-prefix study+python scripts/consensus_to_matrix.py study.consensusXML --out quant.csv --normalize median-Basic identification workflow:+# Peptide chemistry+python scripts/mass_calculator.py --peptide "PEPTIDEM(Oxidation)K" --charges 1 2 3 --isotopes 5+python scripts/digest_protein.py proteins.fasta --enzyme Trypsin --missed 2 --out peptides.csv-```python-# Load identification data-protein_ids = []-peptide_ids = []-ms.IdXMLFile().load("identifications.idXML", protein_ids, peptide_ids)--# Apply FDR filtering-fdr = ms.FalseDiscoveryRate()-fdr.apply(peptide_ids)+# Identification post-processing+python scripts/process_identifications.py search.idXML --fasta db.fasta --fdr 0.01 --out filtered.idXML --csv hits.csv```-**For detailed workflows**: See `references/identification.md`--### 5. Metabolomics Analysis+## Key 3.5.0 API notes-Perform untargeted metabolomics preprocessing and analysis.+These changed from older OpenMS releases—older tutorials and code will break:-Typical workflow:-1. Load and process raw data-2. Detect features-3. Align retention times across samples-4. Link features to consensus map-5. Annotate with compound databases+- **Feature finding**: `FeatureFinder("centroided")` was **removed**. Use+ `FeatureFinderAlgorithmPicked` (proteomics/centroided) or the+ `MassTraceDetection → ElutionPeakDetection → FeatureFindingMetabo` pipeline+ (metabolomics). See `detect_features_*.py`.+- **idXML I/O**: `IdXMLFile().load/store` require a `ms.PeptideIdentificationList()`+ for peptide IDs (a plain Python `list` raises "can not handle type"). Protein IDs+ remain a plain list.+- **Adduct decharging**: the class is `MetaboliteFeatureDeconvolution`, and adducts+ use `Elements:Charge:Probability` syntax (e.g. `H:+:0.4`, `H-2O-1:0:0.05`)—not+ bracket notation like `[M+H]+`.+- **DataFrame columns**: `FeatureMap.get_df()` uses lowercase `rt`/`mz` (not `RT`).+ `ConsensusMap` provides `get_intensity_df()` and `get_metadata_df()`.+- **Bundled data caveat**: the pip wheel ships `HMDBMappingFile.tsv` but not+ `HMDB2StructMapping.tsv`; `accurate_mass_search.py` detects this and explains how+ to supply it.-**For complete metabolomics workflows**: See `references/metabolomics.md`+## Core data structures-## Data Structures+- **MSExperiment** – collection of spectra and chromatograms+- **MSSpectrum / MSChromatogram** – a single spectrum / chromatographic trace+- **Feature / FeatureMap** – a detected LC-MS peak / collection of features+- **ConsensusMap** – features linked across samples (the quant table)+- **PeptideIdentification / ProteinIdentification** – search results+- **AASequence / EmpiricalFormula** – sequence and formula chemistry-PyOpenMS uses these primary objects:+**For details**: see `references/data_structures.md`.-- **MSExperiment**: Collection of spectra and chromatograms-- **MSSpectrum**: Single mass spectrum with m/z and intensity pairs-- **MSChromatogram**: Chromatographic trace-- **Feature**: Detected chromatographic peak with quality metrics-- **FeatureMap**: Collection of features-- **PeptideIdentification**: Search results for peptides-- **ProteinIdentification**: Search results for proteins+## Parameter management-**For detailed documentation**: See `references/data_structures.md`--## Common Workflows--### Quick Start: Load and Explore Data+Most algorithms expose an OpenMS `Param` object:```python-import pyopenms as ms--# Load mzML file-exp = ms.MSExperiment()-ms.MzMLFile().load("sample.mzML", exp)--# Get basic statistics-print(f"Number of spectra: {exp.getNrSpectra()}")-print(f"Number of chromatograms: {exp.getNrChromatograms()}")--# Examine first spectrum-spec = exp.getSpectrum(0)-print(f"MS level: {spec.getMSLevel()}")-print(f"Retention time: {spec.getRT()}")-mz, intensity = spec.get_peaks()-print(f"Peaks: {len(mz)}")+algo = ms.FeatureFindingMetabo()+p = algo.getDefaults()+for key in p.keys():+ print(key.decode(), "=", p.getValue(key), "|", p.getDescription(key))+p.setValue("charge_lower_bound", 1)+algo.setParameters(p)```-### Parameter Management--Most algorithms use a parameter system:+## Export to pandas```python-# Get algorithm parameters-algo = ms.GaussFilter()-params = algo.getParameters()--# View available parameters-for param in params.keys():- print(f"{param}: {params.getValue(param)}")+fm = ms.FeatureMap(); ms.FeatureXMLFile().load("features.featureXML", fm)+df = fm.get_df() # columns include lowercase rt, mz, intensity, charge, quality-# Modify parameters-params.setValue("gaussian_width", 0.2)-algo.setParameters(params)+cm = ms.ConsensusMap(); ms.ConsensusXMLFile().load("study.consensusXML", cm)+intensities = cm.get_intensity_df() # features x samples+metadata = cm.get_metadata_df() # rt, mz, charge, quality, ...```-### Export to Pandas--Convert data to pandas DataFrames for analysis:--```python-import pyopenms as ms-import pandas as pd+## Integration with other tools-# Load feature map-fm = ms.FeatureMap()-ms.FeatureXMLFile().load("features.featureXML", fm)--# Convert to DataFrame-df = fm.get_df()-print(df.head())-```--## Integration with Other Tools--PyOpenMS integrates with:-- **Pandas**: Export data to DataFrames-- **NumPy**: Work with peak arrays-- **Scikit-learn**: Machine learning on MS data-- **Matplotlib/Seaborn**: Visualization-- **R**: Via rpy2 bridge+Pandas (DataFrames), NumPy (peak arrays), scikit-learn (ML), Matplotlib/Seaborn+(plots), and downstream tools via export: GNPS (FBMN), SIRIUS, and mzTab.## Resources-- **Official documentation**: https://pyopenms.readthedocs.io-- **OpenMS documentation**: https://www.openms.org-- **GitHub**: https://github.com/OpenMS/OpenMS+- Official docs (3.5.0): https://pyopenms.readthedocs.io/en/release-3.5.0/+- OpenMS: https://www.openms.org+- GitHub: https://github.com/OpenMS/OpenMS## References-- `references/file_io.md` - Comprehensive file format handling-- `references/signal_processing.md` - Signal processing algorithms-- `references/feature_detection.md` - Feature detection and linking-- `references/identification.md` - Peptide and protein identification-- `references/metabolomics.md` - Metabolomics-specific workflows-- `references/data_structures.md` - Core objects and data structures-+- `references/file_io.md` – file format handling+- `references/signal_processing.md` – signal processing algorithms+- `references/feature_detection.md` – feature detection and linking+- `references/identification.md` – peptide and protein identification+- `references/metabolomics.md` – metabolomics-specific workflows+- `references/data_structures.md` – core objects and data structuresdiff --git a/skills/pyopenms/references/data_structures.md b/skills/pyopenms/references/data_structures.mdindex 9f599b62..031b6f0d 100644--- a/skills/pyopenms/references/data_structures.md+++ b/skills/pyopenms/references/data_structures.md@@ -265,8 +265,9 @@ Identification results for a single spectrum.```python# Load identifications-protein_ids = []-peptide_ids = []+protein_ids = [] # protein IDs: plain list+# pyOpenMS 3.5+: peptide IDs must be a PeptideIdentificationList, not a plain list+peptide_ids = ms.PeptideIdentificationList()ms.IdXMLFile().load("identifications.idXML", protein_ids, peptide_ids)# Access peptide identificationdiff --git a/skills/pyopenms/references/feature_detection.md b/skills/pyopenms/references/feature_detection.mdindex b3cb1ff8..e732c7a5 100644--- a/skills/pyopenms/references/feature_detection.md+++ b/skills/pyopenms/references/feature_detection.md@@ -4,6 +4,10 @@Feature detection identifies persistent signals (chromatographic peaks) in LC-MS data. Feature linking combines features across multiple samples for quantitative comparison.+> **Ready-to-run scripts:** The skill ships CLIs that implement these workflows end to end: `scripts/detect_features_metabo.py` (metabolomics), `scripts/detect_features_centroided.py` (proteomics/centroided), `scripts/align_link_quantify.py` (alignment + linking + quant matrix), and `scripts/detect_adducts.py` (adduct grouping). Use them directly, or adapt the code below.++> **API note (pyOpenMS 3.5.0):** The old `FeatureFinder` class and its `run("centroided", ...)` API were **removed**. Metabolomics now uses the `MassTraceDetection` -> `ElutionPeakDetection` -> `FeatureFindingMetabo` pipeline, and centroided/proteomics data uses `FeatureFinderAlgorithmPicked`. The patterns below reflect the current API.+## Feature Detection BasicsA feature represents a chromatographic peak characterized by:@@ -15,9 +19,9 @@ A feature represents a chromatographic peak characterized by:## Feature Finding-### Feature Finder Multiples (FFM)+### Feature Finding for Metabolomics (FeatureFindingMetabo)-Standard algorithm for feature detection in centroided data:+For small molecules, run the three-stage pipeline that replaced the removed `FeatureFinder`: detect mass traces, split them into elution peaks, then assemble isotope-grouped features.```pythonimport pyopenms as ms@@ -25,22 +29,36 @@ import pyopenms as ms# Load centroided dataexp = ms.MSExperiment()ms.MzMLFile().load("centroided.mzML", exp)--# Create feature finder-ff = ms.FeatureFinder()--# Get default parameters-params = ff.getParameters("centroided")--# Modify key parameters-params.setValue("mass_trace:mz_tolerance", 10.0) # ppm-params.setValue("mass_trace:min_spectra", 7) # Min scans per feature-params.setValue("isotopic_pattern:charge_low", 1)-params.setValue("isotopic_pattern:charge_high", 4)--# Run feature detection+exp.sortSpectra(True)++# Stage 1: mass trace detection+mtd = ms.MassTraceDetection()+p = mtd.getDefaults()+p.setValue("mass_error_ppm", 10.0)+p.setValue("noise_threshold_int", 1000.0)+mtd.setParameters(p)+mass_traces = []+mtd.run(exp, mass_traces, 0)++# Stage 2: elution peak detection+epd = ms.ElutionPeakDetection()+p = epd.getDefaults()+p.setValue("width_filtering", "fixed")+epd.setParameters(p)+mt_split = []+epd.detectPeaks(mass_traces, mt_split)++# Stage 3: feature assembly with isotope grouping+ffm = ms.FeatureFindingMetabo()+p = ffm.getDefaults()+p.setValue("isotope_filtering_model", "metabolites (5% RMS)") # or "none"+p.setValue("remove_single_traces", "true")+p.setValue("charge_lower_bound", 1)+p.setValue("charge_upper_bound", 3)+ffm.setParameters(p)features = ms.FeatureMap()-ff.run("centroided", exp, features, params, ms.FeatureMap())+chrom_out = []+ffm.run(mt_split, features, chrom_out)print(f"Detected {features.size()} features")@@ -48,26 +66,28 @@ print(f"Detected {features.size()} features")ms.FeatureXMLFile().store("features.featureXML", features)```-### Feature Finder for Metabolomics+### Feature Finding for Proteomics (FeatureFinderAlgorithmPicked)-Optimized for small molecules:+For centroided peptide data, use `FeatureFinderAlgorithmPicked` (replaces the removed `FeatureFinder` "centroided" workflow):```python-# Create feature finder for metabolomics-ff = ms.FeatureFinder()--# Get metabolomics-specific parameters-params = ff.getParameters("centroided")+exp = ms.MSExperiment()+ms.MzMLFile().load("centroided.mzML", exp)+exp.sortSpectra(True)+exp.updateRanges()-# Configure for metabolomics-params.setValue("mass_trace:mz_tolerance", 5.0) # Lower tolerance-params.setValue("mass_trace:min_spectra", 5)-params.setValue("isotopic_pattern:charge_low", 1) # Mostly singly charged-params.setValue("isotopic_pattern:charge_high", 2)+ff = ms.FeatureFinderAlgorithmPicked()+params = ff.getDefaults()+params.setValue("isotopic_pattern:charge_low", 1)+params.setValue("isotopic_pattern:charge_high", 4)-# Run detectionfeatures = ms.FeatureMap()-ff.run("centroided", exp, features, params, ms.FeatureMap())+seeds = ms.FeatureMap()+# signature: run(input_map, output, param, seeds)+ff.run(exp, features, params, seeds)++print(f"Detected {features.size()} features")+ms.FeatureXMLFile().store("features.featureXML", features)```## Accessing Feature Data@@ -117,11 +137,11 @@ import pandas as pddf = feature_map.get_df()print(df.columns)-# Typical columns: RT, mz, intensity, charge, quality+# Columns are lowercase: rt, mz, intensity, charge, quality# Analyze featuresprint(f"Mean intensity: {df['intensity'].mean()}")-print(f"RT range: {df['RT'].min():.1f} - {df['RT'].max():.1f}")+print(f"RT range: {df['rt'].min():.1f} - {df['rt'].max():.1f}")```## Feature Linking@@ -136,14 +156,21 @@ fm1 = ms.FeatureMap()fm2 = ms.FeatureMap()ms.FeatureXMLFile().load("sample1.featureXML", fm1)ms.FeatureXMLFile().load("sample2.featureXML", fm2)+feature_maps = [fm1, fm2]-# Create aligner+# Pick the largest map as the alignment referencealigner = ms.MapAlignmentAlgorithmPoseClustering()--# Align maps-fm_aligned = []-transformations = []-aligner.align([fm1, fm2], fm_aligned, transformations)+ref_idx = max(range(len(feature_maps)), key=lambda i: feature_maps[i].size())+aligner.setReference(feature_maps[ref_idx])++# Align each non-reference map in place against the reference+transformer = ms.MapAlignmentTransformer()+for i, fm in enumerate(feature_maps):+ if i == ref_idx:+ continue+ trafo = ms.TransformationDescription()+ aligner.align(fm, trafo)+ transformer.transformRetentionTimes(fm, trafo, True)```### Feature Linking Algorithm@@ -167,9 +194,12 @@ feature_maps = [fm1, fm2, fm3]# Create consensus mapconsensus_map = ms.ConsensusMap()-# Link features+# Link features (feature_maps is a list of FeatureMap)grouper.group(feature_maps, consensus_map)+# Assign unique IDs before storing+consensus_map.setUniqueIds()+print(f"Created {consensus_map.size()} consensus features")# Save consensus map@@ -210,25 +240,41 @@ for map_idx, description in file_descriptions.items():print(f" Size: {description.size}")```+### Building Quant Matrices from a ConsensusMap++`ConsensusMap` exposes two DataFrame helpers that make quantitative tables easy:++```python+# Feature intensities, features (rows) x samples (columns)+intensity_df = consensus_map.get_intensity_df()++# Per-consensus-feature metadata: rt, mz, charge, quality+metadata_df = consensus_map.get_metadata_df()++# Join into a single annotated quant matrix+quant = metadata_df.join(intensity_df)+```+## Adduct Detection-Identify different ionization forms of the same molecule:+Identify different ionization forms of the same molecule. The class is `MetaboliteFeatureDeconvolution` (the old `MetaboliteAdductDecharger` does not exist in 3.5.0). Adducts are specified with `Elements:Charge:Probability` syntax, not bracket notation like `[M+H]+`:```python-# Create adduct detector-adduct_detector = ms.MetaboliteAdductDecharger()+# Create adduct deconvolution+mfd = ms.MetaboliteFeatureDeconvolution()# Configure parameters-params = adduct_detector.getParameters()-params.setValue("potential_adducts", "[M+H]+,[M+Na]+,[M+K]+,[M-H]-")-params.setValue("charge_min", 1)-params.setValue("charge_max", 1)-params.setValue("max_neutrals", 1)-adduct_detector.setParameters(params)--# Detect adducts-feature_map_out = ms.FeatureMap()-adduct_detector.compute(feature_map, feature_map_out, ms.ConsensusMap())+p = mfd.getDefaults()+p.setValue("potential_adducts", [b"H:+:0.4", b"Na:+:0.25", b"NH4:+:0.25", b"K:+:0.1", b"H-2O-1:0:0.05"])+p.setValue("charge_min", 1)+p.setValue("charge_max", 1)+mfd.setParameters(p)++# Detect adducts: compute(in, out, cons_groups, cons_edges)+fm_out = ms.FeatureMap()+groups = ms.ConsensusMap()+edges = ms.ConsensusMap()+mfd.compute(feature_map, fm_out, groups, edges)```## Complete Feature Detection Workflow@@ -249,22 +295,43 @@ def feature_detection_workflow(input_files, output_consensus):feature_maps = []- # Step 1: Detect features in each file+ # Step 1: Detect features in each file (metabolomics pipeline)for mzml_file in input_files:print(f"Processing {mzml_file}...")# Load experimentexp = ms.MSExperiment()ms.MzMLFile().load(mzml_file, exp)-- # Find features- ff = ms.FeatureFinder()- params = ff.getParameters("centroided")- params.setValue("mass_trace:mz_tolerance", 10.0)- params.setValue("mass_trace:min_spectra", 7)-+ exp.sortSpectra(True)++ # Mass trace detection+ mtd = ms.MassTraceDetection()+ p = mtd.getDefaults()+ p.setValue("mass_error_ppm", 10.0)+ p.setValue("noise_threshold_int", 1000.0)+ mtd.setParameters(p)+ mass_traces = []+ mtd.run(exp, mass_traces, 0)++ # Elution peak detection+ epd = ms.ElutionPeakDetection()+ p = epd.getDefaults()+ p.setValue("width_filtering", "fixed")+ epd.setParameters(p)+ mt_split = []+ epd.detectPeaks(mass_traces, mt_split)++ # Feature assembly+ ffm = ms.FeatureFindingMetabo()+ p = ffm.getDefaults()+ p.setValue("isotope_filtering_model", "metabolites (5% RMS)")+ p.setValue("remove_single_traces", "true")+ p.setValue("charge_lower_bound", 1)+ p.setValue("charge_upper_bound", 3)+ ffm.setParameters(p)features = ms.FeatureMap()- ff.run("centroided", exp, features, params, ms.FeatureMap())+ chrom_out = []+ ffm.run(mt_split, features, chrom_out)# Store filename in feature mapfeatures.setPrimaryMSRunPath([mzml_file.encode()])@@ -272,12 +339,18 @@ def feature_detection_workflow(input_files, output_consensus):feature_maps.append(features)print(f" Found {features.size()} features")- # Step 2: Align retention times+ # Step 2: Align retention times against the largest mapprint("Aligning retention times...")aligner = ms.MapAlignmentAlgorithmPoseClustering()- aligned_maps = []- transformations = []- aligner.align(feature_maps, aligned_maps, transformations)+ ref_idx = max(range(len(feature_maps)), key=lambda i: feature_maps[i].size())+ aligner.setReference(feature_maps[ref_idx])+ transformer = ms.MapAlignmentTransformer()+ for i, fm in enumerate(feature_maps):+ if i == ref_idx:+ continue+ trafo = ms.TransformationDescription()+ aligner.align(fm, trafo)+ transformer.transformRetentionTimes(fm, trafo, True)# Step 3: Link featuresprint("Linking features across samples...")@@ -289,7 +362,8 @@ def feature_detection_workflow(input_files, output_consensus):grouper.setParameters(params)consensus_map = ms.ConsensusMap()- grouper.group(aligned_maps, consensus_map)+ grouper.group(feature_maps, consensus_map)+ consensus_map.setUniqueIds()# Save resultsms.ConsensusXMLFile().store(output_consensus, consensus_map)@@ -352,8 +426,9 @@ for feature in feature_map:```python# Annotate features with peptide identifications# Load identifications+# pyOpenMS 3.5+: peptide IDs must be a PeptideIdentificationList, not a plain listprotein_ids = []-peptide_ids = []+peptide_ids = ms.PeptideIdentificationList()ms.IdXMLFile().load("identifications.idXML", protein_ids, peptide_ids)# Create ID mapper@@ -376,16 +451,26 @@ for feature in feature_map:Optimize parameters for your data type:```python-# Test different tolerance values+# Test different mass-trace tolerance values (metabolomics pipeline)mz_tolerances = [5.0, 10.0, 20.0] # ppmfor tol in mz_tolerances:- ff = ms.FeatureFinder()- params = ff.getParameters("centroided")- params.setValue("mass_trace:mz_tolerance", tol)-+ mtd = ms.MassTraceDetection()+ p = mtd.getDefaults()+ p.setValue("mass_error_ppm", tol)+ p.setValue("noise_threshold_int", 1000.0)+ mtd.setParameters(p)+ mass_traces = []+ mtd.run(exp, mass_traces, 0)++ epd = ms.ElutionPeakDetection()+ mt_split = []+ epd.detectPeaks(mass_traces, mt_split)++ ffm = ms.FeatureFindingMetabo()features = ms.FeatureMap()- ff.run("centroided", exp, features, params, ms.FeatureMap())+ chrom_out = []+ ffm.run(mt_split, features, chrom_out)print(f"Tolerance {tol} ppm: {features.size()} features")```@@ -401,7 +486,7 @@ df = feature_map.get_df()import matplotlib.pyplot as pltplt.figure(figsize=(10, 6))-plt.scatter(df['RT'], df['mz'], s=df['intensity']/1000, alpha=0.5)+plt.scatter(df['rt'], df['mz'], s=df['intensity']/1000, alpha=0.5)plt.xlabel('Retention Time (s)')plt.ylabel('m/z')plt.title('Feature Map')diff --git a/skills/pyopenms/references/file_io.md b/skills/pyopenms/references/file_io.mdindex 07d9e327..f726386e 100644--- a/skills/pyopenms/references/file_io.md+++ b/skills/pyopenms/references/file_io.md@@ -66,39 +66,48 @@ spec = indexed_mzml.getSpectrumById(100)spec = indexed_mzml.getSpectrumByNativeId("scan=5000")```-### Streaming Access+### Streaming / On-Disc Access-Memory-efficient processing for very large files:+Memory-efficient processing for very large files uses `OnDiscMSExperiment`,+which parses the index of an indexed mzML and loads spectra on demand instead of+holding the whole run in memory. (The old `MSExperimentConsumer` subclassing+pattern is not available in pyOpenMS 3.5.)```python-# Define consumer function-class SpectrumProcessor(ms.MSExperimentConsumer):- def __init__(self):- super().__init__()- self.count = 0-- def consumeSpectrum(self, spec):- # Process spectrum+# Requires an indexed mzML. Write one with the write-index option set:+exp = ms.MSExperiment()+ms.MzMLFile().load("large.mzML", exp)+f = ms.MzMLFile()+opt = f.getOptions(); opt.setWriteIndex(True); f.setOptions(opt)+f.store("large_indexed.mzML", exp)++# Now access spectra lazily, one at a time+od = ms.OnDiscMSExperiment()+if od.openFile("large_indexed.mzML"):+ count = 0+ for i in range(od.getNrSpectra()):+ spec = od.getSpectrum(i) # loaded from disk on demandif spec.getMSLevel() == 2:- self.count += 1--# Stream file-consumer = SpectrumProcessor()-ms.MzMLFile().transform("large.mzML", consumer)-print(f"Processed {consumer.count} MS2 spectra")+ count += 1+ print(f"Processed {count} MS2 spectra")```### Cached Access-Balance between memory usage and speed:+A cached binary representation trades a little disk space for faster repeated+reads. Use the static `CachedmzML.store`/`load` methods:```python-# Use on-disk caching-options = ms.CachedmzML()-options.setMetaDataOnly(False)-+# Write a cached representationexp = ms.MSExperiment()-ms.CachedmzMLHandler().load("sample.mzML", exp, options)+ms.MzMLFile().load("sample.mzML", exp)+ms.CachedmzML().store("sample.cachedmzML", exp)++# Load it back for on-demand spectrum access+cached = ms.CachedmzML()+ms.CachedmzML().load("sample.cachedmzML", cached)+print(f"{cached.getNrSpectra()} spectra")+spec = cached.getSpectrum(0)```## Writing mzML Files@@ -133,8 +142,9 @@ file_handler.store("compressed.mzML", exp)```python# Load identification results-protein_ids = []-peptide_ids = []+protein_ids = [] # protein IDs: plain list+# pyOpenMS 3.5+: peptide IDs must be a PeptideIdentificationList, not a plain list+peptide_ids = ms.PeptideIdentificationList()ms.IdXMLFile().load("identifications.idXML", protein_ids, peptide_ids)@@ -154,8 +164,8 @@ for peptide_id in peptide_ids:```python# Read mzIdentML-protein_ids = []-peptide_ids = []+protein_ids = [] # protein IDs: plain list+peptide_ids = ms.PeptideIdentificationList() # pyOpenMS 3.5+: not a plain listms.MzIdentMLFile().load("results.mzid", protein_ids, peptide_ids)```@@ -164,8 +174,8 @@ ms.MzIdentMLFile().load("results.mzid", protein_ids, peptide_ids)```python# Load pepXML-protein_ids = []-peptide_ids = []+protein_ids = [] # protein IDs: plain list+peptide_ids = ms.PeptideIdentificationList() # pyOpenMS 3.5+: not a plain listms.PepXMLFile().load("results.pep.xml", protein_ids, peptide_ids)```diff --git a/skills/pyopenms/references/identification.md b/skills/pyopenms/references/identification.mdindex 3da97960..fb40e81c 100644--- a/skills/pyopenms/references/identification.md+++ b/skills/pyopenms/references/identification.md@@ -4,6 +4,10 @@PyOpenMS supports peptide/protein identification through integration with search engines and provides tools for post-processing identification results including FDR control, protein inference, and annotation.+The skill ships ready-to-use CLI scripts: `scripts/process_identifications.py` performs FDR filtering and export on idXML files, and `scripts/inspect_ms_data.py` summarizes idXML (and other MS) files.++> **pyOpenMS 3.5+ API note:** `IdXMLFile().load()`/`store()` require the peptide-IDs argument to be a `ms.PeptideIdentificationList()`, not a plain Python list. Passing a plain list raises `Exception: can not handle type of (...)`. The protein-IDs argument is still a plain Python list.+## Supported Search EnginesPyOpenMS integrates with these search engines:@@ -24,8 +28,9 @@ PyOpenMS integrates with these search engines:import pyopenms as ms# Load identification results-protein_ids = []-peptide_ids = []+protein_ids = [] # protein IDs: plain list+# pyOpenMS 3.5+: peptide IDs must be a PeptideIdentificationList, not a plain list+peptide_ids = ms.PeptideIdentificationList()ms.IdXMLFile().load("identifications.idXML", protein_ids, peptide_ids)@@ -95,7 +100,7 @@ fdr.apply(peptide_ids)# Filter by FDR thresholdfdr_threshold = 0.01 # 1% FDR-filtered_peptide_ids = []+filtered_peptide_ids = ms.PeptideIdentificationList() # use push_back to add IDsfor peptide_id in peptide_ids:# Keep hits below FDR threshold@@ -106,7 +111,7 @@ for peptide_id in peptide_ids:if filtered_hits:peptide_id.setHits(filtered_hits)- filtered_peptide_ids.append(peptide_id)+ filtered_peptide_ids.push_back(peptide_id)print(f"Peptides passing FDR: {len(filtered_peptide_ids)}")```@@ -292,14 +297,18 @@ def identification_workflow(spectrum_file, fasta_file, output_file):search_params.missed_cleavages = 2search_params.modifications = ["Oxidation (M)", "Carbamidomethyl (C)"]- # Step 3: Run search (example with Comet adapter)- # Note: Requires search engine to be installed- # comet = ms.CometAdapter()- # protein_ids, peptide_ids = comet.search(exp, search_params)-- # For this example, load pre-computed results- protein_ids = []- peptide_ids = []+ # Step 3: Run the database search.+ # NOTE: OpenMS search engines (Comet, MSGFPlus, XTandem, ...) are exposed as+ # command-line TOPP tools, NOT pyOpenMS Python classes (there is no+ # ms.CometAdapter). Run them as a subprocess and read the idXML they emit, e.g.:+ # subprocess.run(["CometAdapter", "-in", "spectra.mzML",+ # "-database", fasta_file, "-out", "raw_identifications.idXML"])+ # These adapter executables ship with an OpenMS (not pyOpenMS) installation.++ # Here we load the pre-computed search results+ protein_ids = [] # protein IDs: plain list+ # pyOpenMS 3.5+: peptide IDs must be a PeptideIdentificationList, not a plain list+ peptide_ids = ms.PeptideIdentificationList()ms.IdXMLFile().load("raw_identifications.idXML", protein_ids, peptide_ids)print(f"Initial peptide IDs: {len(peptide_ids)}")@@ -309,7 +318,7 @@ def identification_workflow(spectrum_file, fasta_file, output_file):fdr.apply(peptide_ids)# Filter by 1% FDR- filtered_peptide_ids = []+ filtered_peptide_ids = ms.PeptideIdentificationList() # use push_back to add IDsfor peptide_id in peptide_ids:filtered_hits = []for hit in peptide_id.getHits():@@ -319,7 +328,7 @@ def identification_workflow(spectrum_file, fasta_file, output_file):if filtered_hits:peptide_id.setHits(filtered_hits)- filtered_peptide_ids.append(peptide_id)+ filtered_peptide_ids.push_back(peptide_id)print(f"Peptides after FDR (1%): {len(filtered_peptide_ids)}")diff --git a/skills/pyopenms/references/metabolomics.md b/skills/pyopenms/references/metabolomics.mdindex 617bf647..f5daf4f1 100644--- a/skills/pyopenms/references/metabolomics.md+++ b/skills/pyopenms/references/metabolomics.md@@ -4,6 +4,8 @@PyOpenMS provides specialized tools for untargeted metabolomics analysis including feature detection optimized for small molecules, adduct grouping, compound identification, and integration with metabolomics databases.+> **Code examples target pyOpenMS 3.5.0.** APIs removed in 3.5.0 (e.g. `FeatureFinder().run("centroided", ...)` and `MetaboliteAdductDecharger`) are not used here. The skill also ships ready-to-run scripts implementing these workflows end-to-end: `scripts/detect_features_metabo.py`, `scripts/align_link_quantify.py`, `scripts/consensus_to_matrix.py`, `scripts/detect_adducts.py`, `scripts/accurate_mass_search.py`, and `scripts/export_gnps_sirius.py`.+## Untargeted Metabolomics Pipeline### Complete Workflow@@ -20,7 +22,8 @@ def metabolomics_pipeline(input_files, output_dir):output_dir: Directory for output files"""- # Step 1: Peak picking and feature detection+ # Step 1: Feature detection (MassTraceDetection ->+ # ElutionPeakDetection -> FeatureFindingMetabo)feature_maps = []for mzml_file in input_files:@@ -29,26 +32,37 @@ def metabolomics_pipeline(input_files, output_dir):# Load dataexp = ms.MSExperiment()ms.MzMLFile().load(mzml_file, exp)-- # Peak picking if needed- if not exp.getSpectrum(0).isSorted():- picker = ms.PeakPickerHiRes()- exp_picked = ms.MSExperiment()- picker.pickExperiment(exp, exp_picked)- exp = exp_picked-- # Feature detection- ff = ms.FeatureFinder()- params = ff.getParameters("centroided")-- # Metabolomics-specific parameters- params.setValue("mass_trace:mz_tolerance", 5.0) # ppm, tighter for metabolites- params.setValue("mass_trace:min_spectra", 5)- params.setValue("isotopic_pattern:charge_low", 1)- params.setValue("isotopic_pattern:charge_high", 2) # Mostly singly charged-+ exp.sortSpectra(True)++ # Detect mass traces+ mtd = ms.MassTraceDetection()+ p = mtd.getDefaults()+ p.setValue("mass_error_ppm", 10.0)+ p.setValue("noise_threshold_int", 1000.0)+ mtd.setParameters(p)+ mass_traces = []+ mtd.run(exp, mass_traces, 0)++ # Split traces into elution peaks+ epd = ms.ElutionPeakDetection()+ p = epd.getDefaults()+ p.setValue("width_filtering", "fixed")+ epd.setParameters(p)+ mt_split = []+ epd.detectPeaks(mass_traces, mt_split)++ # Assemble metabolite features+ ffm = ms.FeatureFindingMetabo()+ p = ffm.getDefaults()+ p.setValue("isotope_filtering_model", "metabolites (5% RMS)")+ p.setValue("remove_single_traces", "true")+ p.setValue("charge_lower_bound", 1)+ p.setValue("charge_upper_bound", 3)+ ffm.setParameters(p)features = ms.FeatureMap()- ff.run("centroided", exp, features, params, ms.FeatureMap())+ chrom_out = []+ ffm.run(mt_split, features, chrom_out)+ features.setUniqueIds()features.setPrimaryMSRunPath([mzml_file.encode()])feature_maps.append(features)@@ -59,31 +73,37 @@ def metabolomics_pipeline(input_files, output_dir):print("Detecting adducts...")adduct_grouped_maps = []- adduct_detector = ms.MetaboliteAdductDecharger()- params = adduct_detector.getParameters()- params.setValue("potential_adducts", "[M+H]+,[M+Na]+,[M+K]+,[M+NH4]+,[M-H]-,[M+Cl]-")- params.setValue("charge_min", 1)- params.setValue("charge_max", 1)- adduct_detector.setParameters(params)-for fm in feature_maps:+ mfd = ms.MetaboliteFeatureDeconvolution()+ p = mfd.getDefaults()+ # potential_adducts uses Elements:Charge:Probability syntax+ p.setValue("potential_adducts",+ [b"H:+:0.4", b"Na:+:0.25", b"NH4:+:0.25",+ b"K:+:0.1", b"H-2O-1:0:0.05"])+ p.setValue("charge_min", 1)+ p.setValue("charge_max", 1)+ mfd.setParameters(p)+fm_out = ms.FeatureMap()- adduct_detector.compute(fm, fm_out, ms.ConsensusMap())+ groups = ms.ConsensusMap()+ edges = ms.ConsensusMap()+ mfd.compute(fm, fm_out, groups, edges) # 4 argsadduct_grouped_maps.append(fm_out)- # Step 3: RT alignment+ # Step 3: RT alignment (PoseClustering: pick a reference,+ # then align each map in place against it)print("Aligning retention times...")aligner = ms.MapAlignmentAlgorithmPoseClustering()+ reference = adduct_grouped_maps[0]+ aligner.setReference(reference)- params = aligner.getParameters()- params.setValue("max_num_peaks_considered", 1000)- params.setValue("pairfinder:distance_MZ:max_difference", 10.0)- params.setValue("pairfinder:distance_MZ:unit", "ppm")- aligner.setParameters(params)+ transformer = ms.MapAlignmentTransformer()+ for fm in adduct_grouped_maps:+ trafo = ms.TransformationDescription()+ aligner.align(fm, trafo)+ transformer.transformRetentionTimes(fm, trafo, True)- aligned_maps = []- transformations = []- aligner.align(adduct_grouped_maps, aligned_maps, transformations)+ aligned_maps = adduct_grouped_maps# Step 4: Feature linkingprint("Linking features...")@@ -96,23 +116,21 @@ def metabolomics_pipeline(input_files, output_dir):grouper.setParameters(params)consensus_map = ms.ConsensusMap()- grouper.group(aligned_maps, consensus_map)+ grouper.group(aligned_maps, consensus_map) # list of FeatureMap+ consensus_map.setUniqueIds()print(f"Created {consensus_map.size()} consensus features")- # Step 5: Gap filling (fill missing values)- print("Filling gaps...")- # Gap filling not directly available in Python API- # Would use TOPP tool FeatureFinderMetaboIdent-- # Step 6: Export results+ # Step 5: Export resultsconsensus_file = f"{output_dir}/consensus.consensusXML"ms.ConsensusXMLFile().store(consensus_file, consensus_map)- # Export to CSV for downstream analysis- df = consensus_map.get_df()+ # Export quant matrix for downstream analysis+ # get_intensity_df() -> features x samples; get_metadata_df() -> rt/mz/charge/quality+ intensities = consensus_map.get_intensity_df()+ metadata = consensus_map.get_metadata_df()csv_file = f"{output_dir}/metabolite_table.csv"- df.to_csv(csv_file, index=False)+ metadata.join(intensities).to_csv(csv_file)print(f"Results saved to {output_dir}")@@ -127,41 +145,43 @@ consensus = metabolomics_pipeline(input_files, "output")### Configure Adduct Types+Adducts are configured with the `Elements:Charge:Probability` syntax (e.g.+`b"Na:+:0.25"`), not bracket notation like `[M+Na]+`. Probabilities across the+list should sum to ~1.0.+```python# Create adduct detector-adduct_detector = ms.MetaboliteAdductDecharger()+mfd = ms.MetaboliteFeatureDeconvolution()# Configure common adducts-params = adduct_detector.getParameters()+params = mfd.getDefaults()-# Positive mode adducts+# Positive mode adducts (Elements:Charge:Probability)positive_adducts = [- "[M+H]+",- "[M+Na]+",- "[M+K]+",- "[M+NH4]+",- "[2M+H]+",- "[M+H-H2O]+"+ b"H:+:0.4",+ b"Na:+:0.25",+ b"NH4:+:0.25",+ b"K:+:0.1",+ b"H-2O-1:0:0.05", # neutral water loss]-# Negative mode adducts+# Negative mode adducts (set negative_mode="true" when using these)negative_adducts = [- "[M-H]-",- "[M+Cl]-",- "[M+FA-H]-", # Formate- "[2M-H]-"+ b"H-1:-:0.6",+ b"Cl:-:0.2",]# Set for positive mode-params.setValue("potential_adducts", ",".join(positive_adducts))+params.setValue("potential_adducts", positive_adducts)params.setValue("charge_min", 1)params.setValue("charge_max", 1)-params.setValue("max_neutrals", 1)-adduct_detector.setParameters(params)+mfd.setParameters(params)-# Apply adduct detection+# Apply adduct detection (4 args: in, out, groups, edges)feature_map_out = ms.FeatureMap()-adduct_detector.compute(feature_map, feature_map_out, ms.ConsensusMap())+groups = ms.ConsensusMap()+edges = ms.ConsensusMap()+mfd.compute(feature_map, feature_map_out, groups, edges)```### Access Adduct Information@@ -180,11 +200,38 @@ for feature in feature_map_out:## Compound Identification-### Mass-Based Annotation+### Accurate Mass Search (HMDB)++The built-in `AccurateMassSearchEngine` annotates a `FeatureMap` against HMDB+and writes results as mzTab.++> **Caveat:** the pip wheel ships `HMDBMappingFile.tsv` but **not**+> `HMDB2StructMapping.tsv`, so `engine.init()` fails unless you supply the+> struct file yourself. Download it from+> https://github.com/OpenMS/OpenMS/blob/develop/share/OpenMS/CHEMISTRY/HMDB2StructMapping.tsv+> and point `db:struct` at it.++```python+engine = ms.AccurateMassSearchEngine()+p = engine.getDefaults()+p.setValue("mass_error_value", 5.0)+p.setValue("mass_error_unit", "ppm")+p.setValue("ionization_mode", "positive")+# If the struct file is missing from the wheel, supply it:+# p.setValue("db:struct", b"/path/to/HMDB2StructMapping.tsv")+engine.setParameters(p)+engine.init()++mztab = ms.MzTab()+engine.run(feature_map, mztab)+ms.MzTabFile().store("out.mzTab", mztab)+```++### Mass-Based Annotation (custom database)```python-# Annotate features with compound database-from pyopenms import MassDecomposition+# Annotate features against your own compound list.+# (Plain Python, no pyOpenMS-specific DB required.)# Load compound database (example structure)# In practice, use external database like HMDB, METLIN@@ -280,8 +327,8 @@ for cons_feature in consensus_map_normalized:import pandas as pdimport numpy as np-# Export to pandas-df = consensus_map.get_df()+# Export intensities to pandas (features x samples)+df = consensus_map.get_intensity_df()# Assume QC samples are columns with 'QC' in nameqc_cols = [col for col in df.columns if 'QC' in col]@@ -324,8 +371,8 @@ if blank_cols and sample_cols:import pandas as pdimport numpy as np-# Load data-df = consensus_map.get_df()+# Load intensities (features x samples)+df = consensus_map.get_intensity_df()# Replace zeros with NaNdf = df.replace(0, np.nan)@@ -452,21 +499,40 @@ export_for_metaboanalyst(df, "for_metaboanalyst.csv")Test parameters on pooled QC sample:```python-# Test different mass trace parameters-mz_tolerances = [3.0, 5.0, 10.0]-min_spectra_values = [3, 5, 7]--for tol in mz_tolerances:- for min_spec in min_spectra_values:- ff = ms.FeatureFinder()- params = ff.getParameters("centroided")- params.setValue("mass_trace:mz_tolerance", tol)- params.setValue("mass_trace:min_spectra", min_spec)-+# Test different mass trace detection parameters+mass_errors_ppm = [3.0, 5.0, 10.0]+noise_thresholds = [500.0, 1000.0, 2000.0]++exp.sortSpectra(True)++for mass_err in mass_errors_ppm:+ for noise in noise_thresholds:+ mtd = ms.MassTraceDetection()+ p = mtd.getDefaults()+ p.setValue("mass_error_ppm", mass_err)+ p.setValue("noise_threshold_int", noise)+ mtd.setParameters(p)+ mass_traces = []+ mtd.run(exp, mass_traces, 0)++ epd = ms.ElutionPeakDetection()+ p = epd.getDefaults()+ p.setValue("width_filtering", "fixed")+ epd.setParameters(p)+ mt_split = []+ epd.detectPeaks(mass_traces, mt_split)++ ffm = ms.FeatureFindingMetabo()+ p = ffm.getDefaults()+ p.setValue("isotope_filtering_model", "metabolites (5% RMS)")+ p.setValue("remove_single_traces", "true")+ ffm.setParameters(p)features = ms.FeatureMap()- ff.run("centroided", exp, features, params, ms.FeatureMap())+ chrom_out = []+ ffm.run(mt_split, features, chrom_out)- print(f"tol={tol}, min_spec={min_spec}: {features.size()} features")+ print(f"mass_error_ppm={mass_err}, noise={noise}: "+ f"{features.size()} features")```### Retention Time Windowsdiff --git a/skills/pyopenms/references/signal_processing.md b/skills/pyopenms/references/signal_processing.mdindex f0940964..c8184354 100644--- a/skills/pyopenms/references/signal_processing.md+++ b/skills/pyopenms/references/signal_processing.md@@ -11,18 +11,22 @@ Most signal processing algorithms follow a standard pattern:```pythonimport pyopenms as ms-# 1. Create algorithm instance-algo = ms.AlgorithmName()+# 1. Create algorithm instance (GaussFilter shown as a concrete example)+algo = ms.GaussFilter()# 2. Get and modify parametersparams = algo.getParameters()-params.setValue("parameter_name", value)+params.setValue("gaussian_width", 0.2)algo.setParameters(params)# 3. Apply to dataalgo.filterExperiment(exp) # or filterSpectrum(spec)```+> **Tip:** `scripts/process_spectra.py` runs a configurable smoothing →+> centroiding → normalization → thresholding chain from the command line, so you+> rarely need to wire these steps up by hand.+## Smoothing### Gaussian Filter@@ -87,22 +91,26 @@ exp_picked = ms.MSExperiment()peak_picker.pickExperiment(exp, exp_picked)```-### Peak Picker for CWT+### Iterative Peak Picker-Continuous wavelet transform-based peak picking:+The CWT-based `PeakPickerCWT` was removed in modern OpenMS. For data where+`PeakPickerHiRes` struggles (e.g. broader or low-resolution peaks), use+`PeakPickerIterative`, which refits peak widths over several iterations:```python-# Create CWT peak picker-cwt_picker = ms.PeakPickerCWT()+# Create iterative peak picker+it_picker = ms.PeakPickerIterative()# Configure parameters-params = cwt_picker.getParameters()-params.setValue("signal_to_noise", 1.0)-params.setValue("peak_width", 0.15) # Expected peak width-cwt_picker.setParameters(params)+params = it_picker.getParameters()+params.setValue("signal_to_noise_", 1.0)+params.setValue("peak_width", 0.15) # expected peak width+params.setValue("nr_iterations_", 5)+it_picker.setParameters(params)# Pick peaks-cwt_picker.pickExperiment(exp, exp_picked)+exp_picked = ms.MSExperiment()+it_picker.pickExperiment(exp, exp_picked)```## Normalization@@ -235,27 +243,30 @@ params.setValue("charge_max", 4)params.setValue("potential_charge_states", "1,2,3,4")deconvoluter.setParameters(params)-# Apply deconvolution+# Apply deconvolution. Input is a FeatureMap (not an MSExperiment); the two+# ConsensusMaps receive the charge groups and the connecting edges.feature_map_out = ms.FeatureMap()-deconvoluter.compute(exp, feature_map, feature_map_out, ms.ConsensusMap())+groups = ms.ConsensusMap()+edges = ms.ConsensusMap()+deconvoluter.compute(feature_map, feature_map_out, groups, edges)```-### Isotope Deconvolution+### Deisotoping a Spectrum-Remove isotopic patterns:+The `IsotopeWaveletTransform` algorithm was removed. To collapse isotope+envelopes in a centroided spectrum to monoisotopic peaks, use the static+`Deisotoper.deisotopeAndSingleCharge`:```python-# Create isotope wavelet transform-isotope_wavelet = ms.IsotopeWaveletTransform()--# Configure parameters-params = isotope_wavelet.getParameters()-params.setValue("max_charge", 3)-params.setValue("intensity_threshold", 10.0)-isotope_wavelet.setParameters(params)--# Apply transformation-isotope_wavelet.transform(exp)+spec = exp.getSpectrum(0)+spec.sortByPosition()+# Positional args: spectrum, fragment_tolerance, fragment_unit_ppm, min_charge,+# max_charge, keep_only_deisotoped, min_isopeaks, max_isopeaks,+# make_single_charged, annotate_charge, annotate_iso_peak_count,+# use_decreasing_model, start_intensity_check, add_up_intensity, annotate_features+ms.Deisotoper.deisotopeAndSingleCharge(+ spec, 10.0, True, 1, 3, True, 2, 10, True, True, False, True, 3, False, False+)```## Retention Time Alignmentdiff --git a/skills/pyopenms/scripts/accurate_mass_search.py b/skills/pyopenms/scripts/accurate_mass_search.pynew file mode 100644index 00000000..e621de57--- /dev/null+++ b/skills/pyopenms/scripts/accurate_mass_search.py@@ -0,0 +1,111 @@+#!/usr/bin/env python3+"""+Accurate Mass Search (Metabolite Annotation)++Annotate detected features with putative metabolite identities by matching+accurate masses against the bundled HMDB databases using AccurateMassSearchEngine.+Outputs an annotated mzTab and a flat CSV of hits. By default uses the HMDB+mapping/structure files shipped with pyOpenMS.++Usage:+ python accurate_mass_search.py features.featureXML --out-mztab hits.mzTab+ python accurate_mass_search.py features.featureXML --negative --ppm 5 --csv hits.csv+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)+++def main():+ parser = argparse.ArgumentParser(description="Accurate-mass metabolite annotation.")+ parser.add_argument("input", help="Input featureXML (or consensusXML)")+ parser.add_argument("--out-mztab", help="Output mzTab file")+ parser.add_argument("--csv", help="Output CSV of annotation hits")+ parser.add_argument("--negative", action="store_true", help="Negative ionization mode")+ parser.add_argument("--ppm", type=float, default=5.0, help="Mass error tolerance in ppm (default 5)")+ parser.add_argument("--db-mapping", help="Custom HMDB mapping TSV (default: bundled)")+ parser.add_argument("--db-struct", help="Custom HMDB structure TSV (default: bundled)")+ args = parser.parse_args()++ if not os.path.exists(args.input):+ print(f"Error: file not found: {args.input}")+ sys.exit(1)++ is_consensus = args.input.lower().endswith(".consensusxml")+ if is_consensus:+ fmap = ms.ConsensusMap()+ ms.ConsensusXMLFile().load(args.input, fmap)+ else:+ fmap = ms.FeatureMap()+ ms.FeatureXMLFile().load(args.input, fmap)+ print(f"Loaded {fmap.size()} features")++ # The pip wheel ships HMDBMappingFile.tsv but NOT HMDB2StructMapping.tsv.+ # Verify the structure DB is resolvable before init() to give a clear error.+ struct_path = args.db_struct or "CHEMISTRY/HMDB2StructMapping.tsv"+ resolved = struct_path if os.path.isabs(struct_path) else \+ os.path.join(ms.File.getOpenMSDataPath(), struct_path)+ if not os.path.exists(resolved):+ print(f"Error: structure database not found: {struct_path}")+ print("The pyOpenMS pip wheel does not bundle HMDB2StructMapping.tsv.")+ print("Download it from the OpenMS repository and pass --db-struct:")+ print(" https://github.com/OpenMS/OpenMS/blob/develop/share/OpenMS/CHEMISTRY/HMDB2StructMapping.tsv")+ print(f" (place alongside the mapping file in {ms.File.getOpenMSDataPath()}/CHEMISTRY/")+ print(" or pass --db-struct /path/to/HMDB2StructMapping.tsv --db-mapping /path/to/HMDBMappingFile.tsv)")+ sys.exit(2)++ engine = ms.AccurateMassSearchEngine()+ p = engine.getDefaults()+ p.setValue("mass_error_value", args.ppm)+ p.setValue("mass_error_unit", "ppm")+ p.setValue("ionization_mode", "negative" if args.negative else "positive")+ if args.db_mapping:+ p.setValue("db:mapping", [args.db_mapping.encode()])+ if args.db_struct:+ p.setValue("db:struct", [args.db_struct.encode()])+ engine.setParameters(p)+ engine.init()++ mztab = ms.MzTab()+ if is_consensus:+ engine.run(fmap, mztab)+ else:+ engine.run(fmap, mztab)++ out_mztab = args.out_mztab or os.path.splitext(args.input)[0] + ".mzTab"+ ms.MzTabFile().store(out_mztab, mztab)+ print(f"Wrote {out_mztab}")++ if args.csv:+ # mzTab small-molecule section -> CSV via pandas+ import pandas as pd+ try:+ sm = mztab.getSmallMoleculeSectionRows()+ print(f"Small-molecule annotation rows: {len(sm)}")+ except Exception:+ pass+ # Re-read the mzTab text for a robust flat dump of the SML table+ rows = []+ with open(out_mztab) as fh:+ header = None+ for line in fh:+ if line.startswith("SMH"):+ header = line.rstrip("\n").split("\t")+ elif line.startswith("SML") and header:+ rows.append(dict(zip(header, line.rstrip("\n").split("\t"))))+ if rows:+ pd.DataFrame(rows).to_csv(args.csv, index=False)+ print(f"Wrote {args.csv} ({len(rows)} annotation rows)")+ else:+ print("No small-molecule annotations to write.")+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/align_link_quantify.py b/skills/pyopenms/scripts/align_link_quantify.pynew file mode 100644index 00000000..f5cad6c6--- /dev/null+++ b/skills/pyopenms/scripts/align_link_quantify.py@@ -0,0 +1,140 @@+#!/usr/bin/env python3+"""+Multi-Sample Align, Link, and Quantify++End-to-end untargeted quantification across multiple LC-MS samples:++ 1. Detect features in each mzML (FeatureFindingMetabo) [or load .featureXML]+ 2. Align retention times (MapAlignmentAlgorithmPoseClustering)+ 3. Link features into a consensus map (FeatureGroupingAlgorithmQT)+ 4. Export consensusXML + a wide quantification matrix (CSV)++Accepts either mzML files (features detected here) or pre-computed .featureXML files.++Usage:+ python align_link_quantify.py s1.mzML s2.mzML s3.mzML --out-prefix study+ python align_link_quantify.py *.featureXML --out-prefix study --rt-tol 20 --mz-tol 10+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)++# Reuse the metabolomics detector if available alongside this script+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))+try:+ from detect_features_metabo import detect_features+except Exception:+ detect_features = None+++def load_or_detect(path, ppm, noise):+ if path.lower().endswith(".featurexml"):+ fm = ms.FeatureMap()+ ms.FeatureXMLFile().load(path, fm)+ return fm+ exp = ms.MSExperiment()+ ms.FileHandler().loadExperiment(path, exp)+ if detect_features is None:+ raise RuntimeError("detect_features_metabo.py not importable; pass .featureXML inputs instead.")+ fm, _ = detect_features(exp, ppm=ppm, noise=noise)+ return fm+++def align(feature_maps):+ """Align all maps to the one with the most features (in place)."""+ ref_idx = max(range(len(feature_maps)), key=lambda i: feature_maps[i].size())+ aligner = ms.MapAlignmentAlgorithmPoseClustering()+ aligner.setReference(feature_maps[ref_idx])+ transformer = ms.MapAlignmentTransformer()+ for i, fm in enumerate(feature_maps):+ if i == ref_idx:+ continue+ trafo = ms.TransformationDescription()+ try:+ aligner.align(fm, trafo)+ transformer.transformRetentionTimes(fm, trafo, True)+ except Exception as e:+ print(f" warning: alignment failed for map {i}: {e}")+ return ref_idx+++def link(feature_maps, filenames, rt_tol, mz_tol, mz_unit):+ grouper = ms.FeatureGroupingAlgorithmQT()+ p = grouper.getParameters()+ p.setValue("distance_RT:max_difference", float(rt_tol))+ p.setValue("distance_MZ:max_difference", float(mz_tol))+ p.setValue("distance_MZ:unit", mz_unit)+ grouper.setParameters(p)++ consensus = ms.ConsensusMap()+ headers = consensus.getColumnHeaders()+ for i, fm in enumerate(feature_maps):+ h = ms.ColumnHeader()+ h.filename = filenames[i]+ h.size = fm.size()+ h.unique_id = fm.getUniqueId()+ headers[i] = h+ consensus.setColumnHeaders(headers)+ grouper.group(feature_maps, consensus)+ consensus.setUniqueIds()+ return consensus+++def main():+ parser = argparse.ArgumentParser(description="Align, link, and quantify across samples.")+ parser.add_argument("inputs", nargs="+", help="mzML and/or featureXML files (2+)")+ parser.add_argument("--out-prefix", default="consensus", help="Output file prefix")+ parser.add_argument("--rt-tol", type=float, default=20.0, help="Max RT difference for linking (s)")+ parser.add_argument("--mz-tol", type=float, default=10.0, help="Max m/z difference for linking")+ parser.add_argument("--mz-unit", choices=["ppm", "Da"], default="ppm", help="m/z unit (default ppm)")+ parser.add_argument("--ppm", type=float, default=10.0, help="ppm for feature detection (mzML inputs)")+ parser.add_argument("--noise", type=float, default=1000.0, help="Noise threshold for detection")+ args = parser.parse_args()++ if len(args.inputs) < 2:+ print("Error: provide at least 2 input files.")+ sys.exit(1)++ feature_maps = []+ for path in args.inputs:+ if not os.path.exists(path):+ print(f"Error: file not found: {path}")+ sys.exit(1)+ print(f"Processing {path}...")+ fm = load_or_detect(path, args.ppm, args.noise)+ fm.setUniqueIds()+ print(f" {fm.size()} features")+ feature_maps.append(fm)++ print("Aligning retention times...")+ ref_idx = align(feature_maps)+ print(f" reference map: {args.inputs[ref_idx]}")++ print("Linking features...")+ consensus = link(feature_maps, args.inputs, args.rt_tol, args.mz_tol, args.mz_unit)+ print(f" {consensus.size()} consensus features")++ out_cxml = f"{args.out_prefix}.consensusXML"+ ms.ConsensusXMLFile().store(out_cxml, consensus)+ print(f"Wrote {out_cxml}")++ # Quantification matrix: rows = consensus features, columns = samples.+ # Concatenate positionally (index may be non-unique on degenerate maps).+ import pandas as pd+ intensity_df = consensus.get_intensity_df().reset_index(drop=True)+ meta_df = consensus.get_metadata_df().reset_index(drop=True)+ matrix = pd.concat([meta_df, intensity_df], axis=1)+ out_csv = f"{args.out_prefix}_quant_matrix.csv"+ matrix.to_csv(out_csv, index_label="consensus_id")+ print(f"Wrote {out_csv} ({matrix.shape[0]} features x {intensity_df.shape[1]} samples)")+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/consensus_to_matrix.py b/skills/pyopenms/scripts/consensus_to_matrix.pynew file mode 100644index 00000000..beba7fc2--- /dev/null+++ b/skills/pyopenms/scripts/consensus_to_matrix.py@@ -0,0 +1,70 @@+#!/usr/bin/env python3+"""+Consensus Map to Quantification Matrix++Convert a consensusXML into analysis-ready tables: a wide intensity matrix+(consensus features x samples) joined with feature metadata (RT, m/z, charge,+quality), plus an optional long/tidy format. Optionally normalize intensities+across samples (median or quantile).++Usage:+ python consensus_to_matrix.py study.consensusXML --out quant.csv+ python consensus_to_matrix.py study.consensusXML --out quant.csv --normalize median+ python consensus_to_matrix.py study.consensusXML --out quant.csv --long long.csv+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)+++def main():+ parser = argparse.ArgumentParser(description="Export a consensusXML to a quant matrix CSV.")+ parser.add_argument("input", help="Input consensusXML")+ parser.add_argument("--out", required=True, help="Output wide-matrix CSV")+ parser.add_argument("--long", help="Also write a tidy/long-format CSV")+ parser.add_argument("--normalize", choices=["median", "quantile", "none"], default="none",+ help="Cross-sample intensity normalization (default none)")+ args = parser.parse_args()++ if not os.path.exists(args.input):+ print(f"Error: file not found: {args.input}")+ sys.exit(1)++ cm = ms.ConsensusMap()+ ms.ConsensusXMLFile().load(args.input, cm)+ print(f"Loaded {cm.size()} consensus features, {len(cm.getColumnHeaders())} samples")++ if args.normalize == "median":+ ms.ConsensusMapNormalizerAlgorithmMedian().normalizeMaps(+ cm, ms.NormalizationMethod.NM_SCALE, "", "")+ print("Applied median normalization")+ elif args.normalize == "quantile":+ ms.ConsensusMapNormalizerAlgorithmQuantile().normalizeMaps(cm)+ print("Applied quantile normalization")++ import pandas as pd+ # Ensure unique row identity; consensus ids may be 0/duplicated on some maps.+ cm.setUniqueIds()+ intensity_df = cm.get_intensity_df().reset_index(drop=True)+ meta_df = cm.get_metadata_df().reset_index(drop=True)+ matrix = pd.concat([meta_df, intensity_df], axis=1)+ matrix.to_csv(args.out, index_label="consensus_id")+ print(f"Wrote {args.out} ({matrix.shape[0]} features x {intensity_df.shape[1]} samples)")++ if args.long:+ long_df = intensity_df.copy()+ long_df.insert(0, "consensus_id", range(len(long_df)))+ long_df = long_df.melt(id_vars="consensus_id", var_name="sample", value_name="intensity")+ long_df.to_csv(args.long, index=False)+ print(f"Wrote {args.long} ({len(long_df)} rows)")+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/convert_format.py b/skills/pyopenms/scripts/convert_format.pynew file mode 100644index 00000000..904466b9--- /dev/null+++ b/skills/pyopenms/scripts/convert_format.py@@ -0,0 +1,95 @@+#!/usr/bin/env python3+"""+Convert Between MS File Formats++Convert spectral data between mzML, mzXML, and MGF, with optional MS-level and+RT/intensity filtering. Uses FileHandler for transparent format detection on load.++Supported conversions (by output extension): .mzML, .mzXML, .mgf++Usage:+ python convert_format.py input.mzXML output.mzML+ python convert_format.py input.mzML peaks.mgf --ms-level 2+ python convert_format.py input.mzML out.mzML --rt-min 60 --rt-max 600 --min-intensity 500+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)+++def load_experiment(path):+ exp = ms.MSExperiment()+ ms.FileHandler().loadExperiment(path, exp)+ return exp+++def filter_experiment(exp, ms_level=None, rt_min=None, rt_max=None, min_intensity=None):+ out = ms.MSExperiment()+ for spec in exp:+ if ms_level is not None and spec.getMSLevel() != ms_level:+ continue+ rt = spec.getRT()+ if rt_min is not None and rt < rt_min:+ continue+ if rt_max is not None and rt > rt_max:+ continue+ if min_intensity is not None:+ mz, inten = spec.get_peaks()+ keep = inten >= min_intensity+ spec.set_peaks((mz[keep], inten[keep]))+ out.addSpectrum(spec)+ # carry chromatograms if no MS-level filter requested+ if ms_level is None:+ for chrom in exp.getChromatograms():+ out.addChromatogram(chrom)+ return out+++def store_experiment(exp, path):+ ext = path.lower()+ if ext.endswith(".mzml"):+ ms.MzMLFile().store(path, exp)+ elif ext.endswith(".mzxml"):+ ms.MzXMLFile().store(path, exp)+ elif ext.endswith(".mgf"):+ ms.MascotGenericFile().store(path, exp)+ else:+ raise ValueError(f"Unsupported output extension: {path} (use .mzML, .mzXML, or .mgf)")+++def main():+ parser = argparse.ArgumentParser(description="Convert/filter MS files between formats.")+ parser.add_argument("input", help="Input file (mzML/mzXML/...)")+ parser.add_argument("output", help="Output file (.mzML, .mzXML, or .mgf)")+ parser.add_argument("--ms-level", type=int, help="Keep only spectra at this MS level")+ parser.add_argument("--rt-min", type=float, help="Minimum retention time (s)")+ parser.add_argument("--rt-max", type=float, help="Maximum retention time (s)")+ parser.add_argument("--min-intensity", type=float, help="Drop peaks below this intensity")+ args = parser.parse_args()++ if not os.path.exists(args.input):+ print(f"Error: file not found: {args.input}")+ sys.exit(1)++ print(f"Loading {args.input}...")+ exp = load_experiment(args.input)+ print(f" {exp.getNrSpectra()} spectra, {exp.getNrChromatograms()} chromatograms")++ if any(v is not None for v in (args.ms_level, args.rt_min, args.rt_max, args.min_intensity)):+ exp = filter_experiment(exp, args.ms_level, args.rt_min, args.rt_max, args.min_intensity)+ print(f" after filtering: {exp.getNrSpectra()} spectra")++ print(f"Writing {args.output}...")+ store_experiment(exp, args.output)+ print("Done.")+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/detect_adducts.py b/skills/pyopenms/scripts/detect_adducts.pynew file mode 100644index 00000000..012d8adf--- /dev/null+++ b/skills/pyopenms/scripts/detect_adducts.py@@ -0,0 +1,90 @@+#!/usr/bin/env python3+"""+Adduct Detection / Feature Decharging++Group features that are different ionization forms (adducts/charge variants) of+the same neutral compound using MetaboliteFeatureDeconvolution. Annotates each+feature with its inferred adduct and neutral mass, and writes the decharged+feature map plus a consensus map of grouped adduct families.++Adducts use OpenMS deconvolution syntax 'Elements:Charge:Probability', where+the charge is given as '+'/'-' signs (e.g. 'Ca:++:0.5' is +2) and losses are+written like 'H-2O-1'. Example: 'H:+:0.4'. This differs from the bracket+notation (e.g. [M+H]+) used elsewhere.++Usage:+ python detect_adducts.py features.featureXML --out-features decharged.featureXML+ python detect_adducts.py features.featureXML --negative+ python detect_adducts.py features.featureXML --adducts "H:+:0.6,Na:+:0.2,K:+:0.2"+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)++# 'Elements:Charge:Probability' (OpenMS deconvolution syntax)+DEFAULT_POS = "H:+:0.4,Na:+:0.25,NH4:+:0.25,K:+:0.1,H-2O-1:0:0.05"+DEFAULT_NEG = "H-1:-:0.6,Cl:-:0.2,H-3O-1:-:0.1,CH2O2H-1:-:0.1"+++def main():+ parser = argparse.ArgumentParser(description="Detect adducts / decharge a feature map.")+ parser.add_argument("input", help="Input featureXML")+ parser.add_argument("--out-features", help="Output decharged featureXML (default: <input>_decharged.featureXML)")+ parser.add_argument("--out-consensus", help="Optional consensusXML of adduct groups")+ parser.add_argument("--negative", action="store_true", help="Negative ionization mode")+ parser.add_argument("--adducts", help="Comma-separated potential adducts (overrides defaults)")+ parser.add_argument("--charge-min", type=int, default=1)+ parser.add_argument("--charge-max", type=int, default=1)+ parser.add_argument("--mass-max-diff", type=float, default=0.05, help="Max mass difference (Da)")+ parser.add_argument("--rt-max-diff", type=float, default=10.0, help="Max RT difference (s)")+ args = parser.parse_args()++ if not os.path.exists(args.input):+ print(f"Error: file not found: {args.input}")+ sys.exit(1)++ fm = ms.FeatureMap()+ ms.FeatureXMLFile().load(args.input, fm)+ print(f"Loaded {fm.size()} features")++ adducts = args.adducts+ if adducts is None:+ adducts = DEFAULT_NEG if args.negative else DEFAULT_POS++ mfd = ms.MetaboliteFeatureDeconvolution()+ p = mfd.getDefaults()+ p.setValue("potential_adducts", [a.strip().encode() for a in adducts.split(",")])+ p.setValue("charge_min", args.charge_min)+ p.setValue("charge_max", args.charge_max)+ p.setValue("mass_max_diff", args.mass_max_diff)+ p.setValue("retention_max_diff", args.rt_max_diff)+ p.setValue("negative_mode", "true" if args.negative else "false")+ mfd.setParameters(p)++ fm_out = ms.FeatureMap()+ groups = ms.ConsensusMap()+ edges = ms.ConsensusMap()+ mfd.compute(fm, fm_out, groups, edges)++ annotated = sum(1 for f in fm_out if f.metaValueExists("dc_charge_adducts"))+ print(f"Decharged feature map: {fm_out.size()} features ({annotated} adduct-annotated)")+ print(f"Adduct groups: {groups.size()}")++ out_features = args.out_features or os.path.splitext(args.input)[0] + "_decharged.featureXML"+ ms.FeatureXMLFile().store(out_features, fm_out)+ print(f"Wrote {out_features}")++ if args.out_consensus:+ ms.ConsensusXMLFile().store(args.out_consensus, groups)+ print(f"Wrote {args.out_consensus}")+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/detect_features_centroided.py b/skills/pyopenms/scripts/detect_features_centroided.pynew file mode 100644index 00000000..97b713bc--- /dev/null+++ b/skills/pyopenms/scripts/detect_features_centroided.py@@ -0,0 +1,80 @@+#!/usr/bin/env python3+"""+Peptide/Centroided Feature Detection++Detect features in centroided (peak-picked) LC-MS data using+FeatureFinderAlgorithmPicked -- the modern replacement for the removed+FeatureFinderCentroided. Suited to peptide/proteomics data with defined+isotope patterns and charge states.++Outputs a featureXML and optionally a CSV table.++Usage:+ python detect_features_centroided.py centroided.mzML+ python detect_features_centroided.py data.mzML --out-csv feats.csv --charge-low 2 --charge-high 5+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)+++def detect_features(exp, mz_tol_ppm=10.0, charge_low=1, charge_high=4, min_spectra=7):+ exp.sortSpectra(True)+ exp.updateRanges()+ ff = ms.FeatureFinderAlgorithmPicked()+ params = ff.getDefaults()+ params.setValue("mass_trace:mz_tolerance", mz_tol_ppm / 1e6 * 400.0) # approx Da at m/z 400+ params.setValue("mass_trace:min_spectra", int(min_spectra))+ params.setValue("isotopic_pattern:charge_low", int(charge_low))+ params.setValue("isotopic_pattern:charge_high", int(charge_high))+ ff.setParameters(params)++ features = ms.FeatureMap()+ seeds = ms.FeatureMap()+ ff.run(exp, features, params, seeds)+ features.setUniqueIds()+ return features+++def main():+ parser = argparse.ArgumentParser(description="Centroided/peptide feature detection.")+ parser.add_argument("input", help="Centroided mzML file")+ parser.add_argument("--out-features", help="Output featureXML (default: <input>.featureXML)")+ parser.add_argument("--out-csv", help="Optional CSV table of features")+ parser.add_argument("--mz-tol-ppm", type=float, default=10.0, help="m/z tolerance in ppm (default 10)")+ parser.add_argument("--charge-low", type=int, default=1, help="Lower charge bound (default 1)")+ parser.add_argument("--charge-high", type=int, default=4, help="Upper charge bound (default 4)")+ parser.add_argument("--min-spectra", type=int, default=7, help="Min scans per feature (default 7)")+ args = parser.parse_args()++ 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)+ print(f"Loaded {exp.getNrSpectra()} spectra from {args.input}")++ fm = detect_features(exp, mz_tol_ppm=args.mz_tol_ppm, charge_low=args.charge_low,+ charge_high=args.charge_high, min_spectra=args.min_spectra)+ print(f"Features detected: {fm.size()}")++ out_features = args.out_features or os.path.splitext(args.input)[0] + ".featureXML"+ ms.FeatureXMLFile().store(out_features, fm)+ print(f"Wrote {out_features}")++ if args.out_csv:+ df = fm.get_df()+ df.to_csv(args.out_csv, index=False)+ print(f"Wrote {args.out_csv} ({len(df)} rows)")+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/detect_features_metabo.py b/skills/pyopenms/scripts/detect_features_metabo.pynew file mode 100644index 00000000..cc819ab8--- /dev/null+++ b/skills/pyopenms/scripts/detect_features_metabo.py@@ -0,0 +1,110 @@+#!/usr/bin/env python3+"""+Untargeted Metabolomics Feature Detection++Run the standard OpenMS small-molecule feature-finding pipeline on centroided+LC-MS data:++ MassTraceDetection -> ElutionPeakDetection -> FeatureFindingMetabo++Outputs a featureXML and (optionally) a CSV table of detected features.+This is the recommended entry point for untargeted metabolomics preprocessing.++Usage:+ python detect_features_metabo.py sample.mzML+ python detect_features_metabo.py sample.mzML --out-features feats.featureXML --out-csv feats.csv+ python detect_features_metabo.py sample.mzML --ppm 5 --noise 5000 --charge-low 1 --charge-high 3+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)+++def detect_features(exp, ppm=10.0, noise=1000.0, charge_low=1, charge_high=3,+ remove_single=True, iso_model="metabolites (5% RMS)"):+ """Run MTD -> EPD -> FFM. Returns a FeatureMap."""+ exp.sortSpectra(True)++ # 1. Mass trace detection+ mtd = ms.MassTraceDetection()+ p = mtd.getDefaults()+ p.setValue("mass_error_ppm", float(ppm))+ p.setValue("noise_threshold_int", float(noise))+ mtd.setParameters(p)+ mass_traces = []+ mtd.run(exp, mass_traces, 0)++ # 2. Elution peak detection+ epd = ms.ElutionPeakDetection()+ p = epd.getDefaults()+ p.setValue("width_filtering", "fixed")+ epd.setParameters(p)+ mt_split = []+ epd.detectPeaks(mass_traces, mt_split)++ # 3. Feature assembly (isotope/charge resolution)+ ffm = ms.FeatureFindingMetabo()+ p = ffm.getDefaults()+ p.setValue("isotope_filtering_model", iso_model)+ p.setValue("remove_single_traces", "true" if remove_single else "false")+ p.setValue("charge_lower_bound", int(charge_low))+ p.setValue("charge_upper_bound", int(charge_high))+ p.setValue("report_convex_hulls", "true")+ ffm.setParameters(p)+ fm = ms.FeatureMap()+ chrom_out = []+ ffm.run(mt_split, fm, chrom_out)+ fm.setUniqueIds()+ return fm, len(mass_traces)+++def main():+ parser = argparse.ArgumentParser(description="Untargeted metabolomics feature detection.")+ parser.add_argument("input", help="Centroided mzML file")+ parser.add_argument("--out-features", help="Output featureXML (default: <input>.featureXML)")+ parser.add_argument("--out-csv", help="Optional CSV table of features")+ parser.add_argument("--ppm", type=float, default=10.0, help="Mass trace m/z tolerance in ppm (default 10)")+ parser.add_argument("--noise", type=float, default=1000.0, help="Noise intensity threshold (default 1000)")+ parser.add_argument("--charge-low", type=int, default=1, help="Lower charge bound (default 1)")+ parser.add_argument("--charge-high", type=int, default=3, help="Upper charge bound (default 3)")+ parser.add_argument("--keep-singletons", action="store_true",+ help="Keep single-trace features (default: remove)")+ parser.add_argument("--iso-model", default="metabolites (5% RMS)",+ help="Isotope filtering model (e.g. 'none', 'metabolites (5%% RMS)')")+ args = parser.parse_args()++ 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)+ print(f"Loaded {exp.getNrSpectra()} spectra from {args.input}")++ fm, n_traces = detect_features(+ exp, ppm=args.ppm, noise=args.noise,+ charge_low=args.charge_low, charge_high=args.charge_high,+ remove_single=not args.keep_singletons, iso_model=args.iso_model,+ )+ print(f"Mass traces: {n_traces}")+ print(f"Features detected: {fm.size()}")++ out_features = args.out_features or os.path.splitext(args.input)[0] + ".featureXML"+ ms.FeatureXMLFile().store(out_features, fm)+ print(f"Wrote {out_features}")++ if args.out_csv:+ df = fm.get_df()+ df.to_csv(args.out_csv, index=False)+ print(f"Wrote {args.out_csv} ({len(df)} rows)")+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/digest_protein.py b/skills/pyopenms/scripts/digest_protein.pynew file mode 100644index 00000000..91cc0482--- /dev/null+++ b/skills/pyopenms/scripts/digest_protein.py@@ -0,0 +1,102 @@+#!/usr/bin/env python3+"""+In-Silico Protein Digestion++Digest protein sequences (FASTA or a single sequence) with a configurable+protease, producing theoretical peptides with masses and m/z. Useful for+targeted method design and search-space estimation.++Usage:+ python digest_protein.py proteins.fasta --out peptides.csv+ python digest_protein.py --sequence MKWVTFISLLLLFSSAYS --enzyme Trypsin --missed 2+ python digest_protein.py proteins.fasta --min-length 7 --max-length 40 --charges 1 2 3+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)++PROTON = 1.0072764665789+++def read_fasta(path):+ entries = []+ fe = ms.FASTAFile()+ seqs = []+ fe.load(path, seqs)+ for s in seqs:+ entries.append((s.identifier, s.sequence))+ return entries+++def digest(seq_str, enzyme, missed, min_len, max_len):+ dig = ms.ProteaseDigestion()+ dig.setEnzyme(enzyme)+ dig.setMissedCleavages(missed)+ out = []+ dig.digest(ms.AASequence.fromString(seq_str), out, min_len, max_len)+ return out+++def main():+ parser = argparse.ArgumentParser(description="In-silico protein digestion.")+ parser.add_argument("fasta", nargs="?", help="FASTA file (optional if --sequence given)")+ parser.add_argument("--sequence", help="Single protein sequence")+ parser.add_argument("--enzyme", default="Trypsin", help="Protease (default Trypsin)")+ parser.add_argument("--missed", type=int, default=2, help="Max missed cleavages (default 2)")+ parser.add_argument("--min-length", type=int, default=6, help="Min peptide length (default 6)")+ parser.add_argument("--max-length", type=int, default=40, help="Max peptide length (default 40)")+ parser.add_argument("--charges", type=int, nargs="+", default=[1, 2], help="m/z charge states")+ parser.add_argument("--out", help="Output CSV of peptides")+ args = parser.parse_args()++ proteins = []+ if args.fasta:+ if not os.path.exists(args.fasta):+ print(f"Error: file not found: {args.fasta}")+ sys.exit(1)+ proteins = read_fasta(args.fasta)+ elif args.sequence:+ proteins = [("input", args.sequence)]+ else:+ parser.error("provide a FASTA file or --sequence")++ rows = []+ seen = set()+ for prot_id, seq in proteins:+ for pep in digest(seq, args.enzyme, args.missed, args.min_length, args.max_length):+ pep_str = pep.toString()+ key = (prot_id, pep_str)+ if key in seen:+ continue+ seen.add(key)+ mono = pep.getMonoWeight()+ row = {"protein": prot_id, "peptide": pep_str, "length": pep.size(),+ "mono_mass": round(mono, 5)}+ for z in args.charges:+ row[f"mz_z{z}"] = round((mono + z * PROTON) / z, 5)+ rows.append(row)++ print(f"Proteins: {len(proteins)} Unique peptides: {len(rows)}")+ for r in rows[:10]:+ print(f" {r['peptide']} ({r['length']} aa, {r['mono_mass']} Da)")+ if len(rows) > 10:+ print(f" ... and {len(rows) - 10} more")++ if args.out:+ import csv+ with open(args.out, "w", newline="") as fh:+ w = csv.DictWriter(fh, fieldnames=list(rows[0].keys()) if rows else ["protein", "peptide"])+ w.writeheader()+ w.writerows(rows)+ print(f"Wrote {args.out}")+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/export_gnps_sirius.py b/skills/pyopenms/scripts/export_gnps_sirius.pynew file mode 100644index 00000000..a279fba1--- /dev/null+++ b/skills/pyopenms/scripts/export_gnps_sirius.py@@ -0,0 +1,90 @@+#!/usr/bin/env python3+"""+Export for GNPS (FBMN) and SIRIUS++Generate the input files required by downstream annotation tools:++ gnps Feature-Based Molecular Networking: writes an MGF of MS2 spectra+ (from a consensusXML linked across samples) plus the GNPS+ quantification table.+ sirius Writes a SIRIUS .ms file (and compound-info TSV) from mzML ++ featureXML input for formula/structure elucidation.++Usage:+ python export_gnps_sirius.py gnps study.consensusXML --mzml s1.mzML s2.mzML --out-prefix gnps_out+ python export_gnps_sirius.py sirius sample.mzML --featurexml sample.featureXML --out sample.ms+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)+++def export_gnps(args):+ cm = ms.ConsensusMap()+ ms.ConsensusXMLFile().load(args.consensus, cm)+ print(f"Loaded {cm.size()} consensus features")++ mgf_out = f"{args.out_prefix}.mgf"+ quant_out = f"{args.out_prefix}_quant.txt"++ mzml_paths = [p.encode() for p in args.mzml]+ ms.GNPSMGFFile().store(args.consensus.encode(), mzml_paths, mgf_out)+ print(f"Wrote {mgf_out}")++ ms.GNPSQuantificationFile().store(cm, quant_out)+ print(f"Wrote {quant_out}")+ print("Upload both to GNPS Feature-Based Molecular Networking.")+++def export_sirius(args):+ out_ms = args.out or os.path.splitext(args.input)[0] + ".ms"+ out_info = args.compound_info or os.path.splitext(out_ms)[0] + "_compounds.tsv"++ exporter = ms.SiriusExportAlgorithm()+ feature_files = [args.featurexml.encode()] if args.featurexml else []+ try:+ exporter.run([args.input.encode()], feature_files, out_ms, out_info)+ except RuntimeError as e:+ if "SourceFile" in str(e):+ print("Error: the mzML lacks proper SourceFile annotation required by SIRIUS export.")+ print("This is normal for synthetic/hand-built mzML. Re-export the file through")+ print("OpenMS FileConverter (or any real instrument export) so it carries source")+ print("metadata, then retry. Vendor-converted mzML files already satisfy this.")+ sys.exit(2)+ raise+ print(f"Wrote {out_ms}")+ print(f"Wrote {out_info}")+ print("Run SIRIUS on the .ms file for formula/structure elucidation.")+++def main():+ parser = argparse.ArgumentParser(description="Export for GNPS FBMN or SIRIUS.")+ sub = parser.add_subparsers(dest="mode", required=True)++ g = sub.add_parser("gnps", help="Export GNPS FBMN inputs")+ g.add_argument("consensus", help="consensusXML linked across samples")+ g.add_argument("--mzml", nargs="+", required=True, help="Source mzML files (with MS2)")+ g.add_argument("--out-prefix", default="gnps_export", help="Output prefix")++ s = sub.add_parser("sirius", help="Export SIRIUS .ms file")+ s.add_argument("input", help="mzML file (with MS2)")+ s.add_argument("--featurexml", help="Optional featureXML to group spectra")+ s.add_argument("--out", help="Output .ms path")+ s.add_argument("--compound-info", help="Output compound-info TSV path")++ args = parser.parse_args()+ if args.mode == "gnps":+ export_gnps(args)+ else:+ export_sirius(args)+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/extract_chromatograms.py b/skills/pyopenms/scripts/extract_chromatograms.pynew file mode 100644index 00000000..dc6593c4--- /dev/null+++ b/skills/pyopenms/scripts/extract_chromatograms.py@@ -0,0 +1,105 @@+#!/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)+ 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()diff --git a/skills/pyopenms/scripts/inspect_ms_data.py b/skills/pyopenms/scripts/inspect_ms_data.pynew file mode 100644index 00000000..7331d5d8--- /dev/null+++ b/skills/pyopenms/scripts/inspect_ms_data.py@@ -0,0 +1,167 @@+#!/usr/bin/env python3+"""+Inspect Mass Spectrometry Data++Load any supported MS file (mzML, mzXML, featureXML, consensusXML, idXML) and+print a structured summary: spectrum counts by MS level, RT/m/z ranges, TIC,+chromatograms, precursor info, and instrument metadata. Optionally dump a+per-spectrum table to CSV.++Usage:+ python inspect_ms_data.py data.mzML+ python inspect_ms_data.py data.mzML --spectra-csv spectra.csv+ python inspect_ms_data.py features.featureXML+ python inspect_ms_data.py ids.idXML+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)+++def summarize_experiment(path):+ exp = ms.MSExperiment()+ ms.FileHandler().loadExperiment(path, exp)++ n_spec = exp.getNrSpectra()+ n_chrom = exp.getNrChromatograms()+ print(f"File: {path}")+ print(f"Spectra: {n_spec}")+ print(f"Chromatograms: {n_chrom}")++ if n_spec:+ levels = {}+ rts, total_tic, total_peaks = [], 0.0, 0+ mz_min, mz_max = float("inf"), float("-inf")+ n_precursors = 0+ for spec in exp:+ lvl = spec.getMSLevel()+ levels[lvl] = levels.get(lvl, 0) + 1+ rts.append(spec.getRT())+ mz, inten = spec.get_peaks()+ total_peaks += len(mz)+ if len(mz):+ total_tic += float(inten.sum())+ mz_min = min(mz_min, float(mz.min()))+ mz_max = max(mz_max, float(mz.max()))+ if spec.getPrecursors():+ n_precursors += 1+ print("\nSpectra by MS level:")+ for lvl in sorted(levels):+ print(f" MS{lvl}: {levels[lvl]}")+ if rts:+ print(f"\nRT range: {min(rts):.1f} - {max(rts):.1f} s "+ f"({min(rts)/60:.2f} - {max(rts)/60:.2f} min)")+ if mz_min != float("inf"):+ print(f"m/z range: {mz_min:.4f} - {mz_max:.4f}")+ print(f"Total peaks: {total_peaks}")+ print(f"Total ion current (sum): {total_tic:.3e}")+ print(f"Spectra with precursors (MSn): {n_precursors}")++ # Instrument / metadata+ instr = exp.getInstrument()+ if instr.getName():+ print(f"\nInstrument: {instr.getName()}")+ if instr.getVendor():+ print(f"Vendor: {instr.getVendor()}")+ return exp+++def dump_spectra_csv(exp, out_csv):+ import csv+ with open(out_csv, "w", newline="") as fh:+ w = csv.writer(fh)+ w.writerow(["index", "ms_level", "rt", "n_peaks", "tic",+ "base_peak_mz", "base_peak_int", "precursor_mz", "precursor_charge"])+ for i, spec in enumerate(exp):+ mz, inten = spec.get_peaks()+ tic = float(inten.sum()) if len(inten) else 0.0+ bp_mz, bp_int = ("", "")+ if len(inten):+ j = int(inten.argmax())+ bp_mz, bp_int = f"{mz[j]:.4f}", f"{inten[j]:.1f}"+ prec_mz, prec_z = ("", "")+ if spec.getPrecursors():+ p = spec.getPrecursors()[0]+ prec_mz, prec_z = f"{p.getMZ():.4f}", p.getCharge()+ w.writerow([i, spec.getMSLevel(), f"{spec.getRT():.3f}", len(mz),+ f"{tic:.1f}", bp_mz, bp_int, prec_mz, prec_z])+ print(f"\nWrote per-spectrum table: {out_csv}")+++def summarize_feature_map(path):+ fm = ms.FeatureMap()+ ms.FeatureXMLFile().load(path, fm)+ print(f"File: {path}")+ print(f"Features: {fm.size()}")+ if fm.size():+ df = fm.get_df()+ print(f"\nColumns: {list(df.columns)}")+ print(f"RT range: {df['rt'].min():.1f} - {df['rt'].max():.1f} s")+ print(f"m/z range: {df['mz'].min():.4f} - {df['mz'].max():.4f}")+ print(f"Intensity: median={df['intensity'].median():.3e} max={df['intensity'].max():.3e}")+ if "charge" in df:+ print(f"Charge states: {sorted(df['charge'].unique().tolist())}")+++def summarize_consensus_map(path):+ cm = ms.ConsensusMap()+ ms.ConsensusXMLFile().load(path, cm)+ print(f"File: {path}")+ print(f"Consensus features: {cm.size()}")+ headers = cm.getColumnHeaders()+ print(f"Samples/maps: {len(headers)}")+ for idx, h in headers.items():+ print(f" map {idx}: {h.filename} (size={h.size}, label={h.label})")+++def summarize_idxml(path):+ prot_ids = []+ pep_ids = ms.PeptideIdentificationList() # required type in pyOpenMS 3.5++ ms.IdXMLFile().load(path, prot_ids, pep_ids)+ print(f"File: {path}")+ print(f"Protein ID runs: {len(prot_ids)}")+ total_prot = sum(len(p.getHits()) for p in prot_ids)+ print(f"Protein hits: {total_prot}")+ print(f"Peptide identifications (spectra): {len(pep_ids)}")+ total_pep = sum(len(p.getHits()) for p in pep_ids)+ print(f"Peptide hits: {total_pep}")+ if pep_ids:+ scored = [p for p in pep_ids if p.getHits()]+ if scored:+ st = scored[0].getScoreType()+ print(f"Score type: {st}")+ print(f"Higher score better: {scored[0].isHigherScoreBetter()}")+++def main():+ parser = argparse.ArgumentParser(description="Inspect a mass spectrometry data file.")+ parser.add_argument("input", help="Input file (mzML, mzXML, featureXML, consensusXML, idXML)")+ parser.add_argument("--spectra-csv", help="Write a per-spectrum summary table to this CSV path")+ args = parser.parse_args()++ if not os.path.exists(args.input):+ print(f"Error: file not found: {args.input}")+ sys.exit(1)++ ext = args.input.lower()+ if ext.endswith(".featurexml"):+ summarize_feature_map(args.input)+ elif ext.endswith(".consensusxml"):+ summarize_consensus_map(args.input)+ elif ext.endswith(".idxml"):+ summarize_idxml(args.input)+ else:+ exp = summarize_experiment(args.input)+ if args.spectra_csv:+ dump_spectra_csv(exp, args.spectra_csv)+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/mass_calculator.py b/skills/pyopenms/scripts/mass_calculator.pynew file mode 100644index 00000000..0797c80e--- /dev/null+++ b/skills/pyopenms/scripts/mass_calculator.py@@ -0,0 +1,92 @@+#!/usr/bin/env python3+"""+Mass & Chemistry Calculator++Compute masses and isotope distributions for peptides (amino-acid sequences),+empirical formulas, or both. Reports monoisotopic and average mass, m/z for a+range of charge states, the molecular formula, and the theoretical isotope+pattern.++Usage:+ python mass_calculator.py --peptide DFPIANGER+ python mass_calculator.py --peptide "PEPTIDEM(Oxidation)K" --charges 1 2 3+ python mass_calculator.py --formula C6H12O6 --isotopes 5+ python mass_calculator.py --peptide DFPIANGER --isotopes 6 --csv iso.csv+"""++import argparse+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)++PROTON = 1.0072764665789+++def report_isotopes(formula, n, csv=None):+ gen = ms.CoarseIsotopePatternGenerator(n)+ dist = formula.getIsotopeDistribution(gen)+ print(f"\nIsotope pattern (top {n}):")+ rows = []+ for iso in dist.getContainer():+ mz = iso.getMZ()+ prob = iso.getIntensity()+ print(f" m/z {mz:.4f} rel.abundance {prob*100:6.2f}%")+ rows.append((mz, prob))+ if csv:+ import csv as csvmod+ with open(csv, "w", newline="") as fh:+ w = csvmod.writer(fh)+ w.writerow(["mass", "rel_abundance"])+ w.writerows(rows)+ print(f"Wrote {csv}")+++def main():+ parser = argparse.ArgumentParser(description="Compute masses and isotope distributions.")+ parser.add_argument("--peptide", help="Amino-acid sequence (TPP/OpenMS mod syntax allowed)")+ parser.add_argument("--formula", help="Empirical formula, e.g. C6H12O6")+ parser.add_argument("--charges", type=int, nargs="+", default=[1, 2, 3],+ help="Charge states for m/z (default 1 2 3)")+ parser.add_argument("--isotopes", type=int, default=0, help="Number of isotope peaks to report")+ parser.add_argument("--negative", action="store_true", help="Report negative-mode m/z")+ parser.add_argument("--csv", help="Write isotope pattern to CSV")+ args = parser.parse_args()++ if not args.peptide and not args.formula:+ parser.error("provide --peptide and/or --formula")++ sign = -1 if args.negative else 1++ if args.peptide:+ seq = ms.AASequence.fromString(args.peptide)+ formula = seq.getFormula()+ mono = seq.getMonoWeight()+ avg = seq.getAverageWeight()+ print(f"Peptide: {seq.toString()}")+ print(f"Formula: {formula.toString()}")+ print(f"Monoisotopic mass: {mono:.5f}")+ print(f"Average mass: {avg:.5f}")+ for z in args.charges:+ mz = (mono + sign * z * PROTON) / z+ print(f" [M{'+' if not args.negative else '-'}{z}H]{'+' if not args.negative else '-'} m/z = {mz:.5f} (z={z})")+ if args.isotopes:+ report_isotopes(formula, args.isotopes, args.csv if not args.formula else None)++ if args.formula:+ formula = ms.EmpiricalFormula(args.formula)+ print(f"\nFormula: {formula.toString()}")+ print(f"Monoisotopic mass: {formula.getMonoWeight():.5f}")+ print(f"Average mass: {formula.getAverageWeight():.5f}")+ for z in args.charges:+ mz = (formula.getMonoWeight() + sign * z * PROTON) / z+ print(f" m/z = {mz:.5f} (z={z})")+ if args.isotopes:+ report_isotopes(formula, args.isotopes, args.csv)+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/plot_ms_data.py b/skills/pyopenms/scripts/plot_ms_data.pynew file mode 100644index 00000000..f3a7cb8f--- /dev/null+++ b/skills/pyopenms/scripts/plot_ms_data.py@@ -0,0 +1,129 @@+#!/usr/bin/env python3+"""+Visualize MS Data++Quick plots for inspecting MS data and results:+ spectrum single MS spectrum (peak/stick plot) by index or RT+ tic total ion chromatogram+ featuremap 2D feature map (RT vs m/z, sized/colored by intensity)+ map2d 2D heatmap of MS1 signal (RT vs m/z)++Usage:+ python plot_ms_data.py spectrum data.mzML --index 0 --out spec.png+ python plot_ms_data.py tic data.mzML --out tic.png+ python plot_ms_data.py featuremap features.featureXML --out fmap.png+ python plot_ms_data.py map2d data.mzML --out map.png+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+ import numpy as np+ import matplotlib+ matplotlib.use("Agg")+ import matplotlib.pyplot as plt+except ImportError:+ print("Error: pyopenms/matplotlib not installed. Install with: uv pip install pyopenms matplotlib")+ sys.exit(1)+++def load_exp(path):+ exp = ms.MSExperiment()+ ms.FileHandler().loadExperiment(path, exp)+ return exp+++def plot_spectrum(args):+ exp = load_exp(args.input)+ if args.rt is not None:+ spec = min((s for s in exp), key=lambda s: abs(s.getRT() - args.rt))+ else:+ spec = exp.getSpectrum(args.index)+ mz, inten = spec.get_peaks()+ plt.figure(figsize=(10, 5))+ plt.vlines(mz, 0, inten, linewidth=0.8)+ plt.xlabel("m/z")+ plt.ylabel("Intensity")+ plt.title(f"Spectrum (MS{spec.getMSLevel()}, RT={spec.getRT():.1f}s, {len(mz)} peaks)")+ plt.tight_layout()+++def plot_tic(args):+ exp = load_exp(args.input)+ rts, tic = [], []+ for s in exp:+ if s.getMSLevel() != 1:+ continue+ _, inten = s.get_peaks()+ rts.append(s.getRT())+ tic.append(float(inten.sum()) if len(inten) else 0.0)+ plt.figure(figsize=(10, 5))+ plt.plot(rts, tic, linewidth=1)+ plt.xlabel("Retention time (s)")+ plt.ylabel("Total ion current")+ plt.title("Total Ion Chromatogram")+ plt.tight_layout()+++def plot_featuremap(args):+ fm = ms.FeatureMap()+ ms.FeatureXMLFile().load(args.input, fm)+ df = fm.get_df()+ plt.figure(figsize=(10, 6))+ sizes = 10 + 40 * (df["intensity"] / df["intensity"].max())+ sc = plt.scatter(df["rt"], df["mz"], s=sizes, c=np.log10(df["intensity"] + 1),+ cmap="viridis", alpha=0.7)+ plt.colorbar(sc, label="log10(intensity)")+ plt.xlabel("Retention time (s)")+ plt.ylabel("m/z")+ plt.title(f"Feature map ({fm.size()} features)")+ plt.tight_layout()+++def plot_map2d(args):+ exp = load_exp(args.input)+ rts, mzs, ints = [], [], []+ for s in exp:+ if s.getMSLevel() != 1:+ continue+ mz, inten = s.get_peaks()+ rt = s.getRT()+ for m, it in zip(mz, inten):+ rts.append(rt); mzs.append(m); ints.append(it)+ plt.figure(figsize=(10, 6))+ sc = plt.scatter(rts, mzs, c=np.log10(np.array(ints) + 1), s=2,+ cmap="inferno", alpha=0.5)+ plt.colorbar(sc, label="log10(intensity)")+ plt.xlabel("Retention time (s)")+ plt.ylabel("m/z")+ plt.title("MS1 signal map")+ plt.tight_layout()+++PLOTS = {"spectrum": plot_spectrum, "tic": plot_tic,+ "featuremap": plot_featuremap, "map2d": plot_map2d}+++def main():+ parser = argparse.ArgumentParser(description="Visualize MS data.")+ parser.add_argument("kind", choices=list(PLOTS), help="Plot type")+ parser.add_argument("input", help="Input file")+ parser.add_argument("--index", type=int, default=0, help="Spectrum index (spectrum plot)")+ parser.add_argument("--rt", type=float, help="Select spectrum nearest this RT (spectrum plot)")+ parser.add_argument("--out", required=True, help="Output image path (PNG/PDF/SVG)")+ args = parser.parse_args()++ if not os.path.exists(args.input):+ print(f"Error: file not found: {args.input}")+ sys.exit(1)++ PLOTS[args.kind](args)+ plt.savefig(args.out, dpi=150)+ print(f"Wrote {args.out}")+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/process_identifications.py b/skills/pyopenms/scripts/process_identifications.pynew file mode 100644index 00000000..ece0e56a--- /dev/null+++ b/skills/pyopenms/scripts/process_identifications.py@@ -0,0 +1,111 @@+#!/usr/bin/env python3+"""+Process Peptide/Protein Identifications++Post-process search-engine results (idXML): optionally re-index peptides against+a protein FASTA (assigns target/decoy + protein accessions), estimate FDR/q-values,+filter by FDR threshold, peptide length, and best-hit-per-spectrum, then export a+filtered idXML and a flat CSV of peptide hits.++Usage:+ python process_identifications.py search.idXML --out filtered.idXML --csv hits.csv+ python process_identifications.py search.idXML --fasta db.fasta --fdr 0.01 --out filt.idXML+ python process_identifications.py search.idXML --fdr 0.05 --min-length 7 --best-per-spectrum+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)+++def index_peptides(fasta, prot_ids, pep_ids):+ fasta_entries = []+ ms.FASTAFile().load(fasta, fasta_entries)+ indexer = ms.PeptideIndexing()+ p = indexer.getParameters()+ p.setValue("decoy_string", "DECOY_")+ p.setValue("missing_decoy_action", "warn")+ indexer.setParameters(p)+ indexer.run(fasta_entries, prot_ids, pep_ids)+ print(f"Indexed against {len(fasta_entries)} proteins")+++def main():+ parser = argparse.ArgumentParser(description="Filter and export peptide identifications.")+ parser.add_argument("input", help="Input idXML")+ parser.add_argument("--fasta", help="Protein FASTA (target+decoy) for re-indexing")+ parser.add_argument("--out", help="Output filtered idXML")+ parser.add_argument("--csv", help="Output CSV of peptide hits")+ parser.add_argument("--fdr", type=float, help="FDR/q-value threshold (requires decoys)")+ parser.add_argument("--min-length", type=int, help="Minimum peptide length")+ parser.add_argument("--max-length", type=int, help="Maximum peptide length")+ parser.add_argument("--best-per-spectrum", action="store_true",+ help="Keep only the best hit per spectrum")+ args = parser.parse_args()++ if not os.path.exists(args.input):+ print(f"Error: file not found: {args.input}")+ sys.exit(1)++ # In pyOpenMS 3.5+, idXML load/store require a PeptideIdentificationList+ # (not a plain Python list) for the peptide IDs; protein IDs stay a list.+ prot_ids = []+ pep_ids = ms.PeptideIdentificationList()+ ms.IdXMLFile().load(args.input, prot_ids, pep_ids)+ print(f"Loaded {len(pep_ids)} spectra, "+ f"{sum(len(p.getHits()) for p in pep_ids)} peptide hits")++ if args.fasta:+ index_peptides(args.fasta, prot_ids, pep_ids)++ if args.fdr is not None:+ fdr = ms.FalseDiscoveryRate()+ fdr.apply(pep_ids)+ ms.IDFilter().filterHitsByScore(pep_ids, args.fdr)+ print(f"Applied FDR filter (q <= {args.fdr})")++ if args.best_per_spectrum:+ ms.IDFilter().keepBestPeptideHits(pep_ids, False)+ print("Kept best hit per spectrum")++ if args.min_length is not None or args.max_length is not None:+ lo = args.min_length or 0+ hi = args.max_length or 0 # 0 = no upper bound in OpenMS+ ms.IDFilter().filterPeptidesByLength(pep_ids, lo, hi)+ print(f"Length filter ({lo}-{hi or 'inf'})")++ # Drop now-empty identifications+ ms.IDFilter().removeEmptyIdentifications(pep_ids)+ remaining = sum(len(p.getHits()) for p in pep_ids)+ print(f"Remaining: {len(pep_ids)} spectra, {remaining} peptide hits")++ if args.out:+ ms.IdXMLFile().store(args.out, prot_ids, pep_ids)+ print(f"Wrote {args.out}")++ if args.csv:+ import csv+ with open(args.csv, "w", newline="") as fh:+ w = csv.writer(fh)+ w.writerow(["rt", "mz", "sequence", "charge", "score", "score_type",+ "target_decoy", "accessions"])+ for pid in pep_ids:+ rt = pid.getRT()+ mz = pid.getMZ()+ st = pid.getScoreType()+ for hit in pid.getHits():+ td = hit.getMetaValue("target_decoy") if hit.metaValueExists("target_decoy") else ""+ accs = ";".join(a.decode() for a in hit.extractProteinAccessionsSet())+ w.writerow([f"{rt:.2f}", f"{mz:.4f}", hit.getSequence().toString(),+ hit.getCharge(), hit.getScore(), st, td, accs])+ print(f"Wrote {args.csv}")+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/process_spectra.py b/skills/pyopenms/scripts/process_spectra.pynew file mode 100644index 00000000..4fdd2441--- /dev/null+++ b/skills/pyopenms/scripts/process_spectra.py@@ -0,0 +1,124 @@+#!/usr/bin/env python3+"""+Signal Processing for Spectra++Apply a configurable chain of signal-processing steps to all (or selected MS-level)+spectra in an MS file: smoothing, centroiding (peak picking), normalization, and+intensity/S-N thresholding. Steps run in the order listed below.++Steps (enable with flags):+ --smooth gauss|sgolay Smooth profile data+ --pick Centroid profile data (PeakPickerHiRes)+ --normalize to_one|to_TIC Normalize intensities+ --threshold FLOAT Remove peaks below absolute intensity+ --sn FLOAT Remove peaks below this signal-to-noise ratio++Usage:+ python process_spectra.py raw.mzML centroided.mzML --smooth gauss --pick+ python process_spectra.py data.mzML out.mzML --normalize to_one --threshold 100+ python process_spectra.py data.mzML out.mzML --ms-level 1 --sn 2.0+"""++import argparse+import os+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)+++def main():+ parser = argparse.ArgumentParser(description="Apply signal processing to spectra.")+ parser.add_argument("input", help="Input mzML/mzXML file")+ parser.add_argument("output", help="Output mzML file")+ parser.add_argument("--ms-level", type=int, help="Process only this MS level (others passed through)")+ parser.add_argument("--smooth", choices=["gauss", "sgolay"], help="Smoothing filter")+ parser.add_argument("--gaussian-width", type=float, default=0.2, help="Gaussian width (default 0.2)")+ parser.add_argument("--pick", action="store_true", help="Centroid via PeakPickerHiRes")+ parser.add_argument("--signal-to-noise", type=float, default=0.0,+ help="PeakPicker S/N threshold (0 = off, default)")+ parser.add_argument("--normalize", choices=["to_one", "to_TIC"], help="Normalization method")+ parser.add_argument("--threshold", type=float, help="Remove peaks below this absolute intensity")+ parser.add_argument("--sn", type=float, help="Remove peaks below this S/N (SignalToNoiseEstimatorMedian)")+ args = parser.parse_args()++ 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)+ print(f"Loaded {exp.getNrSpectra()} spectra")++ levels = [args.ms_level] if args.ms_level else []++ # 1. Smoothing+ if args.smooth == "gauss":+ f = ms.GaussFilter()+ p = f.getParameters()+ p.setValue("gaussian_width", args.gaussian_width)+ f.setParameters(p)+ f.filterExperiment(exp)+ print(f"Applied Gaussian smoothing (width={args.gaussian_width})")+ elif args.smooth == "sgolay":+ f = ms.SavitzkyGolayFilter()+ f.filterExperiment(exp)+ print("Applied Savitzky-Golay smoothing")++ # 2. Peak picking / centroiding+ if args.pick:+ picker = ms.PeakPickerHiRes()+ p = picker.getParameters()+ p.setValue("signal_to_noise", args.signal_to_noise)+ if levels:+ p.setValue("ms_levels", levels)+ picker.setParameters(p)+ out = ms.MSExperiment()+ picker.pickExperiment(exp, out, True)+ exp = out+ print("Centroided with PeakPickerHiRes")++ # 3. Normalization+ if args.normalize:+ norm = ms.Normalizer()+ p = norm.getParameters()+ p.setValue("method", args.normalize)+ norm.setParameters(p)+ norm.filterPeakMap(exp)+ print(f"Normalized ({args.normalize})")++ # 4. S/N filtering (per spectrum)+ if args.sn is not None:+ sn_est = ms.SignalToNoiseEstimatorMedian()+ kept_total = 0+ for spec in exp:+ if levels and spec.getMSLevel() not in levels:+ continue+ sn_est.init(spec)+ mz, inten = spec.get_peaks()+ keep = [i for i in range(len(mz)) if sn_est.getSignalToNoise(i) >= args.sn]+ spec.set_peaks(([mz[i] for i in keep], [inten[i] for i in keep]))+ kept_total += len(keep)+ print(f"S/N filter (>= {args.sn}): kept {kept_total} peaks")++ # 5. Absolute intensity threshold+ if args.threshold is not None:+ kept_total = 0+ for spec in exp:+ if levels and spec.getMSLevel() not in levels:+ continue+ mz, inten = spec.get_peaks()+ keep = inten >= args.threshold+ spec.set_peaks((mz[keep], inten[keep]))+ kept_total += int(keep.sum())+ print(f"Intensity threshold (>= {args.threshold}): kept {kept_total} peaks")++ ms.MzMLFile().store(args.output, exp)+ print(f"Wrote {args.output}")+++if __name__ == "__main__":+ main()diff --git a/skills/pyopenms/scripts/theoretical_spectrum.py b/skills/pyopenms/scripts/theoretical_spectrum.pynew file mode 100644index 00000000..df3185b7--- /dev/null+++ b/skills/pyopenms/scripts/theoretical_spectrum.py@@ -0,0 +1,75 @@+#!/usr/bin/env python3+"""+Theoretical Fragment Spectrum Generator++Generate a theoretical fragment-ion spectrum (b/y, optionally a/c/x/z and+losses) for a peptide using TheoreticalSpectrumGenerator. Prints annotated+fragment ions and optionally writes the spectrum to mzML and/or a CSV peak list.++Usage:+ python theoretical_spectrum.py DFPIANGER+ python theoretical_spectrum.py PEPTIDEK --charge 2 --ions b y a --losses+ python theoretical_spectrum.py DFPIANGER --out-mzml theo.mzML --out-csv peaks.csv+"""++import argparse+import sys++try:+ import pyopenms as ms+except ImportError:+ print("Error: pyopenms not installed. Install with: uv pip install pyopenms")+ sys.exit(1)+++def main():+ parser = argparse.ArgumentParser(description="Generate a theoretical peptide spectrum.")+ parser.add_argument("peptide", help="Amino-acid sequence (OpenMS mod syntax allowed)")+ parser.add_argument("--charge", type=int, default=1, help="Max fragment charge (default 1)")+ parser.add_argument("--ions", nargs="+", default=["b", "y"],+ choices=["a", "b", "c", "x", "y", "z"], help="Ion series (default b y)")+ parser.add_argument("--losses", action="store_true", help="Include neutral losses")+ parser.add_argument("--precursor", action="store_true", help="Include precursor peaks")+ parser.add_argument("--out-mzml", help="Write spectrum to mzML")+ parser.add_argument("--out-csv", help="Write annotated peak list to CSV")+ args = parser.parse_args()++ seq = ms.AASequence.fromString(args.peptide)+ tsg = ms.TheoreticalSpectrumGenerator()+ p = tsg.getParameters()+ for ion in ["a", "b", "c", "x", "y", "z"]:+ p.setValue(f"add_{ion}_ions", "true" if ion in args.ions else "false")+ p.setValue("add_losses", "true" if args.losses else "false")+ p.setValue("add_precursor_peaks", "true" if args.precursor else "false")+ p.setValue("add_metainfo", "true")+ tsg.setParameters(p)++ spec = ms.MSSpectrum()+ tsg.getSpectrum(spec, seq, 1, args.charge)+ print(f"Peptide: {seq.toString()} ({len(spec)} fragment peaks)")++ mz, inten = spec.get_peaks()+ names = [spec.getStringDataArrays()[0][i].decode() if spec.getStringDataArrays() else ""+ for i in range(len(mz))]+ rows = sorted(zip(mz, inten, names), key=lambda r: r[0])+ for m, _, name in rows:+ print(f" {name:12s} m/z {m:.4f}")++ if args.out_mzml:+ exp = ms.MSExperiment()+ exp.addSpectrum(spec)+ ms.MzMLFile().store(args.out_mzml, exp)+ print(f"Wrote {args.out_mzml}")++ if args.out_csv:+ import csv+ with open(args.out_csv, "w", newline="") as fh:+ w = csv.writer(fh)+ w.writerow(["ion", "mz", "intensity"])+ for m, it, name in rows:+ w.writerow([name, f"{m:.5f}", f"{it:.3f}"])+ print(f"Wrote {args.out_csv}")+++if __name__ == "__main__":+ main()