agentsclimarketplace

Spatial correlation analysis in imaging mass spectrometry

Skill HolobiomicsLab/asb-skill-collections/collections/metabolomics/v2/skills/spatial-correlation-analysis-in-imaging-mass-spectrometry

Use when after annotating ion pairs with known adducts (using adductMatch or diffGetPeaks), use this skill to filter suspected adduct pairs by testing if their pixel-level intensity profiles are significantly correlated.From its SKILL.md

Install
npx -y skills add HolobiomicsLab/asb-skill-collections --skill spatial-correlation-analysis-in-imaging-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

  • 14 stars14 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

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

spatial-correlation-analysis-in-imaging-mass-spectrometry

Summary

Test whether annotated ion pairs in mass spectrometry imaging data exhibit significant spatial covariance by computing two-tailed Pearson correlation coefficients across pixel intensities. This validates whether suspected parent–adduct relationships are supported by correlated abundance patterns in the tissue sample.

When to use

After annotating ion pairs with known adducts (using adductMatch or diffGetPeaks), use this skill to filter suspected adduct pairs by testing if their pixel-level intensity profiles are significantly correlated. This is essential because mass difference alone is not sufficient evidence of true chemical relationships; spatial correlation in imaging data provides orthogonal validation that two peaks co-localize and co-vary in abundance.

When NOT to use

  • Input massdiff contains unannotated pairs without adduct matches; spatial correlation is most useful after enriching the candidate set with chemical knowledge.
  • MSI data lacks pixel-level spatial structure or contains only bulk/averaged spectra rather than per-pixel intensities; correlation analysis requires variance across sampling locations.
  • Dataset is too small (very few pixels or peaks) to support robust correlation estimation and multiple-testing correction.

Inputs

  • msimat object (pixel × mass intensity matrix)
  • massdiff object with annotated ion pairs (data.frame with columns A, B, and adduct annotations)

Outputs

  • massdiff object augmented with columns: Estimate (Pearson r), P.value (raw), Significance (boolean, Bonferroni-corrected)

How to apply

Load the original msimat object (the full MSI intensity data matrix with pixels as rows and mass peaks as columns) alongside the annotated massdiff object containing the ion pair candidates. Apply corrPairsMSI() to compute two-tailed Pearson correlation for each pair, which extracts the intensity vectors for both peaks from the msimat and tests spatial covariance. The function returns Estimate (correlation coefficient), raw P.value, and Bonferroni-corrected Significance (boolean, default α=0.05). For datasets with hundreds or thousands of peaks that exhaust memory, use corrPairsMSIchunks() instead to process pairs in serial batches. Filter the output to retain only pairs meeting your significance threshold (typically p<0.05 after Bonferroni correction); these represent ion pairs with statistically validated spatial correlation.

Related tools

Examples

d.diff.annot.cor <- corrPairsMSI(d, d.diff.annot)

Evaluation signals

  • Output massdiff object contains non-NA Estimate and P.value columns for each tested pair; no values should be missing except for pairs with insufficient variance.
  • Bonferroni-corrected Significance column is boolean (TRUE/FALSE); FALSE values should predominate if no true spatial correlations exist; TRUE values indicate p < 0.05/n_pairs.
  • Correlation Estimate values range between −1 and +1; positive values expected for true parent–adduct pairs (co-abundant); negative or near-zero values suggest non-specific mass differences.
  • Distribution of raw P.values should be predominantly >0.05 for noise; a significant tail of low p-values (<0.05) indicates detected spatial correlations.
  • Reproducibility: re-running corrPairsMSI on the same input data yields identical Estimate, P.value, and Significance columns (deterministic output).

Limitations

  • Bonferroni correction is conservative; with thousands of ion pairs, corrected significance thresholds become very stringent (p < 0.05/n_pairs), risking false negatives. Consider Benjamini–Hochberg FDR correction as an alternative if not available in the package.
  • Pearson correlation assumes linear relationships; non-linear spatial covariance (e.g., threshold effects, saturation) may be missed.
  • Requires per-pixel intensity values; cannot be applied to mass spectra that have been collapsed, normalized per-pixel, or pre-filtered in ways that remove intensity variance.
  • Memory usage scales quadratically with peak count; corrPairsMSIchunks helps but is slower; very large datasets (thousands of peaks across millions of pixels) may still be impractical.
  • Output p-values depend critically on the assumption of independent observations; if pixels are spatially autocorrelated (common in tissue imaging), effective sample size is inflated and p-values are overly optimistic.
  • Correlation strength does not distinguish causal relationships; two peaks may correlate due to indirect biochemical relationships rather than direct adduct formation.

Evidence

  • [methods] This performs a correlation test (by default two-tailed with Pearson's method) on each pair of peaks in the massdiff object.: "This performs a correlation test (by default two-tailed with Pearson's method) on each pair of peaks in the massdiff object."
  • [methods] Now that we have a list of annotated massdiffs, we want to exploit the spatial information contained in the MSI data to test if each ion pair is actually spatially correlated in the sample.: "Now that we have a list of annotated massdiffs, we want to exploit the spatial information contained in the MSI data to test if each ion pair is actually spatially correlated in the sample."
  • [readme] Output is a data.frame with p-values for each ion pair. By default the cutoff for significance is p=0.05 with Bonferroni correction.: "Output is a data.frame with p-values for each ion pair. By default the cutoff for significance is p=0.05 with Bonferroni correction."
  • [readme] For large data sets, where the tables would not fit into memory, it is possible to break up the problem into "chunks" processed serially. Use the function corrPairsMSIchunks instead of corrPairsMSI.: "For large data sets, where the tables would not fit into memory, it is possible to break up the problem into "chunks" processed serially. Use the function corrPairsMSIchunks instead of corrPairsMSI."
  • [methods] The corrPairsMSI() function performs a two-tailed Pearson correlation test on each pair of peaks in the massdiff object to assess spatial correlation between parent and adduct ions.: "performs a two-tailed Pearson correlation test on each pair of peaks in the massdiff object to assess spatial correlation between parent and adduct ions"

What ships with it

Read from the repository

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

Keep looking

Skills are one crate of 326,861. 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.