mass-spectrometry-peak-enumeration
Summary
Systematically enumerate all pairwise mass differences from a mass spectrometry imaging (MSI) dataset to identify potential molecular adducts. This skill transforms a raw MSI intensity matrix into a ranked catalog of mass-difference patterns, enabling discovery of salt, matrix, and metabolite adducts that may otherwise remain hidden in complex datasets.
When to use
Apply this skill when you have preprocessed MSI data (peaks already binned and normalized) and need to detect adduct formation patterns across the dataset. Use it particularly when the 'dark metabolome' — abundant but unidentified peaks — dominates your spectra, or when you suspect matrix or salt ions are forming adducts with target metabolites and obscuring their detection.
When NOT to use
- Input peaks have not yet been binned or normalized (use Cardinal peakBin() or equivalent preprocessing first).
- You already have a validated adduct annotation table and only need to verify or refine assignments (use spatial correlation testing instead).
- Your instrument mass accuracy is worse than ~50 ppm, making histogram binning unreliable across the full mass range.
Inputs
- CSV matrix of preprocessed MSI intensities (peaks × pixels)
- MSI data matrix in msimat format (preprocessed, peak-binned)
- Cardinal MSProcessedImagingExperiment or MSContinuousImagingExperiment object (v2.2+)
- numeric vector of mass values (if intensity data not available)
Outputs
- massdiff object (data.frame with parent mass, adduct mass, and difference columns)
- massdiffhist histogram object (binned mass differences with counts)
- ranked data.frame of top adducts with occurrence counts and reference matches
- diffGetPeaks subset (parent–adduct ion pairs matching a target mass difference)
How to apply
Load the preprocessed MSI data as a CSV matrix using msimat() with the correct field separator. Compute all possible pairwise mass differences with massdiff(), which returns a data.frame with parent ion masses, adduct ion masses, and their differences. Bin these differences into a histogram using hist() with a bin width appropriate to your instrument's mass accuracy (e.g., 0.01 for 10 ppm precision instruments). Rank the histogram bins by occurrence using topAdducts() to identify the most abundant mass differences. Cross-reference these differences against known chemical adducts using adductMatch() with the built-in adducts reference table. The ranked list reveals which adducts dominate your dataset; high-count mass differences that match known adducts (e.g., DHB-H₂O at 136.016 Da) indicate systematic adduct formation.
Related tools
- mass2adduct (Primary R package providing massdiff(), hist(), adductMatch(), topAdducts(), and diffGetPeaks() functions; also manages the built-in adducts reference datasets.) — https://github.com/kbseah/mass2adduct
- Cardinal (Optional input source for MSI data; peak-binned MSProcessedImagingExperiment and MSContinuousImagingExperiment objects can be converted to msimat format via cardinal2msimat().)
- msimat() (Data import function that loads CSV-formatted MSI intensity matrices (exported from SCiLS, MSiReader, or other software) into the msimat object class required by massdiff().)
- R (Language and execution environment for the mass2adduct package workflow.)
Examples
d <- msimat("msi.csv", sep=";"); d.diff <- massdiff(d); d.diff.hist <- hist(d.diff); topAdducts(d.diff.hist, n=10)
Evaluation signals
- massdiff() output is a valid data.frame with exactly 3 columns (parent mass A, adduct mass B, mass difference) and row count equal to n×(n−1)/2 for n input peaks.
- histogram bin width matches instrument precision (e.g., 0.01 Da bin width for 10 ppm nominal resolution); inspect via plot(d.diff.hist) for a smooth, unimodal distribution.
- topAdducts() returns matches to known adducts (name, formula, mass) where the matched mass difference falls within the histogram bin containing the observed difference.
- High-count bins (top 5–10 adducts) correspond to chemically plausible ions (e.g., Na⁺, K⁺, NH₄⁺, matrix–H₂O losses) rather than random noise.
- Absence of spurious mass differences: compare the observed top differences against unexpected values; if all top hits are <50 counts out of millions of pairs, consider higher instrument noise or poor peak alignment.
Limitations
- The massdiff() function examines all n×(n−1)/2 pairwise combinations; for datasets with thousands of peaks, memory and runtime scale quadratically. Use the Perl script msimunging.pl to reformat large CSV files to triplet format before import, or use corrPairsMSIchunks() for correlation testing.
- Histogram binning requires choosing an appropriate bin width; if too narrow, adjacent adduct signals fragment; if too wide, distinct adducts merge. Bin width should match your instrument's mass measurement uncertainty, typically 5–50 ppm.
- The built-in adducts reference table (adducts and adducts2 datasets) contains common biologically relevant species but may not include rare or instrument-specific adducts; users must supply custom reference data.frames in the same format (name, formula, mass columns).
- No changelog or version-tracking information is provided in the repository, limiting reproducibility when package updates occur.
- The skill does not inherently account for false positives from random pair coincidences; validation via spatial correlation (corrPairsMSI) or external mass spectrometry standards is recommended before interpreting adduct identities.
Evidence
- [readme] Take all possible pairs of masses and calculate the mass difference for each pair. These mass differences represent potential molecular adducts.: "Take all possible pairs of masses and calculate the mass difference for each pair. These mass differences represent potential molecular adducts."
- [other] The massdiff function takes all possible pairs of masses from the MSI data matrix and calculates the mass difference for each pair, with these differences representing potential molecular adducts and returned as a data.frame object.: "The massdiff function takes all possible pairs of masses from the MSI data matrix and calculates the mass difference for each pair, with these differences representing potential molecular adducts and"
- [readme] The calculated mass differences are misleadingly precise, because measurement error and uncertainty are not taken into account. They should be binned into a histogram with a user-specified bin width, that depends on the known mass precision of your instrument.: "The calculated mass differences are misleadingly precise, because measurement error and uncertainty are not taken into account. They should be binned into a histogram with a user-specified bin width,"
- [other] topAdducts ranks mass differences by their occurrences, and reports them in descending order, as well as matches to known adducts, if any: "topAdducts ranks mass differences by their occurrences, and reports them in descending order, as well as matches to known adducts, if any"
- [readme] In mass spectrometry imaging, adducts can form between target molecules (e.g. metabolites) and other substances such as matrix or salt ions.: "In mass spectrometry imaging, adducts can form between target molecules (e.g. metabolites) and other substances such as matrix or salt ions."
- [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."
1---2name: mass-spectrometry-peak-enumeration3description: Use when you have preprocessed MSI data (peaks already binned and normalized) and need to detect adduct formation patterns across the dataset.4license: CC-BY-4.05---67# mass-spectrometry-peak-enumeration89## Summary1011Systematically enumerate all pairwise mass differences from a mass spectrometry imaging (MSI) dataset to identify potential molecular adducts. This skill transforms a raw MSI intensity matrix into a ranked catalog of mass-difference patterns, enabling discovery of salt, matrix, and metabolite adducts that may otherwise remain hidden in complex datasets.1213## When to use1415Apply this skill when you have preprocessed MSI data (peaks already binned and normalized) and need to detect adduct formation patterns across the dataset. Use it particularly when the 'dark metabolome' — abundant but unidentified peaks — dominates your spectra, or when you suspect matrix or salt ions are forming adducts with target metabolites and obscuring their detection.1617## When NOT to use1819- Input peaks have not yet been binned or normalized (use Cardinal peakBin() or equivalent preprocessing first).20- You already have a validated adduct annotation table and only need to verify or refine assignments (use spatial correlation testing instead).21- Your instrument mass accuracy is worse than ~50 ppm, making histogram binning unreliable across the full mass range.2223## Inputs2425- CSV matrix of preprocessed MSI intensities (peaks × pixels)26- MSI data matrix in msimat format (preprocessed, peak-binned)27- Cardinal MSProcessedImagingExperiment or MSContinuousImagingExperiment object (v2.2+)28- numeric vector of mass values (if intensity data not available)2930## Outputs3132- massdiff object (data.frame with parent mass, adduct mass, and difference columns)33- massdiffhist histogram object (binned mass differences with counts)34- ranked data.frame of top adducts with occurrence counts and reference matches35- diffGetPeaks subset (parent–adduct ion pairs matching a target mass difference)3637## How to apply3839Load the preprocessed MSI data as a CSV matrix using msimat() with the correct field separator. Compute all possible pairwise mass differences with massdiff(), which returns a data.frame with parent ion masses, adduct ion masses, and their differences. Bin these differences into a histogram using hist() with a bin width appropriate to your instrument's mass accuracy (e.g., 0.01 for 10 ppm precision instruments). Rank the histogram bins by occurrence using topAdducts() to identify the most abundant mass differences. Cross-reference these differences against known chemical adducts using adductMatch() with the built-in adducts reference table. The ranked list reveals which adducts dominate your dataset; high-count mass differences that match known adducts (e.g., DHB-H₂O at 136.016 Da) indicate systematic adduct formation.4041## Related tools4243- **mass2adduct** (Primary R package providing massdiff(), hist(), adductMatch(), topAdducts(), and diffGetPeaks() functions; also manages the built-in adducts reference datasets.) — https://github.com/kbseah/mass2adduct44- **Cardinal** (Optional input source for MSI data; peak-binned MSProcessedImagingExperiment and MSContinuousImagingExperiment objects can be converted to msimat format via cardinal2msimat().)45- **msimat()** (Data import function that loads CSV-formatted MSI intensity matrices (exported from SCiLS, MSiReader, or other software) into the msimat object class required by massdiff().)46- **R** (Language and execution environment for the mass2adduct package workflow.)4748## Examples4950```51d <- msimat("msi.csv", sep=";"); d.diff <- massdiff(d); d.diff.hist <- hist(d.diff); topAdducts(d.diff.hist, n=10)52```5354## Evaluation signals5556- massdiff() output is a valid data.frame with exactly 3 columns (parent mass A, adduct mass B, mass difference) and row count equal to n×(n−1)/2 for n input peaks.57- histogram bin width matches instrument precision (e.g., 0.01 Da bin width for 10 ppm nominal resolution); inspect via plot(d.diff.hist) for a smooth, unimodal distribution.58- topAdducts() returns matches to known adducts (name, formula, mass) where the matched mass difference falls within the histogram bin containing the observed difference.59- High-count bins (top 5–10 adducts) correspond to chemically plausible ions (e.g., Na⁺, K⁺, NH₄⁺, matrix–H₂O losses) rather than random noise.60- Absence of spurious mass differences: compare the observed top differences against unexpected values; if all top hits are <50 counts out of millions of pairs, consider higher instrument noise or poor peak alignment.6162## Limitations6364- The massdiff() function examines all n×(n−1)/2 pairwise combinations; for datasets with thousands of peaks, memory and runtime scale quadratically. Use the Perl script msimunging.pl to reformat large CSV files to triplet format before import, or use corrPairsMSIchunks() for correlation testing.65- Histogram binning requires choosing an appropriate bin width; if too narrow, adjacent adduct signals fragment; if too wide, distinct adducts merge. Bin width should match your instrument's mass measurement uncertainty, typically 5–50 ppm.66- The built-in adducts reference table (adducts and adducts2 datasets) contains common biologically relevant species but may not include rare or instrument-specific adducts; users must supply custom reference data.frames in the same format (name, formula, mass columns).67- No changelog or version-tracking information is provided in the repository, limiting reproducibility when package updates occur.68- The skill does not inherently account for false positives from random pair coincidences; validation via spatial correlation (corrPairsMSI) or external mass spectrometry standards is recommended before interpreting adduct identities.6970## Evidence7172- [readme] Take all possible pairs of masses and calculate the mass difference for each pair. These mass differences represent potential molecular adducts.: "Take all possible pairs of masses and calculate the mass difference for each pair. These mass differences represent potential molecular adducts."73- [other] The massdiff function takes all possible pairs of masses from the MSI data matrix and calculates the mass difference for each pair, with these differences representing potential molecular adducts and returned as a data.frame object.: "The massdiff function takes all possible pairs of masses from the MSI data matrix and calculates the mass difference for each pair, with these differences representing potential molecular adducts and"74- [readme] The calculated mass differences are misleadingly precise, because measurement error and uncertainty are not taken into account. They should be binned into a histogram with a user-specified bin width, that depends on the known mass precision of your instrument.: "The calculated mass differences are misleadingly precise, because measurement error and uncertainty are not taken into account. They should be binned into a histogram with a user-specified bin width,"75- [other] topAdducts ranks mass differences by their occurrences, and reports them in descending order, as well as matches to known adducts, if any: "topAdducts ranks mass differences by their occurrences, and reports them in descending order, as well as matches to known adducts, if any"76- [readme] In mass spectrometry imaging, adducts can form between target molecules (e.g. metabolites) and other substances such as matrix or salt ions.: "In mass spectrometry imaging, adducts can form between target molecules (e.g. metabolites) and other substances such as matrix or salt ions."77- [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."