rformassspectrometry / Spectra

Low level infrastructure to handle MS spectra
https://rformassspectrometry.github.io/Spectra/
38 stars 25 forks source link

adduct type #324

Open cbroeckl opened 6 months ago

cbroeckl commented 6 months ago

i am working on storing some MS/MS data in Spectra objects. I was interested in storing the adduct type, so ideally when this is exported to msp or mgf (or other) that adduct type is exported with the MS/MS data. Is there a slot for this that has a defined name? Thanks. Corey

jorainer commented 6 months ago

we generally store the information as a spectra variable "adduct". Then, for export to e.g. MGF it depends a bit into which "field" you want the information to be written. We have a parameter mapping that allows to specify the mapping between spectra variables and the fields in the MGF for both data import and export.

The parameter takes a named character, names being the spectra variable names and the values the name of the "field" in the MGF. An example could be:

mms <- c(
    rtime = "RTINSECONDS",
    acquisitionNum = "SCANS",
    precursorMz = "PEPMASS",
    precursorIntensity = "PEPMASSINT",
    precursorCharge = "CHARGE",
    spectrum_id = "TITLE",
    compound_name = "COMPOUND_NAME",
    adduct = "ADDUCT",
    smiles = "SMILES",
    inchi = "INCHI",
    inchikey = "INCHIKEY",
    ms_mass_analyzer = "MS_MASS_ANALYZER",
    ionization = "MS_IONISATION",
    exactmass = "PARENT_MASS",
    collisionEnergy = "COLLISION_ENERGY",
    ms_manufacturer = "MS_MANUFACTURER",
    ms_dissociation_method = "MS_DISSOCIATION_METHOD"
)

This is how I currently load information from the matchms cleaned GNPS MGF files. If your Spectra object has a spectra variable $adduct the information will be written as ADDUCT: with the value of the $adduct variable for that specific spectrum into the MGF. You see that there are also a lot of other mappings and variables. If your Spectra object does not provide these, the data will simply not exported (same for the import), i.e. you can provide mappings also for variables that you don't have.

To use this mms you would call e.g.

s <- Spectra("my-mgf-file.mgf", source = MsBackendMgf(), mapping = mms)

And to write this information to MGF you would call:

export(s, backend = MsBackendMgf(), mapping = mms)