Convert Cardinal MSI Objects to mass2adduct-Compatible Format
Summary
Converts Cardinal's MSProcessedImagingExperiment or MSContinuousImagingExperiment objects to the msimat matrix format required by downstream mass2adduct analysis, enabling seamless integration of Cardinal-preprocessed MSI data into adduct detection pipelines.
When to use
Your MSI data is stored in a Cardinal imaging experiment object (version 2.2+) that has already been peak-binned with peakBin(), and you want to run mass2adduct's massdiff() and adductMatch() pipeline without manually exporting to CSV; or your workflow already uses Cardinal for preprocessing and you wish to avoid intermediate file I/O.
When NOT to use
- Your MSI data has not yet been peak-binned; cardinal2msimat() requires processed Cardinal objects with a defined peaklist, not raw imaging experiments.
- You are importing MSI data from non-Cardinal sources (e.g., MSiReader, SCiLS); use the CSV-based msimat() function instead.
- You only need to extract m/z values without pixel intensity information; use scan() on a plain-text mass list instead.
Inputs
- Cardinal MSProcessedImagingExperiment or MSContinuousImagingExperiment object (version 2.2+)
- Must be pre-processed with peak binning (peakBin() applied)
- ImzML or vendor-native MSI file loaded via readImzML()
Outputs
- msimat object (mass intensity matrix with classes 'msimat' and 'data.frame')
- Rows represent m/z peaks, columns represent image pixels
- Preserves intensity values for downstream spatial correlation tests
How to apply
After preprocessing your Cardinal object with normalize(), smoothSignal(), reduceBaseline(), peakBin(peaklist), and process(), pass the resulting MSProcessedImagingExperiment or MSContinuousImagingExperiment object to cardinal2msimat(). This function extracts the peak intensities and spatial coordinates, reformatting them into the msimat class (a matrix where rows are m/z values and columns are pixel locations). Verify the conversion succeeded by comparing the peak histogram from the original Cardinal object (plot(d_peaks)) with the msimat histogram (plot(d_msimat))—they should be visually identical. The output msimat object is then ready for massdiff() to compute all pairwise mass differences across pixels.
Related tools
- Cardinal (Preprocesses raw MSI data (normalize, smooth, reduce baseline, peak bin) before format conversion) — http://cardinalmsi.org/
- mass2adduct (Receives msimat output to compute pairwise mass differences and match adducts) — https://github.com/kbseah/mass2adduct
- R (Execution environment; required for loading Cardinal and running cardinal2msimat())
Examples
d <- readImzML("msi_file"); d_peaks <- d %>% normalize() %>% smoothSignal() %>% reduceBaseline() %>% peakBin(peaklist) %>% process(); d_msimat <- cardinal2msimat(d_peaks); d.diff <- massdiff(d_msimat)
Evaluation signals
- Output object has class 'msimat' and can be printed with standard R print() to show row (m/z) and column (pixel) dimensions.
- Peak histogram from converted msimat (plot(d_msimat)) matches the histogram from the original Cardinal object (plot(d_peaks)) visually and quantitatively (same peak positions and relative heights).
- Intensity values are preserved: spot-check several m/z peaks by comparing intensity profiles in Cardinal vs. msimat using indexing (e.g., d_msimat[1, 1:10]).
- The msimat object is compatible with downstream mass2adduct functions: massdiff(d_msimat) runs without error and returns a massdiff object.
- Spatial dimensions match: number of columns in msimat equals the total number of pixels in the original Cardinal imaging experiment.
Limitations
- Requires Cardinal version 2.2 or later; earlier versions lack MSProcessedImagingExperiment and MSContinuousImagingExperiment classes.
- Data must be pre-processed and peak-binned before conversion; raw, unpeak-binned Cardinal objects cannot be converted.
- Large MSI datasets (hundreds of thousands of peaks × millions of pixels) may consume significant memory even after conversion; consider sparse triplet format for very large files (via msimunging.pl).
- The conversion preserves only intensity information and peak lists; metadata such as scan times, instrument parameters, or custom annotations in the Cardinal object are not transferred to msimat.
Evidence
- [readme] Cardinal
MSProcessedImagingExperiment or MSContinuousImagingExperiment objects (requires Cardinal v2.2 and above) can be converted to mass2adduct's msimat format. However, the data must first be pre-processed, with peaks already binned with the peakBin() function from Cardinal.: "Cardinal MSProcessedImagingExperiment or MSContinuousImagingExperiment objects (requires Cardinal v2.2 and above) can be converted to mass2adduct's msimat format. However, the data must first"
- [methods] If you are using Cardinal to process your MSI data, data objects in the
MSProcessedImagingExperiment or MSContinuousImagingExperiment formats can be converted to mass2adduct's msimat format: "If you are using Cardinal to process your MSI data, data objects in the MSProcessedImagingExperiment or MSContinuousImagingExperiment formats can be converted to mass2adduct's msimat format"
- [readme] Compare peak histograms from Cardinal vs mass2adduct, should look the same: "Compare peak histograms from Cardinal vs mass2adduct, should look the same"
- [readme] Pre-process and peak bin with existing peaklist: d_peaks <- d %>% normalize() %>% smoothSignal() %>% reduceBaseline() %>% peakBin(peaklist) %>% process; Convert to msimat format for mass2adduct: d_msimat <- cardinal2msimat(d_peaks): "d_peaks <- d %>% normalize() %>% smoothSignal() %>% reduceBaseline() %>% peakBin(peaklist) %>% process; d_msimat <- cardinal2msimat(d_peaks)"
- [methods] 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."
1---2name: msi-data-format-interoperability3description: Use when your MSI data is stored in a Cardinal imaging experiment object (version 2.2+) that has already been peak-binned with peakBin(), and you want to run mass2adduct's massdiff() and adductMatch() pipeline without manually exporting to CSV;4license: CC-BY-4.05---67# Convert Cardinal MSI Objects to mass2adduct-Compatible Format89## Summary1011Converts Cardinal's MSProcessedImagingExperiment or MSContinuousImagingExperiment objects to the msimat matrix format required by downstream mass2adduct analysis, enabling seamless integration of Cardinal-preprocessed MSI data into adduct detection pipelines.1213## When to use1415Your MSI data is stored in a Cardinal imaging experiment object (version 2.2+) that has already been peak-binned with peakBin(), and you want to run mass2adduct's massdiff() and adductMatch() pipeline without manually exporting to CSV; or your workflow already uses Cardinal for preprocessing and you wish to avoid intermediate file I/O.1617## When NOT to use1819- Your MSI data has not yet been peak-binned; cardinal2msimat() requires processed Cardinal objects with a defined peaklist, not raw imaging experiments.20- You are importing MSI data from non-Cardinal sources (e.g., MSiReader, SCiLS); use the CSV-based msimat() function instead.21- You only need to extract m/z values without pixel intensity information; use scan() on a plain-text mass list instead.2223## Inputs2425- Cardinal MSProcessedImagingExperiment or MSContinuousImagingExperiment object (version 2.2+)26- Must be pre-processed with peak binning (peakBin() applied)27- ImzML or vendor-native MSI file loaded via readImzML()2829## Outputs3031- msimat object (mass intensity matrix with classes 'msimat' and 'data.frame')32- Rows represent m/z peaks, columns represent image pixels33- Preserves intensity values for downstream spatial correlation tests3435## How to apply3637After preprocessing your Cardinal object with normalize(), smoothSignal(), reduceBaseline(), peakBin(peaklist), and process(), pass the resulting MSProcessedImagingExperiment or MSContinuousImagingExperiment object to cardinal2msimat(). This function extracts the peak intensities and spatial coordinates, reformatting them into the msimat class (a matrix where rows are m/z values and columns are pixel locations). Verify the conversion succeeded by comparing the peak histogram from the original Cardinal object (plot(d_peaks)) with the msimat histogram (plot(d_msimat))—they should be visually identical. The output msimat object is then ready for massdiff() to compute all pairwise mass differences across pixels.3839## Related tools4041- **Cardinal** (Preprocesses raw MSI data (normalize, smooth, reduce baseline, peak bin) before format conversion) — http://cardinalmsi.org/42- **mass2adduct** (Receives msimat output to compute pairwise mass differences and match adducts) — https://github.com/kbseah/mass2adduct43- **R** (Execution environment; required for loading Cardinal and running cardinal2msimat())4445## Examples4647```48d <- readImzML("msi_file"); d_peaks <- d %>% normalize() %>% smoothSignal() %>% reduceBaseline() %>% peakBin(peaklist) %>% process(); d_msimat <- cardinal2msimat(d_peaks); d.diff <- massdiff(d_msimat)49```5051## Evaluation signals5253- Output object has class 'msimat' and can be printed with standard R print() to show row (m/z) and column (pixel) dimensions.54- Peak histogram from converted msimat (plot(d_msimat)) matches the histogram from the original Cardinal object (plot(d_peaks)) visually and quantitatively (same peak positions and relative heights).55- Intensity values are preserved: spot-check several m/z peaks by comparing intensity profiles in Cardinal vs. msimat using indexing (e.g., d_msimat[1, 1:10]).56- The msimat object is compatible with downstream mass2adduct functions: massdiff(d_msimat) runs without error and returns a massdiff object.57- Spatial dimensions match: number of columns in msimat equals the total number of pixels in the original Cardinal imaging experiment.5859## Limitations6061- Requires Cardinal version 2.2 or later; earlier versions lack MSProcessedImagingExperiment and MSContinuousImagingExperiment classes.62- Data must be pre-processed and peak-binned before conversion; raw, unpeak-binned Cardinal objects cannot be converted.63- Large MSI datasets (hundreds of thousands of peaks × millions of pixels) may consume significant memory even after conversion; consider sparse triplet format for very large files (via msimunging.pl).64- The conversion preserves only intensity information and peak lists; metadata such as scan times, instrument parameters, or custom annotations in the Cardinal object are not transferred to msimat.6566## Evidence6768- [readme] Cardinal `MSProcessedImagingExperiment` or `MSContinuousImagingExperiment` objects (requires Cardinal v2.2 and above) can be converted to mass2adduct's `msimat` format. However, the data must first be pre-processed, with peaks already binned with the `peakBin()` function from Cardinal.: "Cardinal `MSProcessedImagingExperiment` or `MSContinuousImagingExperiment` objects (requires Cardinal v2.2 and above) can be converted to mass2adduct's `msimat` format. However, the data must first"69- [methods] If you are using Cardinal to process your MSI data, data objects in the `MSProcessedImagingExperiment` or `MSContinuousImagingExperiment` formats can be converted to mass2adduct's `msimat` format: "If you are using Cardinal to process your MSI data, data objects in the `MSProcessedImagingExperiment` or `MSContinuousImagingExperiment` formats can be converted to mass2adduct's `msimat` format"70- [readme] Compare peak histograms from Cardinal vs mass2adduct, should look the same: "Compare peak histograms from Cardinal vs mass2adduct, should look the same"71- [readme] Pre-process and peak bin with existing peaklist: d_peaks <- d %>% normalize() %>% smoothSignal() %>% reduceBaseline() %>% peakBin(peaklist) %>% process; Convert to msimat format for mass2adduct: d_msimat <- cardinal2msimat(d_peaks): "d_peaks <- d %>% normalize() %>% smoothSignal() %>% reduceBaseline() %>% peakBin(peaklist) %>% process; d_msimat <- cardinal2msimat(d_peaks)"72- [methods] 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."