mass-spectrum-basepeak-extraction
Summary
Programmatically extract base-peak m/z and intensity values from individual MS1 scans in Thermo Orbitrap raw files using the rawrr package. This skill enables construction of scan-indexed base-peak tables without external file conversion, facilitating direct integration of raw spectral data into R-based proteomics pipelines.
When to use
When you have Thermo Fisher Scientific .raw files from Orbitrap instruments and need to build a quantitative summary of MS1 acquisition intensity dynamics across a run—specifically, the m/z and intensity of the most intense peak in each MS1 scan. This is useful for quality control, retention time alignment, and rapid characterization of acquisition performance without full spectra processing.
When NOT to use
- Input is already in a converted exchange format (mzML, netCDF, HDF5) — use that parser instead of re-reading the raw file.
- You need full spectral data (all peaks in each scan, not just the maximum) — use readSpectrum() directly without the max-intensity filter.
- Raw file is from a non-Thermo instrument (e.g., Bruker, Waters, Sciex) — rawrr does not support those formats.
Inputs
- Thermo Fisher Scientific Orbitrap .raw file
- Scan index data.frame (output of readIndex())
- MS1-level scan numbers (integer vector, ms == 1)
Outputs
- Base-peak table (data.frame with columns: scan_number, basepeak_mz, basepeak_intensity)
- CSV file of base-peak per-scan summary
How to apply
Install the rawrr executable via rawrr::installRawrrExe(), then load the raw file and generate a scan index data.frame using readIndex(). Subset the index to retain only MS1-level scans (ms == 1). For each MS1 scan number, call readSpectrum() to retrieve the rawrrSpectrum object, then extract the m/z value and intensity at the maximum intensity point—these form the base-peak pair. Aggregate the scan number, base-peak m/z, and base-peak intensity into a two-column (or three-column) data.frame and write to CSV. The rationale is that base-peak intensity tracks ionization and transmission efficiency across the run, while base-peak m/z variation reveals scan-to-scan precursor mass shifts or contamination.
Related tools
- rawrr (R package that wraps RawFileReader .NET assembly to read spectra and metadata from .raw files; provides readIndex(), readSpectrum(), and accessor functions for extracting base-peak m/z and intensity) — https://github.com/fgcz/rawrr
- RawFileReader (Vendor-provided .NET assembly (C#) that implements low-level binary .raw file parsing; called by rawrr via system calls) — https://github.com/thermofisherlsms/RawFileReader
- MsBackendRawFileReader (Optional: Bioconductor-compliant MsBackend that wraps rawrr to allow on-disk spectral data access via the Spectra package ecosystem) — https://github.com/cpanse/MsBackendRawFileReader
Examples
index <- rawrr::readIndex(rawrr::sampleFilePath()); ms1_idx <- subset(index, ms == 1); bp_table <- do.call(rbind, lapply(ms1_idx$scan, function(s) { sp <- rawrr::readSpectrum(rawrr::sampleFilePath(), scan = s); max_idx <- which.max(sp@intensity); data.frame(scan = s, bp_mz = sp@mz[max_idx], bp_int = sp@intensity[max_idx]) })); write.csv(bp_table, 'basepeak_ms1.csv')
Evaluation signals
- Output base-peak table has one row per MS1 scan in the raw file; no missing or duplicate scan numbers.
- Base-peak m/z values fall within the instrument's calibrated mass range and show continuous or slow drift across the run (not random jumps).
- Base-peak intensity values are positive, lie within the instrument's dynamic range, and follow expected chromatographic envelope shape (rise and fall with elution).
- Comparison with external validation (e.g., ThermoRawFileParser or Skyline export of the same file) shows row-by-row agreement in scan numbers and base-peak m/z ± 0.01 Da and intensity ± 1%.
- CSV output is well-formed (no trailing commas, proper headers, numeric columns parse without errors).
Limitations
- rawrr requires the RawFileReader .NET assembly, which must be installed and runs via system calls; performance degrades with very large raw files (>10 GB) due to file I/O overhead during spectrum parsing.
- Base-peak extraction is deterministic only if spectra have been calibrated; uncalibrated or badly calibrated raw files may show erratic m/z or intensity values.
- The skill currently does not handle MS2+ scans (only MS1 = 1); filtering by scan type (e.g., 'FTMS + c NSI Full ms2') is available but requires extension to the workflow.
- On Linux and macOS, the .NET runtime (Mono or .NET Core) must be installed separately; Windows support is native.
Evidence
- [full_text] rawrr provides readIndex() to generate a scan index data.frame, readSpectrum() to read spectral data, and accessor functions to programmatically extract scan properties, enabling construction of base-peak tables from raw files without external conversion.: "rawrr provides readIndex() to generate a scan index data.frame, readSpectrum() to read spectral data, and accessor functions to programmatically extract scan properties, enabling construction of"
- [full_text] 1. Install rawrr executable using rawrr::installRawrrExe(). 2. Load the sample raw file path using rawrr::sampleFilePath(). 3. Generate the scan index as a data.frame using readIndex() on the raw file. 4. Subset the index to retain only MS1-level scans (ms == 1). 5. Iterate over each MS1 scan number and call readSpectrum() to retrieve individual spectrum objects. 6. Extract the base-peak m/z (mz value at maximum intensity) and intensity from each rawrrSpectrum object. 7. Aggregate base-peak m/z and intensity into a two-column table indexed by scan number and write to CSV.: "Iterate over each MS1 scan number and call readSpectrum() to retrieve individual spectrum objects. 6. Extract the base-peak m/z (mz value at maximum intensity) and intensity from each rawrrSpectrum"
- [readme] rawrr wraps the functionality of the RawFileReader .NET assembly: "rawrr wraps the functionality of the RawFileReader .NET assembly"
- [methods] R functions request access to data from binary raw files via compiled C# wrapper methods using system calls: "R functions requesting access to data stored in binary raw files (reader family functions listed in Table 1) invoke compiled C# wrapper methods using a system call."
- [results] Individual scans or scan collections (sets) can be read by the function readSpectrum(): "Individual scans or scan collections (sets) can be read by the function readSpectrum()"
1---2name: mass-spectrum-basepeak-extraction3description: Use when when you have Thermo Fisher Scientific .raw files from Orbitrap instruments and need to build a quantitative summary of MS1 acquisition intensity dynamics across a run—specifically, the m/z and intensity of the most intense peak in each MS1 scan.4license: CC-BY-4.05---67# mass-spectrum-basepeak-extraction89## Summary1011Programmatically extract base-peak m/z and intensity values from individual MS1 scans in Thermo Orbitrap raw files using the rawrr package. This skill enables construction of scan-indexed base-peak tables without external file conversion, facilitating direct integration of raw spectral data into R-based proteomics pipelines.1213## When to use1415When you have Thermo Fisher Scientific .raw files from Orbitrap instruments and need to build a quantitative summary of MS1 acquisition intensity dynamics across a run—specifically, the m/z and intensity of the most intense peak in each MS1 scan. This is useful for quality control, retention time alignment, and rapid characterization of acquisition performance without full spectra processing.1617## When NOT to use1819- Input is already in a converted exchange format (mzML, netCDF, HDF5) — use that parser instead of re-reading the raw file.20- You need full spectral data (all peaks in each scan, not just the maximum) — use readSpectrum() directly without the max-intensity filter.21- Raw file is from a non-Thermo instrument (e.g., Bruker, Waters, Sciex) — rawrr does not support those formats.2223## Inputs2425- Thermo Fisher Scientific Orbitrap .raw file26- Scan index data.frame (output of readIndex())27- MS1-level scan numbers (integer vector, ms == 1)2829## Outputs3031- Base-peak table (data.frame with columns: scan_number, basepeak_mz, basepeak_intensity)32- CSV file of base-peak per-scan summary3334## How to apply3536Install the rawrr executable via rawrr::installRawrrExe(), then load the raw file and generate a scan index data.frame using readIndex(). Subset the index to retain only MS1-level scans (ms == 1). For each MS1 scan number, call readSpectrum() to retrieve the rawrrSpectrum object, then extract the m/z value and intensity at the maximum intensity point—these form the base-peak pair. Aggregate the scan number, base-peak m/z, and base-peak intensity into a two-column (or three-column) data.frame and write to CSV. The rationale is that base-peak intensity tracks ionization and transmission efficiency across the run, while base-peak m/z variation reveals scan-to-scan precursor mass shifts or contamination.3738## Related tools3940- **rawrr** (R package that wraps RawFileReader .NET assembly to read spectra and metadata from .raw files; provides readIndex(), readSpectrum(), and accessor functions for extracting base-peak m/z and intensity) — https://github.com/fgcz/rawrr41- **RawFileReader** (Vendor-provided .NET assembly (C#) that implements low-level binary .raw file parsing; called by rawrr via system calls) — https://github.com/thermofisherlsms/RawFileReader42- **MsBackendRawFileReader** (Optional: Bioconductor-compliant MsBackend that wraps rawrr to allow on-disk spectral data access via the Spectra package ecosystem) — https://github.com/cpanse/MsBackendRawFileReader4344## Examples4546```47index <- rawrr::readIndex(rawrr::sampleFilePath()); ms1_idx <- subset(index, ms == 1); bp_table <- do.call(rbind, lapply(ms1_idx$scan, function(s) { sp <- rawrr::readSpectrum(rawrr::sampleFilePath(), scan = s); max_idx <- which.max(sp@intensity); data.frame(scan = s, bp_mz = sp@mz[max_idx], bp_int = sp@intensity[max_idx]) })); write.csv(bp_table, 'basepeak_ms1.csv')48```4950## Evaluation signals5152- Output base-peak table has one row per MS1 scan in the raw file; no missing or duplicate scan numbers.53- Base-peak m/z values fall within the instrument's calibrated mass range and show continuous or slow drift across the run (not random jumps).54- Base-peak intensity values are positive, lie within the instrument's dynamic range, and follow expected chromatographic envelope shape (rise and fall with elution).55- Comparison with external validation (e.g., ThermoRawFileParser or Skyline export of the same file) shows row-by-row agreement in scan numbers and base-peak m/z ± 0.01 Da and intensity ± 1%.56- CSV output is well-formed (no trailing commas, proper headers, numeric columns parse without errors).5758## Limitations5960- rawrr requires the RawFileReader .NET assembly, which must be installed and runs via system calls; performance degrades with very large raw files (>10 GB) due to file I/O overhead during spectrum parsing.61- Base-peak extraction is deterministic only if spectra have been calibrated; uncalibrated or badly calibrated raw files may show erratic m/z or intensity values.62- The skill currently does not handle MS2+ scans (only MS1 = 1); filtering by scan type (e.g., 'FTMS + c NSI Full ms2') is available but requires extension to the workflow.63- On Linux and macOS, the .NET runtime (Mono or .NET Core) must be installed separately; Windows support is native.6465## Evidence6667- [full_text] rawrr provides readIndex() to generate a scan index data.frame, readSpectrum() to read spectral data, and accessor functions to programmatically extract scan properties, enabling construction of base-peak tables from raw files without external conversion.: "rawrr provides readIndex() to generate a scan index data.frame, readSpectrum() to read spectral data, and accessor functions to programmatically extract scan properties, enabling construction of"68- [full_text] 1. Install rawrr executable using rawrr::installRawrrExe(). 2. Load the sample raw file path using rawrr::sampleFilePath(). 3. Generate the scan index as a data.frame using readIndex() on the raw file. 4. Subset the index to retain only MS1-level scans (ms == 1). 5. Iterate over each MS1 scan number and call readSpectrum() to retrieve individual spectrum objects. 6. Extract the base-peak m/z (mz value at maximum intensity) and intensity from each rawrrSpectrum object. 7. Aggregate base-peak m/z and intensity into a two-column table indexed by scan number and write to CSV.: "Iterate over each MS1 scan number and call readSpectrum() to retrieve individual spectrum objects. 6. Extract the base-peak m/z (mz value at maximum intensity) and intensity from each rawrrSpectrum"69- [readme] rawrr wraps the functionality of the RawFileReader .NET assembly: "rawrr wraps the functionality of the RawFileReader .NET assembly"70- [methods] R functions request access to data from binary raw files via compiled C# wrapper methods using system calls: "R functions requesting access to data stored in binary raw files (reader family functions listed in Table 1) invoke compiled C# wrapper methods using a system call."71- [results] Individual scans or scan collections (sets) can be read by the function readSpectrum(): "Individual scans or scan collections (sets) can be read by the function readSpectrum()"