lgatto / MSnbase

Base Classes and Functions for Mass Spectrometry and Proteomics
http://lgatto.github.io/MSnbase/
123 stars 50 forks source link

Change the unit of retention time from minute to second #572

Closed MuyaoXi9271 closed 2 years ago

MuyaoXi9271 commented 2 years ago

Hi expert,

I got the .mgf file of MS2 data in which the unit of retention time is minute, as shown in the image below image

My question is that is it possible to change the unit of retention time from minute to second and corresponding values by any function. Thanks in advance

Bests, Muyao

lgatto commented 2 years ago

Once you have loaded your data into R (as an MSnExp, I assume), you could simply multiply the retention time values by 60 to get seconds.

MuyaoXi9271 commented 2 years ago

Thanks for your quick answer.

In the MSnExp object, I could actually add a new variable SECOND under "featureData" section. The actual problem is that the value of Retention time becomes 0:00 in the assayData, as shown below image

Therefore, even though I add the new variable "SECOND", I can not get the right value of retention time, if I write MSnExp as .mgf file. Do you have some ideas to deal with that? Thanks in advance.

Bests, Muyao

lgatto commented 2 years ago

The retention time accessor will ignore your SECOND variable, and there's not way to tell it to do so. As I said, your best option would be to update the default rtime data.

MuyaoXi9271 commented 2 years ago

It could be a stupid question, but I have no idea how to update the default rtime for MSnExp object by codes.

lgatto commented 2 years ago

This will depend on your MSnExp - if it's on-disk, this should do it:

fData(x)$retentionTime <- fData(x)$retentionTime * 60

In-memory would be rather difficult.

Also, I suggest you look at the Spectra package, which is a considerable improvement to MSnbase.

MuyaoXi9271 commented 2 years ago

Thanks for your suggestion. I will close the issue. Bests.