Skip to main content
Topic: How do I pick peaks on a selected RT range? (Read 6845 times) previous topic - next topic

How do I pick peaks on a selected RT range?

So you have a load of data and you're only really interested in picking peaks on a small range of data. There are two ways of doing this, the new way, which is an upgrade since mzR was incorporated into xcms and the older way. We'll look at both.

1) The new way. Here we'll use the scanrange option to look at only a certain range of the spectra. To do so please make sure that your xcms version is updated to the latest code. (Tested with xcms v 1.35.2)
First, we need to convert the scan time into a scans. Each scan has a certain time. You know the time that you want but the instrument knows that the scan was 1 or 100. The actual time will be slight different after this conversion for the different files.
Code: [Select]
library(xcms)
library(faahKO)
cdfpath <- system.file("cdf", package = "faahKO")
cdffiles <- list.files(cdfpath, recursive = TRUE,full=T)
## lets convert into time into scans
RTrange<-c(2600,3000)
xr<-xcmsRaw(cdffiles[5]) ## loads up a single file into an xcmsRaw object
which(xr@scantime > 2600 & xr@scantime < 2605)[1]
## [1] 65
> which(xr@scantime > 3499 & xr@scantime < 3500)
## [1] 639
xr@scantime[c(65,639)] This will be our new scan range

xset <- xcmsSet(cdffiles, scanrange=c(65,636))


2)The old way. In this method all of the LC-MS spectrum is used for peak detection.
Afterwards the xcmsSet object is slimmed down to only the required range. This method can be quite useful if you want to have both the slimmed down object and the full RT range object in your R user space at the same time.

Code: [Select]
library(xcms)
library(faahKO)
cdfpath <- system.file("cdf", package = "faahKO")
cdffiles <- list.files(cdfpath, recursive = TRUE,full=T)
xset <- xcmsSet(cdffiles)
## Do peak detection on everything

## Now edit the object to the required range
RTrange<c(2600, 3500)
ix.rt<-which(xset@peaks[,"rt"] > RTrange[1] & xset@peaks[,"rt"] < RTrange[2])
xsetRT<-xset## copy the object into a new object to save the old one :)
xsetRT@peaks<-xset@peaks[ix.rt,] ## selects only the peaks that we want in the range and copy it into  the new object
xset
xsetRT

The results should look something like this. Notice the RT range is now changed:
xset :
An "xcmsSet" object with 12 samples

Time range: 2506.1-4147.7 seconds (41.8-69.1 minutes)
Mass range: 200.1-599.3338 m/z
Peaks: 4721 (about 393 per sample)
Peak Groups: 0
Sample classes: KO, WT

Profile settings: method = bin
                  step = 0.1

Memory usage: 0.713 MB

xsetRT:
An "xcmsSet" object with 12 samples

Time range: 2604.7-3499.8 seconds (43.4-58.3 minutes)
Mass range: 200.1-597.3132 m/z
Peaks: 2722 (about 227 per sample)
Peak Groups: 0
Sample classes: KO, WT

Profile settings: method = bin
                  step = 0.1

Memory usage: 0.515 MB
~~
H. Paul Benton
Scripps Research Institute
If you have an error with XCMS Online please send me the JOBID and submit an error via the XCMS Online contact page