Description Usage Arguments Examples
Convenient plot for MS2 data, with superimposed Raw- and processed data.
1 2 3 4 5 6 | plotGroups(xraw, precursor = NULL, xa, mzrange = NULL, rtrange = NULL,
ms1peaks = NULL, precursorcol = 1)
plotAllSpectra(xa, specperpage=9, prefix="Spec",
pspecs=1:length(xa@pspectra),
titles="", ...)
|
xraw |
|
precursor |
|
xa |
|
mzrange |
|
rtrange |
|
ms1peaks |
|
precursorcol |
|
specperpage |
Plot multiple spectra per page |
prefix |
Use prefix for generated graphics |
pspecs |
Indix of spectra to be plotted, default: all |
titles |
Graphics title(s) |
... |
Arguments passed to - idontknow. |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function(xraw, precursor=NULL, xa, mzrange=NULL, rtrange=NULL,
ms1peaks=NULL, precursorcol=1) {
## Create usable/nonconflicting set of colors
groupcolors <- rep(grep("dark.*[^123]$", colors(), value=TRUE),
length.out=length(xa@pspectra))
## groupcolors <- rep(c("red", "blue", "cyan", "magenta", "yellow", "aquamarine4",
## "darkred", "darkblue", "darkcyan", "darkmagenta", "darkgray",
## "aliceblue","aquamarine","brown" ,"chocolate", "purple", "violetred",
## "tomato", "turquoise", "darkgoldenrod4", "brown4"),
## length.out=length(xa@pspectra))
grouppeakcolors <- unlist(sapply(1:length(xa@pspectra),
function(x) {
## omit black
rep(groupcolors[x], each=length(xa@pspectra[[x]]))
}))
peakcolors <- rep(1, each=nrow(xa@peaks))
peakcolors[unlist(xa@pspectra)] <- grouppeakcolors
bbox <- t(sapply (xa@pspectra, function(x) {
c(rtmin = min(xa@peaks[x,"rtmin"]),
rtmed = mean(xa@peaks[x,"rt"]),
rtmax = max(xa@peaks[x,"rtmax"]),
mzmin = min(xa@peaks[x,"mzmin"]),
mzmed = mean(xa@peaks[x,"mz"]),
mzmax = max(xa@peaks[x,"mzmax"])
)
}))
if (is.null(rtrange)) {
if (is.null(xraw)) {
rtrange <- range(getPeaklist(xa)[,"rt"])
} else {
rtrange <- range(xraw@scantime)
}
}
if (is.null(mzrange) ) {
if (!is.null(rtrange)) {
inrange <- which (bbox[,"rtmed"] > rtrange[1] & bbox[,"rtmed"] < rtrange[2])
mzrange <- c(max(bbox[inrange,"mzmax"]), min(bbox[inrange,"mzmin"]))
} else {
if (!is.null(xraw)) {
mzrange <- xraw@mzrange
} else {
mzrange <- range(getPeaklist(xa)[,"mz"])
}
}
}
## title <- gsub(".mzData","", basename(xraw@filepath))
title <- gsub(".mzData","", basename(filepaths(xa@xcmsSet)))
if (!is.null(xraw)) {
raw <- rawMat(xraw, mzrange, rtrange, NULL, log=TRUE)
y <- raw[,"intensity"]
ylim <- range(y)
y <- y/ylim[2]
colorlut <- terrain.colors(20)
col <- colorlut[y*15+4]
plot(cbind(raw[,"time"], raw[,"mz"]), pch=".", cex=1.8,
main = title, xlab="Seconds", ylab="m/z", col=col,
xlim=range(raw[,"time"]), ylim=range(raw[,"mz"]))
## par(cex=0.5)
## plotRaw(xraw, log=TRUE,
## mzrange=mzrange, rtrange=rtrange,
## title=gsub(basename(xraw@filepath), ".mzData",""))
## par(cex=1)
} else {
plot.new()
plot.window(xlim=rtrange, ylim=mzrange,
xlab="Seconds", ylab="m/z")
axis(1)
axis(2)
box()
title(main=title,
xlab="Seconds", ylab="m/z")
}
if (!is.null(precursor)) {
bounds <- which( precursor[1:nrow(precursor)-1,2]
!= precursor[2:nrow(precursor),2])
start <- c(1, bounds[1:length(bounds)]+1)
end <- c(bounds[1:length(bounds)], nrow(precursor))
## col <- ifelse(alphaChannelSupported(),
## rgb(t(col2rgb(precursorcol)),
## alpha=mean(col2rgb(precursorcol)),
## max=255),
## precursorcol)
col <- precursorcol
rect(precursor[start,"rt"], precursor[start,"mz"]-4,
precursor[end,"rt"], precursor[end,"mz"]+4,
border=col)
}
if (!is.null(ms1peaks)) {
## Most peaks are correct:
## TODO: weighted distance (e.g. rt+mz*10)
ms1 <- peaks(ms1peaks)[,c("rt","mz")]
ms2pre <- precursor
ms2a <- xa
## Precursor mz / rt
psprt <- bbox[,"rtmed"]
pspmz <- ms2pre[findInterval(psprt, ms2pre[,"rt"]),"mz"]
psppre <- cbind(rt=bbox[,"rtmed"], mz=pspmz)
## Closest MS1 peak
ms1pre <- peaks(ms1peaks)[knn(ms1, psppre, 1:nrow(ms1)),c("rt","mz", "into")]
points(ms1pre, col=groupcolors,
cex=log(ms1pre[,"into"])*0.2,
lwd=log(ms1pre[,"into"])*0.33,
)
segments(bbox[,"rtmed"], bbox[,"mzmin"], ms1pre[,"rt"], ms1pre[,"mz"],
col=groupcolors, lwd=1.5)
} else {
segments(bbox[,"rtmed"], bbox[,"mzmin"], bbox[,"rtmed"], bbox[,"mzmax"],
col=groupcolors, lwd=1.5)
}
## text(x=bbox[,"rtmed"],
## mzrange[1]+(mzrange[2]-mzrange[1])*(0.8 + 0.05*1:length(xa@pspectra)%%4),
## col=groupcolors, labels=1:length(xa@pspectra))
## Random order o to avoid biased overdrawing
o <- order(xa@peaks[,"into"])
points(xa@peaks[o,c("rt", "mz")],
cex=log(xa@peaks[o,"into"])*0.2,
lwd=log(xa@peaks[o,"into"])*0.33,
pch=4, col=peakcolors[o])
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.