Skip to main content
Topic: How do I plot the EIC for compounds XCMS has found? (Read 8701 times) previous topic - next topic

How do I plot the EIC for compounds XCMS has found?

I'm really confused about how to use plotEIC, plotPeaks and plotChrom and how they're different. From the help file, it sounds like they're all plotting raw data, which isn't what I want. I would like to plot the retention-time-corrected and aligned peaks for specific mass features. So far, I have:
* picked peaks with xcmsSet,
* grouped them with group,
* corrected the retention time with retcor,
* grouped again with group,
* filled in missing peaks with fillPeaks,
* and generated a difference report with diffreport.
When I called the diffreport function, I had it also plot the EICs for the top 20-most different peaks, and those plots are the kind of plots I want. How do I create plots for the EICs of other compounds that XCMS has found? I don't really want it to plot every single one of the 5000+ compounds it found and then just look through that list and find the png files I'm interested in. How do I choose the ones that I want? I've tried playing around with getEIC, plotEIC, plotPeaks and plotChrom, and, to be honest, I can't get a single one of them to work, and I'm just not really understanding what the help file is saying. 

Thanks in advance.

Laura

Re: How do I plot the EIC for compounds XCMS has found?

Reply #1
Hi Laura,

plotPeaks and plotCrom works only on xcmsRaw objects. So using the retention time corrected peaks within a xcmsSet you have to use the getEIC function.
I created some code snippet with the faahKO data set, which should do what you want.

Code: [Select]
library(xcms)
library(faahKO)

xs.grp  <- group(faahko)
xs.ret  <- retcor(xs.grp)
xs.grp2  <- group(xs.ret)
xs.fill <- fillPeaks(xs.grp2)

xeic.raw <- getEIC(xs.fill, rt = "raw", groupidx= 1:nrow(xs.fill@groups))
xeic.corrected <- getEIC(xs.fill, rt = "corrected", groupidx= 1:nrow(xs.fill@groups))

#plot first feature from diffreport (not sorted after pval!!)
#rt row data
plot(xeic.raw, xs.fill,groupidx=1)
#rt corrected data
plot(xeic.corrected, xs.fill,groupidx=1)

Re: How do I plot the EIC for compounds XCMS has found?

Reply #2
Thanks for the response, Carsten!

I tried your code, and while I could get it to work with the first mass feature listed in the groups, I couldn't get it to work with any others. For example, I tried looking at the 4th mass feature, and I got an error that says, "Error in tempsplit[[2]] : subscript out of bounds".

Here's what I did for the 1st mass feature (and this worked):
Code: [Select]
MF1.raw <- getEIC(set5.filledpeaks, rt="raw", groupidx=1)
MF1.cor <- getEIC(set5.filledpeaks, rt="corrected", groupidx=1)

par(mfrow=c(2,1))
plot(MF1.raw, set5.filledpeaks, groupidx=1)
plot(MF1.cor, set5.filledpeaks, groupidx=1)
And here's what I did for the 4th mass feature (and this gave me that error above when I tried getEIC so I didn't even get to the plot part):
Code: [Select]
MF4.raw <- getEIC(set5.filledpeaks, rt="raw", groupidx=4)
MF4.cor <- getEIC(set5.filledpeaks, rt="corrected", groupidx=4)
Any suggestions? Thank you very much for your help!

Laura

Re: How do I plot the EIC for compounds XCMS has found?

Reply #3
If you extract only the 4th mass feature with
Code: [Select]
MF4.cor <- getEIC(set5.filledpeaks, rt="corrected", groupidx=4)
then the xcmsEIC object contains only 1! mass feature.

So you can plot it with
Code: [Select]
plot(MF1.cor, set5.filledpeaks, groupidx=1) #not 4

But why don't you extract all with mass features as in my example with
groupidx= 1:nrow(set5.filledpeaks)
and plot afterwards the 4th?

That should work!

Carsten

Re: How do I plot the EIC for compounds XCMS has found?

Reply #4
Oh, I see: getEIC populates some other table that you call when you use plot, so if you only getEIC for one compound, regardless of what groupidx it was in originally, now it will be the 1 and only groupidx, right? Thank you, Carsten!

I feel like I'm asking questions that must be spelled out someplace in some documentation somewhere, and I just don't want to waste your time. Is there some documentation that explains some of these things or did you read through the code itself to figure that out?

Another question I have is how to figure out what the groupidx for a given compound is. It doesn't appear to be related to the output of diffreport, so then I thought that it might be the row number for the output of groups(set5.filledpeaks) but it doesn't look like that's it, either.

Thanks again!

Laura

Re: How do I plot the EIC for compounds XCMS has found?

Reply #5
Quote
Is there some documentation that explains some of these things or did you read through the code itself to figure that out?
I simply knew it ;) , because I worked a long time with xcms and use some of its functions in CAMERA. I'm not aware of any additional documentation besides the normal vignette and the man pages.
 
Quote
Another question I have is how to figure out what the groupidx for a given compound is. It doesn't appear to be related to the output of diffreport, so then I thought that it might be the row number for the output of groups(set5.filledpeaks) but it doesn't look like that's it, either.
As I mentioned in my previous post, the diffreport result is per default sorted by p-value. So the easiest way to retrieve the same order would be to call diffreport with:
Code: [Select]
diffreport(object, sortpval=FALSE)

Re: How do I plot the EIC for compounds XCMS has found?

Reply #6
Ok, now I see how to find my compound! Yay! This seems to be working! I am so pleased with this!

THANK YOU very much, Carsten!!!

Laura