WriteMspFile {OrgMassSpecR}R Documentation

Write Spectra to the NIST MSP Text Format

Description

Writes all spectra in the OrgMassSpecR data frame format to a single text file in NIST MSP format. The MSP files can be imported into the NIST MS Search program to make a custom seachable library.

Usage

WriteMspFile(spectra, metadata, filename = "library.msp", comment = "")

Arguments

spectra

data frame containing the mass spectra.

metadata

data frame containing the metadata.

filename

character string. Name (including path if needed) of the MSP text file.

comment

charater string applied to the COMMENT field of the MSP file. The comment is applied to all spectra.

Details

The spectra and metadata data frame format is specified in the help files for the LibraryReport functions in the spectral library packages, for example see SpecLibExample::LibraryReport. The spectra data frame must contain at least columns: filename, mz, and intensity. The metadata data frame must contain at least columns: filename and compound.

The NAME field for each spectrum in the MSP file is assigned based on compound in the metadata data frame.

Newlines are CR+LF since the NIST MS Search program is Windows based.

Value

An MSP file is written using a file connection.

Author(s)

Nathan G. Dodder

Examples

## Simple example to illustrate the input data formats. 

spectra <- data.frame(filename = c(rep("Spectrum A", 2), rep("Spectrum B", 2)),
                      mz = c(50, 51, 100, 101),
                      intensity = c(70, 71, 90, 91))

metadata <- data.frame(filename = c("Spectrum A", "Spectrum B"),
                       compound = c("Compound A", "Compound B"))

## Not run: 
WriteMspFile(spectra = spectra, 
             metadata = metadata,
             filename = "Test.txt",
             comment = "Test Comment")

## End(Not run)

## Example using SpecLibExample package located at http://OrgMassSpec.github.io/libraries.html.
## Not run: 
library(SpecLibExample)
WriteMspFile(spectra = spec,
             metadata = meta,
             comment = "example output")

## End(Not run)

[Package OrgMassSpecR version 0.5-3 Index]