MSI Data Matrix Import and Validation
Summary
Import mass spectrometry imaging (MSI) intensity data from CSV or Cardinal objects into R and validate the resulting matrix representation. This skill ensures data integrity and correct format conversion before downstream adduct detection and correlation analysis.
When to use
You have MSI intensity data exported from MSiReader, SCiLS, or Cardinal as plain-text CSV files or as Cardinal MSProcessedImagingExperiment/MSContinuousImagingExperiment objects, and need to load it into R as a validated msimat object for mass difference and adduct analysis.
When NOT to use
- Input data is already in msimat format or pre-loaded into R memory—skip import and proceed directly to massdiff().
- You have only a plain list of masses (no pixel intensity information) and do not need spatial correlation testing—use scan() directly instead.
- Data originates from non-imaging mass spectrometry (e.g., bulk liquid chromatography–mass spectrometry) with no spatial coordinates—this skill is specific to MSI.
Inputs
- CSV file exported from MSiReader or SCiLS with intensity matrix (mass × pixel)
- Cardinal MSProcessedImagingExperiment or MSContinuousImagingExperiment object (v2.2+, pre-processed with peakBin())
- Triplet format files (rows, cols, vals, peaks, spots) from msimunging.pl conversion
Outputs
- msimat object (S3 class inheriting from data.frame) with mass spectrum and intensity matrix
- Validated mass spectrum plot showing total intensity per peak
How to apply
Use the msimat() function to import CSV data with appropriate separator (typically semicolon for European-formatted exports). Specify the file path and sep parameter matching your file format. For Cardinal objects, pre-process with peakBin() first, then convert using cardinal2msimat(). After import, validate by inspecting the object class (should be 'msimat'), printing the summary, and comparing the resulting mass spectrum plot to the original to ensure no data corruption. For very large CSV files (several gigabytes), consider reformatting to triplet format using the provided msimunging.pl Perl script before import to avoid memory overflow.
Related tools
Examples
d <- msimat(system.file("extdata","msi.csv",package="mass2adduct"),sep=";"); class(d); print(d); plot(d)
Evaluation signals
- Returned object has class 'msimat' (verify with class(d))
- print(d) produces a summary report with expected number of peaks and pixels
- plot(d) generates a mass spectrum matching the original instrument output or software visualization
- For Cardinal imports: mass spectrum from cardinal2msimat() matches plot of pre-processed Cardinal object
- For triplet imports: data reconstruction is lossless (compare sum of intensities or histogram with original CSV)
Limitations
- CSV files must be exported from known sources (MSiReader, SCiLS) in plain-text format; other proprietary formats may fail.
- Cardinal conversion requires pre-processing with peakBin() and Cardinal v2.2+; earlier versions unsupported.
- For very large CSV files (>RAM capacity), msimunging.pl conversion is necessary but may still fail if file exceeds total system memory.
- Triplet format conversion with msimunging.pl is limited by available RAM; conversion of 40 Gb CSV on 32 Gb system unlikely to succeed.
- No built-in handling for missing data or NaN values; these should be imputed or filtered before import.
Evidence
- [readme] MSI data exported from the MSiReader software with the "intensity export" function, or from some other third party software that can output plain-text comma-delimited tables (CSV format).: "MSI data exported from the MSiReader software with the "intensity export" function, or from some other third party software that can output plain-text comma-delimited tables (CSV format)"
- [readme] If the data matrix is very large, consider reformatting it: "If the data matrix is very large, consider reformatting it (see "Reformatting large CSV files" below). Import the data into R as a data.frame: d <- msimat("msi.csv", sep=";")"
- [readme] Cardinal MSProcessedImagingExperiment or MSContinuousImagingExperiment objects 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"
- [other] Load the example MSI data (msi.csv) from inst/extdata using the msimat() function with appropriate separator (semicolon).: "Load the example MSI data (msi.csv) from inst/extdata using the msimat() function with appropriate separator (semicolon)"
- [readme] Plain-text CSV files of MSI data exported by software such as SCILS or MSIreader can be large, on the order of several Gb. For many MSI data sets, a lot of this is "wasted" because the majority of peaks are only detected in a minority of pixels.: "Plain-text CSV files of MSI data exported by software such as SCILS or MSIreader can be large, on the order of several Gb. For many MSI data sets, a lot of this is "wasted" because the majority of"
1---2name: msi-data-matrix-import-and-validation3description: Use when you have MSI intensity data exported from MSiReader, SCiLS, or Cardinal as plain-text CSV files or as Cardinal MSProcessedImagingExperiment/MSContinuousImagingExperiment objects, and need to load it into R as a validated msimat object for mass difference and adduct analysis.4license: CC-BY-4.05---67# MSI Data Matrix Import and Validation89## Summary1011Import mass spectrometry imaging (MSI) intensity data from CSV or Cardinal objects into R and validate the resulting matrix representation. This skill ensures data integrity and correct format conversion before downstream adduct detection and correlation analysis.1213## When to use1415You have MSI intensity data exported from MSiReader, SCiLS, or Cardinal as plain-text CSV files or as Cardinal MSProcessedImagingExperiment/MSContinuousImagingExperiment objects, and need to load it into R as a validated msimat object for mass difference and adduct analysis.1617## When NOT to use1819- Input data is already in msimat format or pre-loaded into R memory—skip import and proceed directly to massdiff().20- You have only a plain list of masses (no pixel intensity information) and do not need spatial correlation testing—use scan() directly instead.21- Data originates from non-imaging mass spectrometry (e.g., bulk liquid chromatography–mass spectrometry) with no spatial coordinates—this skill is specific to MSI.2223## Inputs2425- CSV file exported from MSiReader or SCiLS with intensity matrix (mass × pixel)26- Cardinal MSProcessedImagingExperiment or MSContinuousImagingExperiment object (v2.2+, pre-processed with peakBin())27- Triplet format files (rows, cols, vals, peaks, spots) from msimunging.pl conversion2829## Outputs3031- msimat object (S3 class inheriting from data.frame) with mass spectrum and intensity matrix32- Validated mass spectrum plot showing total intensity per peak3334## How to apply3536Use the msimat() function to import CSV data with appropriate separator (typically semicolon for European-formatted exports). Specify the file path and sep parameter matching your file format. For Cardinal objects, pre-process with peakBin() first, then convert using cardinal2msimat(). After import, validate by inspecting the object class (should be 'msimat'), printing the summary, and comparing the resulting mass spectrum plot to the original to ensure no data corruption. For very large CSV files (several gigabytes), consider reformatting to triplet format using the provided msimunging.pl Perl script before import to avoid memory overflow.3738## Related tools3940- **mass2adduct** (R package providing msimat() import function, msimat class definition, and validation methods for MSI data) — https://github.com/kbseah/mass2adduct41- **Cardinal** (R package for preprocessing MSI data; data objects convertible to msimat format via cardinal2msimat()) — http://cardinalmsi.org/42- **msimunging.pl** (Perl script bundled in mass2adduct inst/ folder for reformatting large CSV files to triplet format before import) — https://github.com/kbseah/mass2adduct4344## Examples4546```47d <- msimat(system.file("extdata","msi.csv",package="mass2adduct"),sep=";"); class(d); print(d); plot(d)48```4950## Evaluation signals5152- Returned object has class 'msimat' (verify with class(d))53- print(d) produces a summary report with expected number of peaks and pixels54- plot(d) generates a mass spectrum matching the original instrument output or software visualization55- For Cardinal imports: mass spectrum from cardinal2msimat() matches plot of pre-processed Cardinal object56- For triplet imports: data reconstruction is lossless (compare sum of intensities or histogram with original CSV)5758## Limitations5960- CSV files must be exported from known sources (MSiReader, SCiLS) in plain-text format; other proprietary formats may fail.61- Cardinal conversion requires pre-processing with peakBin() and Cardinal v2.2+; earlier versions unsupported.62- For very large CSV files (>RAM capacity), msimunging.pl conversion is necessary but may still fail if file exceeds total system memory.63- Triplet format conversion with msimunging.pl is limited by available RAM; conversion of 40 Gb CSV on 32 Gb system unlikely to succeed.64- No built-in handling for missing data or NaN values; these should be imputed or filtered before import.6566## Evidence6768- [readme] MSI data exported from the MSiReader software with the "intensity export" function, or from some other third party software that can output plain-text comma-delimited tables (CSV format).: "MSI data exported from the MSiReader software with the "intensity export" function, or from some other third party software that can output plain-text comma-delimited tables (CSV format)"69- [readme] If the data matrix is very large, consider reformatting it: "If the data matrix is very large, consider reformatting it (see "Reformatting large CSV files" below). Import the data into R as a data.frame: d <- msimat("msi.csv", sep=";")"70- [readme] Cardinal MSProcessedImagingExperiment or MSContinuousImagingExperiment objects 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"71- [other] Load the example MSI data (msi.csv) from inst/extdata using the msimat() function with appropriate separator (semicolon).: "Load the example MSI data (msi.csv) from inst/extdata using the msimat() function with appropriate separator (semicolon)"72- [readme] Plain-text CSV files of MSI data exported by software such as SCILS or MSIreader can be large, on the order of several Gb. For many MSI data sets, a lot of this is "wasted" because the majority of peaks are only detected in a minority of pixels.: "Plain-text CSV files of MSI data exported by software such as SCILS or MSIreader can be large, on the order of several Gb. For many MSI data sets, a lot of this is "wasted" because the majority of"