[Gtdb-commits] r53 - in pkg/gt.db: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri May 28 00:05:31 CEST 2010
Author: dahinds
Date: 2010-05-28 00:05:31 +0200 (Fri, 28 May 2010)
New Revision: 53
Added:
pkg/gt.db/man/manhattan.plot.Rd
Modified:
pkg/gt.db/R/gplot.R
pkg/gt.db/man/gplot.Rd
Log:
- added zlim argument to gplot
- added manhattan.plot()
Modified: pkg/gt.db/R/gplot.R
===================================================================
--- pkg/gt.db/R/gplot.R 2010-05-24 20:22:08 UTC (rev 52)
+++ pkg/gt.db/R/gplot.R 2010-05-27 22:05:31 UTC (rev 53)
@@ -1,32 +1,34 @@
#
# Copyright (C) 2009, Perlegen Sciences, Inc.
-#
+#
# Written by David A. Hinds <dhinds at sonic.net>
-#
+#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the license, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
-#
+#
gplot <-
function(formula, data, aggr.fn=max, rescale=FALSE, binsz=1e6,
- subset=TRUE, col.regions=rev(heat.colors(100)[10:100]),
+ subset=TRUE, col.regions=rev(heat.colors(100)[10:90]),
scales=list(x=list(at=seq(0,250,20), draw=TRUE)),
shrink=list(x=1,y=0.75), colorkey=list(height=0.25),
- xlab='Position, Mb', ylab='Chromosome', ...)
+ xlab='Position, Mb', ylab='Chromosome', zlim, ...)
{
subset <- eval(substitute(subset), data, environment(formula))
data <- data[subset,]
z <- latticeParseFormula(formula, data)$right
+ if (!missing(zlim))
+ z <- pmax(zlim[1],pmin(zlim[2],z))
bin <- list(factor(data$scaffold), trunc(data$position/binsz))
m <- tapply(z, bin, aggr.fn)
if (rescale) m <- m/mean(m,na.rm=TRUE)
@@ -44,3 +46,32 @@
col.regions=col.regions, colorkey=colorkey,
shrink=shrink, xlab=xlab, ylab=ylab, panel=p, ...)
}
+
+manhattan.plot <-
+ function(y, data, gap=0, threshold=-log10(5e-8), around=0,
+ xticks=c(1:12,14,16,18,20,22,'X','Y'), cex=0.25,
+ xlab=NULL, ylab=deparse(substitute(y)),
+ col=c('#d0d0d0','#e0e0e0','#ff0000'), ...)
+{
+ val <- eval(substitute(y), data, parent.frame())
+ len <- with(data, tapply(position, .sort.levels(scaffold),
+ max, na.rm=TRUE))
+ ofs <- cumsum(c(0,as.numeric(len+gap)))
+ mid <- (ofs[-1] + ofs[-length(ofs)])/2
+ pos <- data$position + ofs[match(data$scaffold, names(len))]
+ set <- list(superpose.symbol=list(col=col))
+ grp <- (match(data$scaffold, names(len)) %% 2)
+ grp <- ifelse(val > threshold, 2, grp)
+ if (around > 0) {
+ hits <- pos[which(val > threshold)]
+ keep <- (diff(hits) > around)
+ hits <- hits[c(TRUE,keep) | c(keep,TRUE)]
+ for (hit in hits) {
+ grp[abs(pos - hit) < around] <- 2
+ }
+ }
+ w <- match(paste('chr',xticks,sep=''), names(len))
+ xyplot(val~pos, ..., cex=cex, groups=grp, par.settings=set,
+ scales=list(x=list(at=mid[w],tck=0,labels=xticks)),
+ xlab=xlab, ylab=ylab)
+}
Modified: pkg/gt.db/man/gplot.Rd
===================================================================
--- pkg/gt.db/man/gplot.Rd 2010-05-24 20:22:08 UTC (rev 52)
+++ pkg/gt.db/man/gplot.Rd 2010-05-27 22:05:31 UTC (rev 53)
@@ -1,5 +1,6 @@
%
% Copyright (C) 2009, Perlegen Sciences, Inc.
+% Copyright (C) 2010, 23andMe, Inc.
%
% Written by David A. Hinds <dhinds at sonic.net>
%
@@ -25,16 +26,16 @@
}
\usage{
gplot(formula, data, aggr.fn=max, rescale=FALSE, binsz=1e6,
- subset=TRUE, col.regions=rev(heat.colors(100)[10:100]),
+ subset=TRUE, col.regions=rev(heat.colors(100)[10:90]),
scales=list(x=list(at=seq(0,250,20), draw=TRUE)),
shrink=list(x=1,y=0.75), colorkey=list(height=0.25),
- xlab='Position, Mb', ylab='Chromosome', ...)
+ xlab='Position, Mb', ylab='Chromosome', zlim, ...)
}
\arguments{
\item{formula}{a one-sided formula (i.e. \code{~ x}) describing the
values to be plotted.}
\item{data}{a data frame containing values required to evaluate
- \code{formula}, as well as \code{chromosome} and
+ \code{formula}, as well as \code{scaffold} and
\code{position} columns.}
\item{aggr.fn}{an aggregating function to apply to data within each bin.}
\item{rescale}{logical: indicates if results should be scaled based
@@ -44,6 +45,9 @@
\code{data} to be included in the plot.}
\item{col.regions, scales, shrink, colorkey, xlab, ylab}{see
\code{\link[lattice:levelplot]{levelplot}}.}
+ \item{zlim}{if present, gives the lower and upper limits for the
+ plotted values; values outside this range are clipped to the
+ appropriate limit value.}
\item{\dots}{additional arguments passed to
\code{\link[lattice:levelplot]{levelplot}}.}
}
Added: pkg/gt.db/man/manhattan.plot.Rd
===================================================================
--- pkg/gt.db/man/manhattan.plot.Rd (rev 0)
+++ pkg/gt.db/man/manhattan.plot.Rd 2010-05-27 22:05:31 UTC (rev 53)
@@ -0,0 +1,63 @@
+%
+% Copyright (C) 2010, 23andMe, Inc.
+%
+% Written by David A. Hinds <dhinds at sonic.net>
+%
+% This is free software; you can redistribute it and/or modify it
+% under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 3 of the license, or
+% (at your option) any later version.
+%
+% This program is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with this program. If not, see <http://www.gnu.org/licenses/>
+%
+\name{manhattan.plot}
+\alias{manhattan.plot}
+\title{Genome-Wide Manhattan Plot}
+\description{
+ Generates a "Manhattan plot" of genome-wide data, with chromosomes
+ arranged in ascending order along the X axis.
+}
+\usage{
+manhattan.plot(y, data, gap=0, threshold=-log10(5e-8), around=0,
+ xticks=c(1:12,14,16,18,20,22,'X','Y'), cex=0.25,
+ xlab=NULL, ylab=deparse(substitute(y)),
+ col=c('#d0d0d0','#e0e0e0','#ff0000'), ...)
+}
+\arguments{
+ \item{y}{the scores, evaluated in context of \code{data}.}
+ \item{data}{a data frame that includes \code{scaffold} and
+ \code{position} columns giving genomic positions.}
+ \item{gap}{a gap size, in base pairs, to insert between chromosomes.}
+ \item{threshold}{a score threshold for a \dQuote{hit}.}
+ \item{around}{in base pairs, specifies that SNPs within this interval
+ of a hit should also be highlighted.}
+ \item{xticks}{a list of chromosomes to be labeled in the plot.}
+ \item{cex, xlab, ylab}{see \code{\link[lattice:xyplot]{xyplot}}.}
+ \item{col}{colors to use for odd and even chromosomes, and hits.}
+ \item{\dots}{additional arguments passed to
+ \code{\link[lattice:xyplot]{xyplot}}.}
+}
+\details{
+ Typically, the scores are expected to be \code{-log10(pvalue)}.
+}
+\value{
+ A plot object of class \code{"trellis"}.
+}
+\seealso{
+ \code{\link{gplot}}, \code{\link[lattice:xyplot]{xyplot}}.
+}
+\examples{
+gt.demo.check()
+pt <- fetch.pt.data('Demo_1')
+gt <- fetch.gt.data('Demo_1')
+pt$status <- as.logical(rbinom(nrow(pt), 1, 0.5))
+r <- score.gt.data(status~genotype, pt, gt, score.chisq)
+manhattan.plot(-log10(pvalue), merge(r,gt), threshold=-log10(0.01))
+}
+\keyword{hplot}
More information about the Gtdb-commits
mailing list