agentsclimarketplace

Nearest neighbor clustering for mass spectrometry

Skill HolobiomicsLab/asb-skill-collections/collections/metabolomics/v2/skills/nearest-neighbor-clustering-for-mass-spectrometry

Use when you have extracted mass tracks (EICs) from individual samples at 0.001 amu m/z resolution and need to align them into a composite mass grid for feature detection.From its SKILL.md

Install
npx -y skills add HolobiomicsLab/asb-skill-collections --skill nearest-neighbor-clustering-for-mass-spectrometry

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 15 stars15 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as CC-BY-4.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

9.1 KB, ~1.6k tokens by cl100k_base, as published. Nobody here has run it

nearest-neighbor-clustering-for-mass-spectrometry

License: restricted — no clear open-source license detected for the underlying tool; verify licensing before commercial use or redistribution. <!-- asb-license-banner -->

Summary

Cluster and bin m/z values from mass tracks across multiple LC-MS samples using nearest-neighbor methods to resolve overlapping chromatograms and construct a unified mass grid. This skill leverages high mass resolution to group chemically equivalent ions and align them reproducibly across the cohort.

When to use

Apply this skill when you have extracted mass tracks (EICs) from individual samples at 0.001 amu m/z resolution and need to align them into a composite mass grid for feature detection. Specifically, use it when: (1) you have overlapping m/z values from different samples that represent the same chemical species, (2) you need to resolve degeneracy caused by adjacent bins or mass measurement drift, or (3) you are processing studies with >10 samples where pairwise alignment becomes computationally expensive.

When NOT to use

  • Input is already a feature table or composite peak list (clustering is applied at the mass track stage, before feature detection)
  • Mass resolution is <0.1 amu or m/z measurement error is >5 ppm; nearest-neighbor clustering depends on sub-ppm precision
  • Single sample or no cross-sample overlap; clustering is most valuable when cohort-level alignment is needed

Inputs

  • mass tracks (EICs) extracted from individual mzML samples
  • m/z values binned at 0.001 amu resolution per sample
  • isotope or adduct difference patterns (e.g., 13C/12C, Na/H) for anchor detection
  • sample count and reference sample designation

Outputs

  • MassGrid structure: a table with one row per unique mass track, columns listing sample indices and their m/z values
  • centroided m/z values for each mass track cluster
  • anchor track annotations with alignment priority flags
  • m/z recalibration parameters if drift >1 ppm detected

How to apply

First, bin all m/z values from mass tracks across samples at 0.001 amu resolution, merging adjacent bins within tolerance. Apply nearest-neighbor clustering by m/z seeds (using mass_functions.nn_cluster_by_mz_seeds) to group overlapping m/z values into clusters. For small studies (≤10 samples), perform pairwise alignment on anchor mass tracks first and recalibrate if systematic drift exceeds 1 ppm, then align remaining tracks. For larger studies, centroid m/z values within each cluster and construct the MassGrid by binning all tracks across samples (using MassGrid.bin_track_mzs and MassGrid.build_grid_by_centroiding). The output is a MassGrid where each row represents a unique mass track identifier and contains sample indices mapped to their corresponding m/z values, with anchor tracks marked for higher priority.

Related tools

Examples

from asari.mass_functions import nn_cluster_by_mz_seeds; from asari.chromatograms import get_thousandth_bins; mz_bins = get_thousandth_bins(mass_tracks); clusters = nn_cluster_by_mz_seeds(mz_bins, tolerance=0.001)

Evaluation signals

  • MassGrid contains exactly one row per unique mass track identifier with no duplicates
  • Each MassGrid row lists all sample indices with measured m/z values and no missing values for samples where the track was detected
  • Centroided m/z values per cluster are within ±0.001 amu of the input bin resolution
  • Anchor mass tracks are marked with elevated priority flags and appear first in alignment order
  • For samples with systematic m/z drift >1 ppm, recalibration parameters are applied and post-correction pairwise m/z differences are <0.5 ppm
  • Mass tracks representing the same chemical species across samples cluster together; verify by comparing expected isotope offsets (1.003 amu for 13C/12C) to actual m/z differences in aligned rows

Limitations

  • Clustering precision depends on high mass resolution (sub-ppm accuracy); data with >1 ppm uncalibrated drift may produce spurious clusters or misalignments
  • Nearest-neighbor methods are sensitive to seed selection and bin width; suboptimal choices of 0.001 amu binning may either over-merge genuine distinct masses or fail to consolidate isotopologue series
  • For studies with very large numbers of samples (>>100), centroiding-based clustering may smooth out real biological variation in m/z if samples exhibit systematic within-cohort calibration differences
  • Anchor track detection (isotope/adduct patterns) requires presence of abundant ions; low-abundance or singleton mass tracks may not be detected as anchors and could be misaligned

Evidence

  • [other] bin m/z values at 0.001 amu resolution, merging adjacent bins within tolerance and applying nearest-neighbor clustering by m/z seeds: "Extract mass tracks from each sample using pymzml and bin m/z values at 0.001 amu resolution, merging adjacent bins within tolerance and applying nearest-neighbor clustering by m/z seeds to resolve"
  • [other] For small studies (≤10 samples), perform pairwise alignment by comparing anchor mass tracks first, recalibrating if drift exceeds 1 ppm, then aligning remaining mass tracks: "For small studies (≤10 samples), perform pairwise alignment by comparing anchor mass tracks first, recalibrating all m/z values if systematic drift exceeds 1 ppm, then aligning remaining mass tracks"
  • [other] For larger studies, apply nearest-neighbor clustering on all mass tracks across samples to bin and centroid m/z values into a unified MassGrid: "For larger studies, apply nearest-neighbor clustering on all mass tracks across samples to bin and centroid m/z values into a unified MassGrid"
  • [other] MassGrid contains one m/z row per unique mass track identifier, each row lists sample indices and their corresponding m/z values, and anchor tracks are marked with higher priority: "MassGrid contains one m/z row per unique mass track identifier, each row lists sample indices and their corresponding m/z values, and anchor tracks are marked with higher priority in the alignment"
  • [other] Asari aligns mass tracks across samples by constructing a MassGrid, leveraging high mass resolution to prioritize mass separation and alignment, enabling reproducible tracking: "Asari aligns mass tracks across samples by constructing a MassGrid, a process that leverages high mass resolution to prioritize mass separation and alignment, enabling reproducible tracking and"

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.