Access list of rtime/intensity values from chromatograms object from MSnbase
1
1
Entering edit mode
@djshipman2011-21483
Last seen 4.9 years ago

Hello All,

I am working with the chromatograms object from MSnbase. I used the chromatogram method with a set run time range and mz range in turn creating a large chromatograms object. I see that there is an S4 method for accessing data inside of the object but can not quite get it to work to pull the list of intensity values from the object. When I write the chromatograms object to a txt file, I can see that the data is there and can access it that way, with a lot a data cleaning along the way. Is there a way to access this intensity and rtime data directly from the large chromatograms object itself in R?

Thank you

MSnbase chromatograms intensity • 1.1k views
ADD COMMENT
2
Entering edit mode
@laurent-gatto-5645
Last seen 9 weeks ago
Belgium

Below, I have the chrs object as created in ?Chromatograms. It is possible to extract the retention time and intensities from individual chromatogram composing the Chromatograms with rtime and intensity:

> chrs
Chromatograms with 2 rows and 2 columns
                  1              2
     <Chromatogram> <Chromatogram>
[1,]     length: 25     length: 32
[2,]     length: 19     length: 21
phenoData with 0 variables
featureData with 0 variables
> chrs[1, 1]
Object of class: Chromatogram
length of object: 25
from file: 
mz range: [NA, NA]
rt range: [1, 25]
MS level: 1
> rtime(chrs[1, 1])
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
> intensity(chrs[1, 1])
 [1]  19.557055 245.006734 129.752097  83.322814  74.496695  42.930450
 [7] 150.737775  13.503153  50.654998 153.979835  30.482448 143.358903
[13] 217.916567 251.069691 117.040263 328.638097 269.552266   1.415845
[19] 566.549108 181.653059  36.156939 415.043559 198.929917 387.871998
[25]  70.145956

To extract all of these at once, you can convert the Chromatograms to a list and iterate over the elements:

> str(lapply(as(chrs, "list"), intensity))
List of 4
 $ : num [1:25] 19.6 245 129.8 83.3 74.5 ...
 $ : num [1:19] 169.8 206.3 60.4 76.8 153.7 ...
 $ : num [1:32] 96.4 45.5 162.9 65.2 161.9 ...
 $ : num [1:21] 102.7 36.7 19.2 22.3 33.4 ...
> str(lapply(as(chrs, "list"), rtime))
List of 4
 $ : int [1:25] 1 2 3 4 5 6 7 8 9 10 ...
 $ : int [1:19] 1 2 3 4 5 6 7 8 9 10 ...
 $ : int [1:32] 1 2 3 4 5 6 7 8 9 10 ...
 $ : int [1:21] 1 2 3 4 5 6 7 8 9 10 ...
ADD COMMENT
0
Entering edit mode

Thank you so much! I was using the wrong syntax to access the data. Can the list of intensities and rtimes be added to a data frame without the additional information being included (x1, x2,...)?

Edit: Ignore me, I figured it out. Thank you so much for all the help!!!! :D

ADD REPLY

Login before adding your answer.

Traffic: 536 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6