%% book chapter for Computational statistics vol III on data vizualisation.

\documentclass[11pt]{article}
\usepackage[numbers,sort&compress]{natbib}

\usepackage{color}
\definecolor{darkblue}{rgb}{0.0,0.0,0.75}

\usepackage[%
baseurl={http://www.bioconductor.org},%
pdftitle={Visualizing Genomic Data},%
pdfauthor={Wolfgang Huber},%
pdfsubject={Visualization, Genomics},%
pdfkeywords={Bioconductor},%
pagebackref,bookmarks,colorlinks,linkcolor=darkblue,citecolor=darkblue,%
pagecolor=darkblue,raiselinks,plainpages,pdftex]{hyperref}

\usepackage[pdftex]{graphicx}
%% \DeclareGraphicsExtensions{.tiff}


\newcommand{\Robject}[1]{\texttt{{#1}}}
\newcommand{\Rpackage}[1]{\textit{{#1}}}
\newcommand{\Rfunction}[1]{\textit{{#1}}}
\newcommand{\Rclass}[1]{\textit{{#1}}}
\newcommand{\mycapt}[1]{\centerline{{\fontfamily{phv}\selectfont\textbf{{#1}}}}}
\newcommand{\myhead}[1]{{\fontfamily{phv}\selectfont\textbf{{#1}}}}
\newcommand{\myincfig}[3]{%
  \begin{figure}[tp]
    \begin{center}
      \includegraphics[width=#2]{#1}
      \caption{\label{#1}#3}
    \end{center}
  \end{figure}
}
\newcommand{\fixme}[1]{\marginpar{fixme}\textit{#1}}

\begin{document}

%------------------------------------------------------------
\title{Visualizing Genomic Data\\
{\small Book chapter for Handbook of Computational Statistics, edited by W. H\"ardle}}
%------------------------------------------------------------
\author{Florian Hahne, Wolfgang Huber, Robert Gentleman}

\maketitle
\tableofcontents

<<caching, results=hide, echo=FALSE>>=
cache <- function(name, expr) {
  cachefile <- paste("tmp-", name, ".RData", sep="")
  if(file.exists(cachefile)) {
    load(cachefile)
  } else {
    assign(name, expr)
    save(list=name, file=cachefile)
  }
  get(name)
}
@


<<setup, results=hide, echo=FALSE>>=
## note: the dependencies are contained in the DESCRIPTION file of the CompStatViz package
library("CompStatViz")
data("CLLbatch")
stopifnot(package.version("CompStatViz") >= package_version("0.5.4"))
@

%--------------------------------------------------
\section{Introduction}
%--------------------------------------------------
The advent of experimental techniques capable of probing biomolecules
and cells at high levels of resolution has led to a rapid change in
the methods used for experimental molecular
biology~\cite{NatGenChipping}. The range of applications is dramatic,
from basic biology to the study of human diseases. Since these
techniques produce massive amounts of data, there has been a
corresponding need to develop new statistical methods for modeling and
interpreting the observed data. 

In this chapter we discuss visualization methods that can be applied
to various sorts of data. This is not the place to define and describe
all of the relevant biology, and interested readers are referred to
texts such as \cite{HMG,Alberts} for more complete details. We also
note that the examples are intended to convey principles of
visualization and are not in any way complete, or definitive
descriptions of how to process genomic data; these topics are covered
elsewhere \cite{biocbook2005, Speed}, for example.

There are many good books on visualization~\cite{Cleveland:1993, Cleveland:1994,
TufteEI,TufteQI} that can be consulted for ideas. Visualization does remain an 
art, yet there are underlying principles that should be adhered to.
Visualization is more than simply producing a plot, or some other graphic.
It involves conscious decisions about what message should be conveyed
by a particular plot and the choice of methodologies that are likely to
convey that information easily and accurately to the user. While we give 
specific examples, we will also try to point out where general
principles apply and to indicate some reasonable extensions that could be
made. The use of color is important, and appropriate choice of color schemes 
is essential.  

Our examples and code are all written in R and make use of many
different R and Bioconductor packages. Good references for more
extensive discussion and examples are \cite{biocbook2005,Rgraphics}.
There is an accompanying R package named \Rpackage{CompStatViz} that
contains the data and supplementary R code that produces most of the
figures, tables and statistics reported in this chapter. It can be
obtained from the Bioconductor web site \url{http://www.bioconductor.org}.

%------------------------------------------------------------
\section{Data}
\label{sec:Data}
%------------------------------------------------------------
We use a number of different data sets in the examples given in this 
chapter and here provide brief descriptions of the different data
sets.

\paragraph{CLL} The chronic lymphocytic leukemia (CLL) microarray data were 
generated in Dr. J. Ritz's lab at the Dana Farber Cancer Institute, by Dr. S.
Chiaretti. The data consist of 24 Affymetrix HGU95Av2 arrays on blood samples
from patients with CLL. While there are a number of phenotypic characteristics
of interest we have restricted our attention to one which is a characteristic
of the disease and patients are classified as either stable or progressive.
Data on this phenotype is available for 23 of the 24 arrays.

The CLL data are processed using \Rfunction{gcrma} \cite{Wu:etal:2004} from 
the \Rpackage{affy} package to compute expression estimates for each 
probeset. We carried out two separate reductions of the genes. In
one we selected those genes where the expression level on the measured scale
was larger than 100 in at least 25\% of the samples,
the IQR was larger than $0.5$ on the log scale, and the median
expression, across samples, was larger than 300 on the normal scale. 
Such genes should be useful for prediction, but were purposely selected 
without regard to phenotype. This subset was used only for the second
multidimensional scaling plot.

%
<<gcrma, echo=FALSE, results=hide>>=
CLL.exprs = cache("CLL.exprs", gcrma(CLLbatch))
sampleNames(CLL.exprs) = gsub("\.CEL", "", sampleNames(CLL.exprs))
data(disease)
pD = new("phenoData", pData=disease,
   varLabels = list(SampleID = "Sample ID", Disease = "Stable/Progressive"))
phenoData(CLL.exprs) <- pD
f1 <- pOverA(.25, log2(100))
f2 <- function(x)(IQR(x)>0.5)
f3 <- function(x) (median(x) > log2(300))
ff <- filterfun(f1,f2,f3)
selected <- genefilter(CLL.exprs, ff)
sum(selected)
CLL.sub <- CLL.exprs[selected,]
eS <- exprs(CLL.sub)
@
<<ttestfilter, echo=FALSE, results=hide>>=
goodCell = !is.na(CLL.exprs$Disease)

rwtt = rowttests(CLL.exprs[,goodCell], CLL.exprs$Disease[goodCell])

ff2 = filterfun(f1, f2)
sel2 = genefilter(CLL.exprs, ff2)

forsubset = sel2 & rwtt$p.value < 0.005
CLL.dis = CLL.exprs[forsubset, goodCell]
eSdis = exprs(CLL.dis)
@

The second filtering was designed to select genes that are the best
differentiators of stable disease versus progressive disease. To that end, in
addition to the first two filters described above we also used a $t$-test to
compare the two groups and selected those genes that had an unadjusted
$p$-value less than $0.005$.  We were left with \Sexpr{sum(forsubset)} genes.
We will make use of this subset in most of the examples below, and will refer
to it as the CLL disease progress subset.

\paragraph{Cytometry data}
The cytometry data used for some of the examples were generated in a
cell-based screen probing for activating and inhibiting effects of
over-expression of unknown genes conducted at the German Cancer Research
Center Heidelberg by Dr. Dorit Arlt \cite{Arlt2005}. They comprise four
replicate 96 well microtiter plates containing cells transfected with
YFP-fused expression constructs. Cell proliferation was monitored though an
antibody-based BrdU assay and data was subsequently processed using the
package \Rpackage{prada} to obtain measures of inhibition and activation.

\paragraph{High density tiling array data}
\textit{Saccharomyces cerevisiae} was grown in rich culture and RNA was
isolated.  Then labeled cDNA was produced and hybridized to high-density 
tiling arrays designed by Dr. Lars Steinmetz from the European Molecular 
Biology Laboratory (EMBL) and manufactured by Affymetrix Corporation.  The
arrays cover both strands of the whole yeast genome with 25-mer
oligonuleotide probes, whose start positions tile in intervals of 8
bases.The measurements on unsynchronized cells were taken by Dr. Lior
David at the Stanford Genome Center (Figure~\ref{fig_tiling_dotsSeg}),
those on synchronized cells by Dr. Sandra Clauder-M\"unster at the
EMBL (Figure~\ref{fig_tiling_heatmap}).

%------------------------------------------------------------
\section{Methodology} 
%------------------------------------------------------------
Exploratory data analysis is an omnibus name for a diverse set of
computational and visualization methods that are employed to
investigate data in order to discover interesting patterns,
regularities or irregularities.  The goal is not to fit models, to
make estimates, or to test hypotheses, but rather to gain insight
into the structure of the data without imposing conditions upon them.
EDA often relies on graphical methods and many of the examples presented
here arise from the application of these principles.

Among the basic graphical principles proposed by \cite{Cleveland:1993}
and \cite{Cleveland:1994} is the importance of comparisons on a common
scale. Cleveland also notes that there are problems with
the visual comparison of curves, since the eye is drawn to areas where
the curves are close, but it is difficult to determine either the
vertical separation or the horizontal separation with any precision.
However, we are often more interested in accurate estimation of either 
the horizontal or the vertical distance between the curves.

In other settings, especially those related to linear modeling,
graphical methods have made good use of both models and residuals. It
is often of substantial interest to visualize the impact of model
assumptions and to also study deviations from those assumptions. Residuals
can be computed by comparing the observed data with the predictions made
using the hypothesized model. To date there has
been little use of residuals in the analysis of genomic data, even
when studying highly designed microarray experiments where
they are likely to be of substantial benefit.

%------------------------------------------------------------
\subsection{Plotting distributions}
\label{sec:plotdist}
%------------------------------------------------------------
Often one wants to compare the distributions of different populations,
or subsets, of the experimental data. For microarray experiments it is common
practice to compare the distributions of probe values for different
arrays while for flow cytometry data it is often of interest to compare
distributions of forward scatter, or side scatter between the wells in
a plate. Three commonly used visualization methods for comparing
distributions are boxplots, plots of the empirical distribution function and
plots of density estimates. Since they are all relatively easy to produce, it
seems prudent to examine all three for data that are to be analyzed. These 
methods are illustrated in Section~\ref{sec:distrsum}.

Boxplots are useful if the data have a roughly unimodal and symmetric
density. If that is not the case, then many important features of the data
will not be observed by comparing boxplots. Boxplots show how well the
medians align, whether spread, as measured by the IQR, is consistent
across the samples and the extent to which outliers exist, again
across samples. The comparison is on a common scale; for horizontal
boxplots, the $y$-axis and hence adhere to the principles proposed by 
Cleveland.

Plots of the empirical distribution function can be illuminating with
respect to shifts in the location of the distributions (some forms of
this are detected by boxplots, but not all) and to other anomalies
that effect the tails of the distribution. It is straightforward, if
potentially tedious, to locate the median and other quantiles. Direct
pairwise, or groupwise comparisons are less straightforward. A trained eye
can detect multimodality and other anomalies, but for these defects a
density plot will often yield a more direct answer. Despite these
defects, and the fact that they do not adhere to Cleveland's recommendation
their use is widespread and they are often valuable showing
estimated distributions that cross and other unusual patterns that
are not easily seen by the other two methods.

Density estimates are most revealing for the shape of the
distribution. Shape can be important, especially if the density plot
reveals a marked lack of symmetry or strong evidence of multimodality
since both of these can effect the sensitivity and specificity of
statistical routines applied to the data. As mentioned above, neither
of these two problems is easily detected using the other plots of the
distributions. Not detecting these problems can mislead the analyst
into thinking that they have carried out an appropriate analysis when,
in fact, they have not.

When plotting distributions and densities it is generally worth considering
whether a transformation of the data might yield a better scale
on which to carry out the comparisons. Often the data are first 
visualized on the scale in which they were obtained, but in many cases
any monotone transformation, such as the logarithm or a power
transformation, is equally plausible. Such transformations can be
applied without loss of information, but potentially with a strong
effect on the shape and moments of distributions. This can lead to
quite different perceptions of the data. An example is shown in
Figure~\ref{fig:visualization-scale}.  If one does not know the
underlying process and only sees the sample, the appropriate choice of
scale may not be obvious  and a prudent strategy is to examine
different transformation scales.

%------------------------------------------------------------------------------
% Figure visualization-scale: the importance of scale
%------------------------------------------------------------------------------
<<scaleSetSeed, echo=FALSE, results=hide>>=
set.seed(123)
@ 
%
<<scaleShow, results=hide, echo=FALSE>>=
y = 50+exp(c(rnorm(4000, mean=6, sd=1), rnorm(2000, mean=3, sd=0.5)))
@ 
%
<<scale1, echo=FALSE, results=hide, include=FALSE, width=3.6, height=3, fig=TRUE>>=
opar <- gpar(c("mar", "mgp"))
par(mar=c(4, 4, 0.5, 1), mgp=c(2.5,1,0))
plot(density(y, from=0, to=2000), lwd=2, col="blue", xlab="y", main="")
@ 
<<scale2, echo=FALSE, results=hide, include=FALSE, width=3.6, height=3, fig=TRUE>>=
par(mar=c(4, 4, 0.5, 1), mgp=c(2.5,1,0))
plot(density(log(y), from=4, to=12), lwd=2, col="blue", xlab="log(y)", main="")
par(opar)
@ 
%
\begin{figure}[tp]
\begin{center}
\begin{tabular}{lll}
\myhead{a}&\myhead{b}\\
\includegraphics[width=0.45\textwidth]{visualization-scale1}&
\includegraphics[width=0.45\textwidth]{visualization-scale2}
\end{tabular}
\end{center}
\caption{\label{fig:visualization-scale}%
  The impact of non-linear transformations on the shape of a distribution. The
  two panels show kernel density estimates 
  of a random sample from a mixture of two log-normal distributions (\emph{a}) 
  and of the logarithmically transformed values (\emph{b}).}
\end{figure}
%

%% RG: I am not sure I see that this example works for this paper.
%% It seems to be more about data analysis than about visualization, but
%% maybe I am missing the point. No doubt that transformations are
%% important for visualization, but I think this example doesn't really
%% work for me.
%%
%% FH&WH: We think this point is about visualization - the same data can be 
%% visualized differently, possibly leading to quite different perceptions 
%% of the distribution. We have tried to make the explanation clearer.

%--------------------------------------------------
\subsection{Color}
%--------------------------------------------------
The use of color is an essential ingredient of many visualization
methods. While the book containing this chapter is printed without color
we provide on-line complements through the Bioconductor web site with color
versions of the graphics. 

We encourage the appropriate use of color as it can greatly help to make
complex plots more readily interpretable.  Unfortunately color can also be
used to obfuscate the message.  Red-green color schemes, so popular in
bioinformatics, should be avoided since an appreciable proportion of the
audience is red-green color blind and hence unable to read the plot. Lighter
colors tend to make areas look larger than darker colors, thus colors of equal
luminance should be chosen for graphics with large filled areas
or where perception of area is important~\cite{IhakaColorPres}.

Following the results of Brewer, the \Rfunction{RColorBrewer} package 
offers three different types of color palettes; sequential, diverging and
qualitative. These palettes have variations that provide between 3 and
9 colors and then the \Rfunction{colorRampPalette} function can be used 
to provide any number of intermediate color values, given a set of
input colors. Sequential palettes are suitable for ordered values, that
progress from low to high values. Diverging palettes put equal emphasis
on mid-range values and extreme values. And qualitative palettes do not imply
magnitude differences and hence are suitable for encoding unordered data
such as race, or category.

There are also, often advantages to using well known palettes, such as
those for topographic color schemes, or terrain color schemes, as readers
will be familiar with them, and in some cases, their familiar encodings
can help readers to comprehend the plots.

There are many uses for color in visualization. Color is good at showing
connectivity or group membership. In many graphics, points from the same group
will be colored the same. Color can also be used to
highlight particular observations or samples.  Most points or graphical
objects are plotted in one color, and those to which particular attention
should be devoted are plotted in another, distinct color.  The heatmap in
Figure~\ref{fig:heatmap} is a combination of a two-dimensional image (where
the rows and columns identify objects) with a third continuous variable for
each specific row-column pair. The third variable is encoded using color so
these displays are often called \textit{false color displays}. A color scheme
capable of describing values on a common, ordered scale should be used.
Groupings, of the variables that constitute either the rows or the columns of
the image plot can be encoded using a colored bar.


%------------------------------------------------------------------------------
% Figure: Color schemes
%------------------------------------------------------------------------------
<<somecolors, echo=FALSE, results=hide>>=
library("colorspace")

plothcl = function(h, c, l, x0=0.5, y0=0.5, what="c", default.units="npc", ...) {
  switch(what,
         "c" = {
           stopifnot(length(l)==1)
           n = length(c)
         }, 
         "l" = {
           stopifnot(length(c)==1)
           n = length(l)
         }, 
         stop("Sapperlot"))
  
  cr = seq(0.1, 0.5, length=n+1)
  dr = 0.05/n

  for(j in 1:n) {
    r = c(cr[j]+dr, cr[j+1]-dr)
    for(i in 1:(length(h)-1)){
      phi=seq(h[i], h[i+1], by=1)/180*pi
      px = x0 + c(r[1]*cos(phi), r[2]*rev(cos(phi)))
      py = y0 + c(r[1]*sin(phi), r[2]*rev(sin(phi)))
      mycol = switch(what,
        "c" = hcl(h=mean(h[i+(0:1)]), c=c[j], l=l),
        "l" = hcl(h=mean(h[i+(0:1)]), c=c, l=l[j]))
      grid.polygon(px, py, gp=gpar(col=mycol, fill=mycol), 
                   default.units=default.units,...)
    }
  }
}
@ 
%
<<hcl-c, fig=TRUE, include=FALSE, width=3.6, height=3.6, results=hide, echo=FALSE>>=
plothcl(seq(0, 360, by=3), seq(5, 75, by=10), 75, what="c")
@ 
%
<<hcl-l, fig=TRUE, include=FALSE, width=3.6, height=3.6, results=hide, echo=FALSE>>=
plothcl(seq(0,360,by=3), 55, seq(20, 100, by=10), what="l")
@ 
%
\begin{figure}[tp]
\begin{center}
\begin{tabular}{lll}
\myhead{a}&\myhead{b}\\
\includegraphics[width=0.45\textwidth]{visualization-hcl-c}\hspace{2ex}&
\includegraphics[width=0.45\textwidth]{visualization-hcl-l}
\end{tabular}
\end{center}
\caption{\label{fig:hcl}Circles in HCL colorspace. 
  \emph{a}: circles in HCL space at constant $L=75$, with the angular
  coordinate $H$ varying from 0 to 360 and the radial coordinate $C=0, 10,
  \ldots, 60$.  \emph{b}: constant $C=50$, and $L=10, 20, \ldots, 90$.}
\end{figure}

While the space of light spectra is infinite-dimensional, the space of color
perception in humans is three-dimensional~\cite{Helmholtz}.  There are
different ways of parameterizing this space. Maybe the best known among
computer programmers is the RGB coordinate system, which uses three values in
$[0,1]$. These coordinates reflect the design of current color displays, which
use light sources in red, green, and blue primary colors, and they are
hardware-dependent.  There are many examples of visually unpleasant color
schemes derived from extreme points in the RGB unit cube
(Figure~\ref{fig:genomebrowser}).  The R function \Rfunction{hcl} uses three
coordinates \emph{hue} $H$, an angle in $[0, 360]$, \emph{chroma} $C$, and
\emph{lightness} $L$ as a value in $[0,100]$. Allowable values for $C$ depend
on certain constraints, but generally are between 0 and 255. HCL is designed
for area fills.  By keeping chroma and luminescence coordinates constant and
only varying hue, it is easy to produce color palettes that are harmonious,
avoiding irradiation illusions that make light colored areas look bigger than
dark ones (Figure~\ref{fig:hcl}).  Our attention also tends to get
drawn to loud colors and fixing the value of chroma makes the colors equally
attractive to our eyes.

There are a number of ways of choosing colors from a color
wheel. \emph{Triads} are three colors chosen equally spaced around
the color wheel; for example, $H=0, 120, 240$ gives red, green, and
blue.  \emph{Tetrads} are four equally spaced colors around the color
wheel, and some graphic artists describe the effect as "dynamic".
\emph{Warm colors} are a set of equally spaced colors close to yellow,
\emph{cool colors} a set of equally spaced colors close to blue.
\emph{Analogous color} sets contain colors from a small segment of the
color wheel, for example, yellow, orange and red, or green, cyan and
blue.  \emph{Complementary colors} are colors diametrically opposite
each other on the color wheel. A tetrad is two pairs of
complementaries.  \emph{Split complementaries} are three colors
consisting of a pair of complementaries, with one partner split
equally to each side, for example, $H=60, 240-30, 240+30$.  This is
useful to emphasize the difference between a pair of similar
categories and a third different one. A more thorough discussion is
provided in the references~\cite{mollon-95,IhakaColorPres}.

%--------------------------------------------------
\subsection{Two-dimensional layouts of data}
\label{sec:2Ddata}
%--------------------------------------------------
When inspecting data from different genomic experiments,
two-dimensional structures are often of great interest to us. For
microarrays, we want to inspect the intensities in their original
layout to look for systematic defects that could result from printing
or hybridizing samples to the arrays, such as Figure~\ref{fig:affyimage} for
Affymetrix arrays and Figure~\ref{fig_spatial} for cDNA arrays.

For either 96 well or 384 well microtitre plates, we again have substantial
interest in viewing the data in its original position. Many plates have
reagents handled using robotics with fluidics and integrated pipetting where
handling problems often result in spatial patterns such as stripes or
gradients in the two-dimensional view of the data. We have also noticed that
one may encounter edge-effects, where the wells in the outside edge of the
plate may behave differently (potentially drying out more rapidly, or heating
or cooling more rapidly etc.).

Heatmaps have not been much
used in statistics prior to their widespread use for viewing
microarray data. A heatmap is a two dimensional false-color image of
the data where the user has the option of rearranging either the
columns or the rows (independently) so that similar rows (or similar
columns) are adjacent. The reader is looking for rectangular regions of
relatively constant intensity. These indicate a subset of the samples and the
variables where there is relative homogeneity of signal which is distinct from
that of other samples for the same genes.

In most cases hierarchical clustering is used
to perform the rearrangement of rows and columns, and subsequently 
the resultant dendrograms are plotted on the sides. But there is no reason 
to prefer the reordering via hierarchical clustering over other methods for
reorganizing the rows and columns such as those
proposed in \cite{Hurley} which are implemented in the
\Rpackage{gclus} package available from CRAN.  Alternatively, good
results have been reported by simply ordering each axis,
independently, according to the values in the first principle
component.

%------------------------------------------------------------------------------------------
\section{Visualization of experimental data}
%------------------------------------------------------------------------------------------
\subsection{Spatial layout}
%------------------------------------------------------------------------------------------
In Figure~\ref{fig:affyimage} we see the false color image of an Affymetrix
chip. In this case, there appear to be some minor problems since there are
small cloudy patches in the lower right and left corners of the image. The
images in Figure~\ref{fig_spatial} show typical irregularities in the spatial
distribution of the probe intensities from several two-color spotted cDNA
microarrays. Again, the choice of appropriate scale is important
particularly when using false color images. 

%------------------------------------------------------------------------------
% Figure: Affy chip image
%------------------------------------------------------------------------------
<<affyimage, fig=TRUE, echo=FALSE, include=FALSE, results=hide>>=
 jpeg("affyimage.jpg", width=1500, height=1500)
   par(mar=c(0, 0, 0, 0))
   palette.gray <- c(rep(gray(0:10/10), times = seq(1, 41, by = 4)))
   image(CLLbatch[, 15], col = palette.gray, main="")
 dev.off()
@
%
\begin{figure}[tp]
\begin{center}
\includegraphics[width=.5\textwidth]{affyimage.jpg}
\end{center}
\caption{\label{fig:affyimage}
Grey-scale false color image of the probe fluorescence intensities measured 
from an Affymetrix chip. The dynamic range of the data is about 
$10^3$, and a logarithmic transformation has been used in the mapping to 
the color scheme.}
\end{figure}

%------------------------------------------------------------
% Figure:spatial layout of spotted cDNA arrays
%------------------------------------------------------------
\newlength{\wid}
\setlength{\wid}{0.14\textwidth}
\newlength{\hsp}
\setlength{\hsp}{0.01\textwidth}
\newlength{\cbw}
\setlength{\cbw}{0.05\textwidth}
\begin{figure}[tp] 
\begin{center}
\parbox[t]{\wid}{\myhead{a}\\\includegraphics[width=\wid, trim=0 0 0 -20, clip=TRUE]{fig_spatial_004_fgred_rank.pdf}\\}\hspace{\hsp}
\parbox[t]{\wid}{\myhead{b}\\\includegraphics[width=\wid, trim=0 0 0 -20, clip=TRUE]{fig_spatial_004_bgred_rank.pdf}\\}\hspace{\hsp}
\parbox[t]{\wid}{\myhead{c}\\\includegraphics[width=\wid, trim=0 0 0 -20, clip=TRUE]{fig_spatial_004_red_rank.pdf}\\}\hspace{\hsp}
\parbox[t]{\wid}{\myhead{d}\\\includegraphics[width=\wid, trim=0 0 0 -20, clip=TRUE]{fig_spatial_144_fggreen_rank.pdf}\\}\hspace{\hsp}
\parbox[t]{\wid}{\myhead{e}\\\includegraphics[width=\wid, trim=0 0 0 -20, clip=TRUE]{fig_spatial_079_fggreen_log.pdf}\\}\hspace{\hsp}
\parbox[t]{\wid}{\myhead{f}\\\includegraphics[width=\wid, trim=0 0 0 -20, clip=TRUE]{fig_spatial_079_fggreen_rank.pdf}\\}
\parbox[t]{\cbw}{\myhead{}\\\includegraphics[width=\cbw, trim=0 0 0 -20, clip=TRUE]{fig_spatial_colorbar.pdf}}
\end{center}  
\caption{\label{fig_spatial}%
False color representations of the spatial intensity distributions of
three different $64 \times 136$ spot cDNA microarrays from one
experimental series~\cite{Sultmann2005}.  The color scale is shown in
the panel on the right. 
\emph{a}: probe intensities in the red color channel,
\emph{b}: the corresponding local background estimates, 
\emph{c}: the result of subtracting \emph{b} from \emph{a}.  
In \emph{a} and \emph{b}, there is an artifactual
intensity gradient, which is mostly removed in \emph{c}. For visualization,
the color scale was chosen in each image to be proportional to the
ranks of the intensities.  
\emph{d}: for a second array, probe intensities in
the green color channel.  There is a rectangular region of low
intensity in the top left corner, corresponding to one print pin.
Apparently, there was a sporadic failure of the pin for this
particular array.  
Panels \emph{e} and \emph{f} show the probe intensities in the
green color channel from a third array.  The color scale was chosen
proportional to the logarithms of intensities in \emph{e} and proportional
to the ranks in \emph{f}.  Here, the latter provides better contrast.  The
bright blob in the lower right corner appears to be the result of being
touched by a finger. Interestingly, it appears only in the green color
channel, while the half moon shaped region in the upper left appears
both in the green and red channels (data from red color channel not
shown).}
\end{figure}


%------------------------------------------------------------
% Figure: plate plots
%------------------------------------------------------------
\subsubsection{Plate plots of microtitre plates}
The top panel of Figure~\ref{fig:plotPlate} shows a plate plot intended to
resemble the geometrical structure of a 96 well microtitre plate that can be
used to display arbitrary quantities of interest for individual wells. Most
applications in cell biology use microtitre plates, either for cell culture or
during measurement. In this example we plot the number of cells per well as it
was measured by flow cytometry. The consistently low number of cells around
the edges of the plate indicates a handling problem during cultivation. For
multifactorial data the wells on the plot can be subdivided into segments as
shown in Figure~\ref{fig:plotPlate} b. Each of the four segments represents
one replicate experiment and the false colors indicate activation (red) and
inhibition (blue) of cell proliferation. Regrettably, it is not possible to
show this in black and white and readers are referred to the on-line
complements for a colored version of this plot. While such data could just as
easily be represented in a square data image we have found that the
representation of wells as circles provides most biologist collaborators with
an instant frame of reference and they are readily able to understand and
interpret the data.
 
<<plotPlates, fig=TRUE, echo=FALSE, include=FALSE, results=hide>>=
sampleDir <- system.file("extdata", "map", package = "CompStatViz")
if( sampleDir == "" )
   stop("did not find phenoData directory")
mapk <- readCytoSet(path = sampleDir, phenoData = "plateIndex.txt")
nrCells <- csApply(mapk, nrow)
dim <- devDims(7.2)
pdf(file="ppcell.pdf", width=dim$width, height=dim$height)
plotPlate(nrCells, col = brewer.pal(9, "YlOrBr"), cex.lab=1.9,
          cex.legend=1.5)
dev.off()
@
%
<<plotPlate2, fig=TRUE, echo=FALSE, include=FALSE, results=hide>>=
ppmult <- function (data, ...){
  xpos <- ypos <- 0.5
  r = 0.45
  col <- c(...)
  data <- rep(1,length(col))
  rad <- c(0, cumsum(data)/sum(data) * 2)
  nredges <- 180
  for (i in 2:length(rad)) {
    phi <- seq(rad[i - 1] * pi, rad[i] * pi, len = ceiling(nredges *
                                               rad[i]))
    x <- c(xpos, r * cos(phi) + xpos, xpos)
    y <- c(ypos, r * sin(phi) + ypos, ypos)
    grid.polygon(x, y, gp = gpar(fill = col[i - 1]))
  }
}

makeCols <- function(z) {
  m2d <- function(x){
    nc <- ncol(x)
    res <- data.frame(I(x[,1])) 
    for(i in 2:nc)
      res <- cbind(res, I(x[,i]))
    return(res)
  }
  d <- dim(z)
  xrange <- c(-40,40)
  col <- brewer.pal(9, "RdBu")[9:1]
  col <- c(col[1:4], rep(col[5],2), col[6:9])
  nrcolors = 256
  thepalette = colorRampPalette(col)(nrcolors)
  res = round((z - xrange[1])/diff(xrange) * (nrcolors -
    1)) + 1
  res[res > nrcolors] = nrcolors
  res[res < 1] = 1
  cols <- thepalette[res]
  cols[is.na(cols)] <- "white"
  dim(cols) <- d
  cols <- m2d(cols)
  colnames(cols) <- paste("col", 1:ncol(cols), sep="")
  return(cols)
}

load(system.file("extdata", "ppcomp.rda", package = "CompStatViz"))
pdf(file="ppcomp.pdf", width=dim$width, height=dim$height)
plotPlate(ppcomp, gridFun="ppmult", funArgs=makeCols(ppcomp),
          cex.lab=1.9)
vp <- viewport(width = 0.1, x = 0.88, just = "left")
pushViewport(vp)
col <- brewer.pal(9, "RdBu")[9:1]
col <- c(col[1:4], rep(col[5],2), col[6:9])
prada:::.drawLegend(col=col, xrange=range(ppcomp, na.rm=TRUE), cex.legend=1.5,
                    cex.desc=1.7)
popViewport()
dev.off()
@
% 
\begin{figure}[tp]
\begin{center}
\begin{tabular}{lll}
\myhead{a}\\
\includegraphics[width=.75\textwidth, trim=0 0 0 40, clip=TRUE]{ppcell.pdf}\\
\myhead{b}\\
\includegraphics[width=.75\textwidth, trim=0 30 0 37, clip=TRUE]{ppcomp.pdf}
\end{tabular}
\end{center}
\caption{\label{fig:plotPlate}
  \emph{a}: plate plot showing number of cells for each well of a 96 well
  microtitre plate. Cell numbers at the edges of the plate seem to be
  consistently low, indicating a handling problem. \emph{b}: plate plot of
  analysis results from four replicate experiments probing for activation
  (red) and inhibition (blue) of cell proliferation (see on-line complements
  for a colored version). Reproducibility between experiments seems to be
  high.}
\end{figure}

\subsubsection{Affymetrix probe set intensities}
On an Affymetrix array multiple probes, referred to as a probe set, are used
to interrogate a particular mRNA. The number of probes in a probe set depends
on the microarray being used. A rather interesting observation is the fact
that there is a great deal of variation in these probes, given that they are
meant to be measuring the same quantity -- the abundance of the target mRNA.
In part the variation is due to the difference in GC content as will be
demonstrated in Figure~\ref{fig:gcdistributions}, but there are also
additional sequence features, which are currently not well understood, that
significantly contribute to the effect.  Figure~\ref{fig:affyprobe} a and b
provides two plots of these data, one with the probes represented on the
$x$-axis and the other with arrays represented on the $x$-axis. Since the data
are essentially three dimensional it is easy to produce a false color image
map, Figure~\ref{fig:affyprobe} c.

In these various plots we can see how the values from the different probes 
vary in a correlated manner across arrays, however with different baselines. 
This observation was the starting point for the model-based analysis of 
Affymetrix probe set intensities that led to a dramatic improvement in 
the sensitivity of the technology~\cite{LiWong2000,Irizarry2003}.
%
%------------------------------------------------------------
% Figure: Affy probe sets and array comparison
%------------------------------------------------------------
<<affyprobe1, fig=TRUE, echo=FALSE, include=FALSE, width=3.2, height=3.2>>=
par(mar=c(3.5, 3.5, 0.9, 1), mgp=c(2.5,1,0))
#mycol  = hcl(seq(-30, 90, len=16), 55, 75) #warm colors
mycol <-  colorRampPalette(brewer.pal(9, "Reds")[3:7])(16)
matplot(pm(CLLbatch, "1001_at"), type = "l", xlab = "Probe No.",
        ylab = "PM Probe intensity", log="y", col=mycol, lwd=2)
@
%
<<affyprobe2, fig=TRUE, echo=FALSE, include =FALSE, width=3.2, height=3.2, results=hide>>=
par(mar=c(3.5, 3.5, 0.9, 1), mgp=c(2.5,1,0))
#mycol  = hcl(seq(150, 270, len=length(CLLbatch)), 55, 75) #cool colors
mycol <-  colorRampPalette(brewer.pal(9, "Blues")[3:7])(length(CLLbatch))
matplot(t(pm(CLLbatch, "1001_at"))[,16:1], type = "l", col=mycol, lwd=2,
        xlab = "Array No.", ylab = "PM Probe intensity", log="y")
par(opar)
@
%
<<affyprobe3, fig=TRUE, echo=FALSE, include =FALSE, width=4.7, height=4.7, results=hide>>=
mycol  = rev(brewer.pal(9, "PuBuGn"))
dcols = brewer.pal(8, "Greys")[ifelse(CLL.exprs$Disease == "stable", 3, 6)]
heatmap(log(pm(CLLbatch, "1001_at")), scale="none", Rowv=NA, col=mycol,
keep.dendro=TRUE, ColSideColors=dcols)
@ 
%
\begin{figure}[tp]
\begin{center}
\begin{tabular}{lll}
\myhead{a}&\myhead{b}\\
\includegraphics[width=.45\textwidth]{visualization-affyprobe1}\hspace{8mm}&
\includegraphics[width=.45\textwidth]{visualization-affyprobe2}\\
\end{tabular}
\begin{tabular}{lll}
\myhead{c}\\
\includegraphics[width=.8\textwidth, trim=0 5 0 65, clip=TRUE]{visualization-affyprobe3}
\end{tabular}
\end{center}
\caption{\label{fig:affyprobe}%
  Plotted along the $y$--axis are probe intensities from the CLL data for the
  probe set \texttt{1001\_at}. The probe set contains 16 probes and is
  specific for the receptor tyrosine kinase TIE.  \emph{a}: plotted along the
  $x$--axis are the 16 probes, and each line corresponds to one of the 24
  microarrays in the dataset.  \emph{b}: plotted along the $x$--axis are the
  arrays, each line corresponds to a different probe. \emph{c}: false color
  image map of the intensities. Rows: the 16 probes in the dataset. Columns:
  the \Sexpr{ncol(exprs(CLLbatch))}
  microarrays. An additional categorical covariate for the microarrays, 
  the disease type, is indicated by the grey-scale color bar on top.}
\end{figure}
%
%------------------------------------------------------------------------------------------
\subsection{Distribution summaries}
\label{sec:distrsum}
%------------------------------------------------------------------------------------------
For a high-throughput experiment that measures a certain property
across a large set of reagents, we expect the result to depend on the
biological properties of the reagents, but not on the particular
instance of experimental equipment in which the reagents were
manipulated. For example, a cDNA microarray may be produced from a
library of thousands of cDNA molecules, each specific for a certain
gene, which are produced and stored in 384 well microtitre trays and
deposited on the microarray using a print head with 16 pins.  We
expect that there should not be any reason for the distribution of
resulting spot intensities to be different for the different print
pins, or for the different trays. Hence, examining both boxplots and
empirical distribution functions of spot intensities by print pin and
tray is a commonly employed procedure for the quality assessment of
spotted cDNA arrays.  Industrially manufactured arrays such as those
made by Affymetrix, are usually not subject to these sorts of
problems, but other effects can be of interest. One example is the
dependency of the measured intensities on the GC-content of the
microarray probes, that is, the fraction of cytosines and guanines
among the nucleotides that make up each 25-mer probe on the array
(Figure~\ref{fig:gcdistributions}). Cytosin and guanin are able to
form three hydrogen bonds while adenine (A) and thymine (T) only form
two. This leads to more stable hybridization bindings, and
subsequently to higher intensities measured on the array, regardless
of the abundance of target molecules.

%------------------------------------------------------------------------------
% Figures visualization-gcboxplot, visualization-gcdensity, 
%   visualization-gcecdf
%------------------------------------------------------------------------------
<<gccalc, echo=FALSE, results=hide>>=
baseCt = basecontent(hgu95av2probe$sequence)
gcCt   = ordered(baseCt[, "C"]+baseCt[, "G"])

## make sure the levels are ascending numbers
stopifnot(all(diff(as.numeric(levels(gcCt)))>=1))

#mycol  = hcl(seq(0, 360, len=nlevels(gcCt)), 55, 75)
mycol <-  colorRampPalette(brewer.pal(9, "GnBu"))(nlevels(gcCt))
## find the 10 most popular levels
tab = table(gcCt)
ord = sort(order(tab, decreasing=TRUE)[1:10])
stopifnot(all(diff(ord)==1))
datsel  = (as.character(gcCt) %in% names(tab)[ord])
gcCtsel = ordered(gcCt[datsel])
colsel = mycol[sort(ord)]

iab = get("xy2i", "package:hgu95av2cdf")(hgu95av2probe$x, hgu95av2probe$y)
meanint    = rowMeans(exprs(CLLbatch)[iab, ])
meanlogint = rowMeans(log2(exprs(CLLbatch)[iab, ]))
exlab = expression(log[2]~intensity)
@ 
%
<<gcboxplot, echo=FALSE, results=hide, include=FALSE, width=6, height=2.6, fig=TRUE>>=
par(mar=c(4, 4, 0.5, 1), mgp=c(2.5,1,0))
boxplot(meanlogint ~ gcCt, 
  col=mycol, outline=FALSE,
  xlab="Number of G and C", ylab=exlab)
@ 
%
<<gcecdf, echo=FALSE, results=hide, include=FALSE, width=6, height=2.6, fig=TRUE>>=
par(mar=c(4, 4, 0.5, 1), mgp=c(2.5,1,0))
multiecdf(meanlogint[datsel] ~ gcCtsel, xlim=c(6, 11), xlab=exlab, ylab="ECDF", main="", col=colsel, lwd=2)
par(opar)
@ 
%
<<gcdensity, echo=FALSE, results=hide, include=FALSE, width=6, height=2.6, fig=TRUE>>=
par(mar=c(4, 4, 0.5, 1), mgp=c(2.5,1,0))
multidensity(meanlogint[datsel] ~ gcCtsel, xlim=c(6, 11), xlab=exlab, main="", col=colsel, lwd=2)
@  
%
\begin{figure}[tp]
\begin{center}
\begin{tabular}{lll}
\myhead{a}\\
\includegraphics[width=0.75\textwidth, trim=0 0 0 7, clip=TRUE]{visualization-gcboxplot}\\
\myhead{b}\\
\includegraphics[width=0.75\textwidth, trim=0 0 0 7, clip=TRUE]{visualization-gcecdf}\\
\myhead{c}\\
\includegraphics[width=0.75\textwidth, trim=0 0 0 7, clip=TRUE]{visualization-gcdensity}
\end{tabular}
\end{center}
\caption{Distributions of the $\log_2$--intensities from the CLL
  dataset (see Section~\ref{sec:Data}) grouped by the number of
  cytosines (C) and guanines (G) among the 25 nucleotides in each
  probe. Box plots (\emph{a}), empirical cumulative distribution
  functions (ECDF, \emph{b}) and kernel density estimates
  (\emph{c}). Box and line colors in the three panels correspond to
  the same groups. The top plot shows all groups from 1 to 23, the
  middle and lower plots show the ten most populated groups from
  \Sexpr{names(tab)[ord[1]]} to \Sexpr{names(tab)[ord[length(ord)]]}.
  Cytosine and guanine are able to form three hydrogen bonds, while
  adenine (A) and thymine (T) only form two, hence oligonucleotides
  with a higher proportion of C and G can form more stable
  hybridization bindings. The plots show how this results in higher
  intensities measured on the array, regardless of the abundance of
  target molecules.} % caption
\label{fig:gcdistributions} 
\end{figure}

%---------------------------------------------------------
\subsection{Scatterplots and 2-dimensional density plots}
%---------------------------------------------------------
Scatterplots are a powerful tool for the visualization of data from two
variables given the number of observations is relatively small. For
scatterplots of high observation density it is often difficult to get a good
impression of the distribution underlying the data because the mass of points
forms a featureless dark area (Figure \ref{fig:densScatter} a). This problem
can be addressed by dividing the data into a two-dimensional histogram of
hexagonal bins \cite{Carr} and plotting these bins using false-color coding
(Figure \ref{fig:densScatter} b). An alternative approach is provided by
plotting the local densities either as false-color images (Figure
\ref{fig:densScatter} c) or each observation individually coloring the points
with respect to their density (Figure \ref{fig:densScatter}d).


%------------------------------------------------------------
% Figure: High density scatterplots
%------------------------------------------------------------
<<densPlots, fig=TRUE, include=FALSE, echo=FALSE, results=hide>>=
mapkc <- combineFrames(mapk, rep(1, 96))
cramp <- colorRampPalette(brewer.pal(9, "Blues")[-(1:3)])
vals <- exprs(mapkc[[1]])
sel <- vals[,2]<1023 & vals[,1]>0 & vals[2]>0 

jpeg(file="dens1.jpg", width=1000, height=1000)
par(mar=c(5, 4.5, 0.5, 1))
plot(vals[sel, 1:2], pch=20, cex=0.5, xlab="FSC", ylab="SSC",
     cex.lab=3, cex.axis=3)
dev.off()

pdf(file="dens2.pdf", width=7, height=7)
hb <- hexbin(vals[sel, 1:2], xbin=20)
plot(hb, xlab="", ylab="", colramp=cramp, lcex=1.3)
dev.off()

jpeg(file="dens3.jpg", width=1000, height=1000)
par(mar=c(5, 4.5, 0.5, 1))
smoothScatter(vals[sel, 1:2], xlab="FSC", ylab="SSC",
              nrpoints=500, cex.lab=3, cex.axis=3)
dev.off()

jpeg(file="dens4.jpg", width=1000, height=1000)
par(mar=c(5, 4.5, 0.5, 1))
plot(vals[sel, 1:2], pch=20, cex=0.5, xlab="FSC", ylab="SSC",
     col=densCols(vals[sel, 1:2]), cex.lab=3, cex.axis=3)
dev.off()
@ 
%
\begin{figure}[tp]
\begin{center}
\begin{tabular}{lll}
\myhead{a}&\myhead{b}\\
\includegraphics[width=.45\textwidth]{dens1.jpg}&
\includegraphics[width=.45\textwidth]{dens2.pdf}\\
\myhead{c}&\myhead{d}\\
\includegraphics[width=.45\textwidth]{dens3.jpg}&
\includegraphics[width=.45\textwidth]{dens4.jpg}
\end{tabular}
\end{center}
\caption{\label{fig:densScatter}
  Four different visualizations of a scatterplot of flow cytometry data
  (forward light scatter versus side light scatter). \emph{a}: the usual
  scatterplot. Because of the large number of points, it is a rather
  featureless black blot. \emph{b}: the result of a hexagon binning procedure.
  The color code at each hexagon represents the number of data points that it
  contains. \emph{c}: color representation of smooth point densities
  calculated from the data using a kernel density estimator.  In the sparse
  regions of the density, the plot is augmented by black dots that represent
  individual data points.  In the denser regions, these are omitted. \emph{d}:
  usual scatterplot with points colored according to the local density.}
\end{figure}

%--------------------------------------------------
\subsection{Clustering}
\label{sec:Clustering}
%--------------------------------------------------
Clustering, sometimes also referred to as unsupervised machine
learning, is a widely used method for finding groups in data. For
a clustering problem the setting is generally that there is some 
number of objects, and for each of those objects a set of variables
have been measured. The
notion of clustering is to group together objects that are similar to
each other, for the variables that were measured (or the subset of
those variables that are deemed to be important). To carry out such an
operation the user must carefully select a distance measure that will
be used to combine the different variables. In many cases the
variables were measured on different scales, possibly in different
units, and this needs to be considered. For many genomic data sets
many more variables are measured than can easily, or sensibly, be
used. Some objects group on one set of variables, while other samples
group on other sets of variables and hence, one might say that the
problem is itself ill-posed.

Perhaps the most widely used clustering algorithm is agglomerative
hierarchical clustering. This algorithm is easy to implement, and
somewhat easy to interpret, but the resulting dendrogram is less easy to
deal with. It is essential to note that given any data set, regardless
of the existence of real clusters in the data one can perform
hierarchical clustering and often the resulting dendrogram will appear
to indicate that there are groups in the data. Dendrograms
are not visualization methods. Visualization is the process of
revealing structure in data, hierarchical clustering (and the
resulting dendrogram) impose structure and hence the result is often of
little practical use.

The silhouette plot was proposed in \cite{Kaufman:1990} and is easily
applied to the output of any clustering algorithm. For each observation
a new quantity is computed. That quantity is related to the relative
difference between the average distance between the observation and all other
members of the cluster it is assigned to, and the average distance between 
the observation and the members of another cluster (for each observation
the \textit{other cluster} is the cluster with the smallest average distance
that the observation was not assigned to). This quantity is then
displayed using horizontal bars, grouped by cluster membership, as seen in
Figure~\ref{fig:sl1}. For any observation the bar is positive if the point is 
closer to the cluster it was assigned to and the bar is negative if the 
observation is closer to some other cluster. Note that this ensures that 
comparisons between observations are carried out on a common scale, in
accordance with good visualization principles.  

Using the CLL data and the genes selected to discern between stable
and progressive disease the samples were clustered using the \Rfunction{pam} 
function in the \Rpackage{cluster} package.
In Figure~\ref{fig:sl1} we present a silhouette plot of the clustering
information. In this plot, each sample is represented by a horizontal bar. 
The length (and direction) of the bar is related to the average distance from 
the sample and the other members of the group it is in, versus the 
smallest average distance from the sample, to all members of another cluster.
Thus, bars that are large (close to 1) indicate observations that are well
clustered, while bars that are negative (eg. CLL8) indicate observations
that may be in the wrong cluster.

%------------------------------------------------------------
% Figure: silhouette plots
%------------------------------------------------------------
<<clusterEx, echo=FALSE, results=hide>>=
require(cluster)
 pm1 = pam(t(eSdis), 2)
 sl1 = silhouette(pm1)
@
%
<<sil1, fig=TRUE, echo=FALSE, include=FALSE, results=hide, width=4.7, height=4.7>>=
 plot(sl1, main="Silhouette plot of CLL data",
     col="lightblue")
@
%
\begin{figure}[tp]
\begin{center}
\includegraphics[width=.66 \textwidth]{visualization-sil1}
\end{center}
\caption{A silhouette plot based on clustering the CLL samples into
two groups based on genes selected to differentiate those with
stable disease from those with progressive disease. \label{fig:sl1}}
\end{figure}

%%% --- Biclustering:
There is interest in clustering itself and methods that are referred
to as \textit{biclustering}, a procedure originally proposed in
\cite{Hartigan} for simultaneously clustering samples and variables to
find interesting subgroups. Biclustering turns out to be a difficult
problem to solve in general; some heuristics for addressing it have
been discussed in Section~\ref{sec:2Ddata}.

%%% --- projections, mds:
Two dimensional projections of data are useful since they can be
easily communicated on paper or screen, and we find it much easier to
interpret than higher dimensional representations.  Often used tools
are principal component reductions and multi-dimensional scaling (MDS).
For an in depth discussion of MDS and its many variations we recommend
consulting \cite{Cox:2001}.

%------------------------------------------------------------
% Figure: mds
%------------------------------------------------------------
<<mds1, fig=TRUE, echo=FALSE, include=FALSE, results=hide, width=3.2, height=3.2>>=
par(mar=c(2, 3.5, 2, 1), mgp=c(2.5,1,0))
DisCols = list(
  strong = brewer.pal(9, "Paired")[ifelse(CLL.dis$Disease == "stable", 4, 8)],
  light  = brewer.pal(9, "Paired")[ifelse(CLL.dis$Disease == "stable", 3, 7)])
DisPch = ifelse(CLL.dis$Disease == "stable", 16, 17)
dtt = dist(t(eSdis))
mdstt = cmdscale(dtt, 2)
plot(mdstt[,1], mdstt[,2], pch=DisPch, col=DisCols$strong, xlab="", ylab="")
@ 
%
<<mds2, fig=TRUE, echo=FALSE, include=FALSE, results=hide, width=3.2, height=3.2>>=
par(mar=c(2, 3.5, 2, 1), mgp=c(2.5,1,0))
AG = t(eS[,goodCell])
dAG = dist(AG)
mdsAG = cmdscale(dAG, 2)
plot(mdsAG[,1], mdsAG[,2], pch=DisPch, col=DisCols$strong, xlab="", ylab="")
par(opar)
@
%
\begin{figure}[tp]
\begin{center}
\begin{tabular}{lll}
\myhead{a}&\myhead{b}\\
\includegraphics[width=.45\textwidth, trim=0 0 0 20, clip=TRUE]{visualization-mds1}&
\includegraphics[width=.45\textwidth, trim=0 0 0 20, clip=TRUE]{visualization-mds2}
\end{tabular}
\end{center}
\caption{Two different MDS views of the arrays in the CLL dataset. 
  \mbox{\emph{a}: feature} selection that prefers genes that separate the two disease groups. 
  \mbox{\emph{b}: features} selected on the basis of their variability.
  \label{fig:mds} }
\end{figure}
%
Here we compare the two dimensional views that can be obtained by 
applying classical MDS to the CLL data. In Figure~\ref{fig:mds} 
two different two dimensional MDS reductions are shown. They are 
remarkably different. The left panel clearly indicates two groups, but this 
is most likely due to the fact that it is based on genes that were selected to 
emphasize the difference between the two disease groups. The right panel, 
was constructed using genes that showed high variability across arrays rather
than those that can separate the two disease groups. In the right
panel we do not see evidence for two groups, but rather that there is 
one peculiar microarray and some effort should be expended to identify that
array and the causes of the behavior shown in that panel.

Unfortunately, dimension reduction methods such as MDS and principal components
are often misused. It is always possible to compute and visualize the
first two, or three components but these need not be meaningful in any way.
There are two common problems that can arise. One being that the first two
components do not describe the bulk of the variability in the data and that
in reality one needs more components to provide a reasonable description of
the data. It is prudent and important to compute, and report, the proportion 
of the variability explained by the components that are visually displayed.
A second major problem is that the manner in which the data were collected, 
or assembled, and processed has a profound effect on the variability in the
data and hence on visualizations of it. As we demonstrated in 
Figure~\ref{fig:mds} the left panel indicates two groups, while the right
panel does not.

%------------------------------------------------------------
%   scree plot:
We also emphasize that some effort should be expended to determine the
number of dimensions needed to explain the data. In
Figure~\ref{fig:screeplot} we compare the MDS goodness of fit
statistics for different numbers of dimensions, for both those genes
selected to be to differentially expressed between the disease groups
and those genes selected because they show large overall variation
across samples.  We see that low-dimensional embedding generally
provide a somewhat better fit for the disease selected genes, but
there is no clear break, in either graph, between two and three
dimensions. Thus, there is little evidence that a two dimensional
projection is particularly adequate for either data set.
%
<<screeCalc,echo=FALSE, results=hide>>=
res = matrix(as.numeric(NA), nrow=12, ncol=2)
colnames(res) = c("Disease", "All genes")

for(d in 1:nrow(res)){
  res[d,1] = cmdscale(dtt, d, x.ret=T)$GOF[1]
  res[d,2] = cmdscale(dAG, d, x.ret=T)$GOF[1]
}

@ 
<<screeplot, fig=TRUE, echo=FALSE, include=FALSE, results=hide, width=3.2, height=3.2>>=
screeCol=brewer.pal(9, "Paired")[c(4,8)]
par(mar=c(2, 3.5, 2.5, 1), mgp=c(2.5,1,0))
matplot(res, lty=1, pch=c(16,17), type="b", col=screeCol, xlab="d", ylab="GOF")
legend(x=nrow(res), y=0.6, colnames(res), pch=c(16,17), lty=1, col=screeCol, xjust=1)
@ 
\begin{figure}[tp]
\begin{center}
\includegraphics[width=.45\textwidth, trim=0 0 0 20, clip=TRUE]{visualization-screeplot}
\end{center}
\caption{Goodness of fit statistic from MDS, for different numbers of
components, comparing the MDS fit for genes selected for disease
status to the GOF for those selected for variability across samples.}
\label{fig:screeplot} 
\end{figure}

%------------------------------------------------------------------------------------------
\subsection{Heatmaps}
\label{sec:Heatmaps}
%------------------------------------------------------------------------------------------
In Figure~\ref{fig:heatmap} we see a heatmap showing the expression
estimates of genes selected according to the $p$-value in a $t$-test
comparing those with stable disease to those with progressive
disease. The top bar contains one small block for each sample, those
samples that correspond to the stable disease phenotype have a dark
colored block, those with progressive disease a light colored
block. It is not surprising that the two groups are well separated
(all the dark blocks are to the right), since that is how genes were
selected.

%------------------------------------------------------------
% Figure: Heatmap original data
%------------------------------------------------------------
<<heatmap, fig=TRUE, echo=FALSE, include=FALSE, results=hide>>=
jpeg("heatmap.jpg", width=700, height=700)
DisColsGray <- brewer.pal(8, "Greys")[ifelse(CLL.dis$Disease == "stable", 3, 6)]

## Reviewer question:
## Making one flip of the dendogram would ensure a full separation, why has that not been done?
## WH 24.3.06:

if(!TRUE) {
  ## the "Colv" or "reorderfun" argument should help doing this, but I have tried for
  ##  around 1h and give up now, without success
 wts =  as.integer(CLL.dis$Disease)
 names(wts) = CLL.dis$SampleID
 wts["CLL9"] = 0
 heatmap(eSdis, ColSideColors=DisColsGray, col=rev(brewer.pal(9, "RdBu")), 
         Colv=wts)
} else {
  ## damn it, instead we are cheating
  sel = colnames(eSdis)!="CLL9"
  heatmap(eSdis[, sel], ColSideColors=DisColsGray[sel], 
    col=rev(brewer.pal(9, "RdBu")))  
}

dev.off()
@
%
\begin{figure}[tp]
\begin{center}
\includegraphics[width=.75\textwidth, trim=0 25 0 0, clip=TRUE]{heatmap.jpg}
\end{center}
\caption{A heatmap representation of the CLL data. Genes were selected
using a $t$-test comparing those with a progressive disease and those
with a stable disease. Colors indicate low (blue) and high (red)
values of the expression estimates. \label{fig:heatmap} }
\end{figure}




\subsection{Diagnostics}

The RNA degradation plot, Figure~\ref{fig:RNAdeg}, indicates that there
is in fact one unusual array, CLL1.  These plots show a relationship
between probe position and intensity. In general, the relationship is
non-constant, and increasing in the 5' to 3' direction. The shape of
the curve is generally not of interest, but rather whether there are
different curves for different samples, since if this occurs it is
likely that the computed expression values will not be directly
comparable.  In this case, one might be tempted to think that perhaps
the handling of the RNA for the first array was potentially different
from the handling for other arrays and hence that the exclusion of
this array from subsequent analyses might be a good approach.


%------------------------------------------------------------
% Figure: RNA digestion plot
%------------------------------------------------------------
<<affyRNAdeg, echo=FALSE>>=
RNAdeg <- cache("RNAdeg", AffyRNAdeg(CLLbatch))
@
<<affyRNAdegplot, fig=TRUE, echo=FALSE, results=hide, include=FALSE, width=4, height=4>>=
##note the odd handling of the col argument 
par(mar=c(4, 4, 1, 0.5), mgp=c(3,1,0))
plotAffyRNAdeg(RNAdeg, col=rep("slategrey", length(RNAdeg$sample.names)))
par(opar)
@

\begin{figure}[tp]
\begin{center}
\includegraphics[width=.5\textwidth]{visualization-affyRNAdegplot}
\end{center}
\caption{RNA degradation plot for the 24 CLL microarrays. \label{fig:RNAdeg}
}
\end{figure}

The Bioconductor package \Rpackage{affyPLM} provides a number of more
detailed computational methods for performing diagnostics on
Affymetrix microarrays. It fits a model to the dataset and provides
methods for plotting false color images of the fitted parameters, the
residuals, and a number of quality metrics. In
Figure~\ref{fig:plmimages}, we present the images for array
\texttt{CLL6}. More striking examples can be found in Chapter 3 of
\cite{biocbook2005}.

%------------------------------------------------------------
% Figure: affyPLM plots
%------------------------------------------------------------
<<affyPLM, echo=FALSE, results=hide>>=
CLL.plm <- cache("CLL.plm", fitPLM(CLLbatch))
@
%
<<plmimages, fig=TRUE, include=FALSE, echo=FALSE, results=hide>>=
jpeg(file="plmimages1.jpg", width=1000, height=1000)
par(mar=rep(0.5,4))
image(CLLbatch[, 21], col = palette.gray, main="")
dev.off()

jpeg(file="plmimages2.jpg", width=1000, height=1000)
par(mar=rep(0.5,4))
image(CLL.plm, type = "weights", which = 21, main="")
dev.off()

jpeg(file="plmimages3.jpg", width=1000, height=1000)
par(mar=rep(0.5,4))
image(CLL.plm, type = "resids", which = 21, main="")
dev.off()

jpeg(file="plmimages4.jpg", width=1000, height=1000)
par(mar=rep(0.5,4))
image(CLL.plm, type = "sign.resids", which = 21, main="")
dev.off()
@ 
%
\begin{figure}[tp]
\begin{center}
\begin{tabular}{lll}
\myhead{a}&\myhead{b}\\
\includegraphics[width=.45\textwidth]{plmimages1.jpg}&
\includegraphics[width=.45\textwidth]{plmimages2.jpg}\\
\myhead{c}&\myhead{d}\\
\includegraphics[width=.45\textwidth]{plmimages3.jpg}&
\includegraphics[width=.45\textwidth]{plmimages4.jpg}\\
\end{tabular}
\end{center}
\caption{Image plots for Array CLL 6. \emph{a}: raw data.
  \emph{b}: weights used in fitting the model, green values correspond to low
  weights, light values to high weights. \emph{c}: residuals \emph{d}: signs of
  the residuals; red corresponds to positive residuals, blue to negative
  residuals (see on-line complements for a colored version).
  \label{fig:plmimages} }
\end{figure}
%
Other quality assessments can be made, and often they lead us back to the
sorts of problems mentioned in Section~\ref{sec:plotdist} of plotting
distributions. For example, the relative log expression (RLE) values are
computed for each probeset on an array, as the log of the expression value on
that array to the median expression value for that probeset across all arrays
\cite{biocbook2005}. Assuming that most genes are not changing in expression
across arrays means most RLE values will be near 0. Comparing per array
boxplots indicates arrays where there is potentially a problem.  For the CLL
data RLE is plotted in the left frame of Figure~\ref{fig:plmimages2}, where
only the array labeled 11 seems odd.  Another quality measure is the
normalized unscaled standard errors (NUSE). To compute the NUSE the standard
error estimates obtained for each gene on each array are standardized across
arrays so that the median standard error for each gene is one across all
arrays \cite{biocbook2005}.  Any array with elevated NUSE relative to the
other arrays is often of lower quality. Again, we have a distribution of
numbers, per array and boxplots can be used to display these. In
Figure~\ref{fig:plmimages2} we plot the NUSE values for the CLL arrays. We see
that there are two such arrays, the one numbered 1 (CLL10) and the one
numbered 11 (CLL19).

%------------------------------------------------------------
% Figure: affyPLM RLE and NUSE
%------------------------------------------------------------
<<plmRLE, fig=TRUE, echo=FALSE, width=3.2, height=3.2, include=FALSE, results=hide>>=
par(mar=c(2, 2, 0.5, 0.5), mgp=c(2.5,1,0))
Mbox(CLL.plm, ylim = c(-1, 1), names = NULL, col="lightblue",
whisklty=0, staplelty=0)
@
%
<<plmNUSE, fig=TRUE, echo=FALSE, width=3.2, height=3.2, results=hide, include=FALSE>>=
par(mar=c(2, 2, 0.5, 0.5), mgp=c(2.5,1,0))
boxplot(CLL.plm, ylim = c(0.95, 1.5), names = NULL,
        outline = FALSE, col="lightblue")
par(opar)
@
%
\begin{figure}[tp]
\begin{center}
\begin{tabular}{lll}
\myhead{a}&\myhead{b}\\
\includegraphics[width=.45\textwidth]{visualization-plmRLE}&
\includegraphics[width=.45\textwidth]{visualization-plmNUSE}
\end{tabular}
\end{center}
\caption{
Interquartile ranges of RLE (\emph{a}) and box-and-whiskers plots of 
NUSE values (\emph{b}) for the CLL data.}
\label{fig:plmimages2}
\end{figure}


%------------------------------------------------------------------------------
\section{Plotting in genomic coordinates}
%------------------------------------------------------------------------------
Many biopolymers have a linear structure, and many (although certainly not
all) of their properties can be viewed and understood as features
arranged along a linear coordinate.
In this section, we will discuss two uses of visualization along the
sequence of nucleotides in a chromosome. In
Section~\ref{sec:highdenstiling}, we map transcript
abundance to chromosomal location. A reasonable assumption
is that the true abundance should be either piecewise continuous
or piecewise constant over loci and noise can be reduced by
applying smoothing procedures that make use of this assumption.
Furthermore, ordering by locus can provide a more
appropriate context for interpretation of the data. In
Section~\ref{sec:genbrowser}, we look at the integration and
presentation of large amounts of public sequence data and metadata in
so-called genome browsers.

%------------------------------------------------------------------------------
\subsection{Along-chromosome plots of high-density tiling array data}
\label{sec:highdenstiling}
%------------------------------------------------------------------------------
Along-chromosome plots of microarray data measuring the abundance of
RNA transcripts are shown in Figures~\ref{fig_tiling_dotsSeg} and
\ref{fig_tiling_heatmap}. Figure~\ref{fig_tiling_dotsSeg} shows
the data from one condition where the data are essentially
two-dimensional: at each genomic coordinate, an intensity measurement
quantifies the amount of target molecules transcribed from that site
through a real number. Figure~\ref{fig_tiling_heatmap} is a
generalization to situations where we have an additional dimension, in
this case, time. The two spatial dimensions of the plot area are now
used for genomic coordinate and time, respectively, while the
intensity is coded through a false color scheme. The plots were
produced with the \Rfunction{plotAlongChrom} function in the
\Rpackage{tilingArray} package.

%------------------------------------------------------------
%%  Figure: fig_tiling_dotsSeg
%------------------------------------------------------------
\myincfig{fig_tiling_dotsSeg}{\textwidth}{Visualization of hybridization
intensities along 16 kB of yeast chromosome 1, measured on a
high-density DNA tiling array. The array covers the genome with 25mer
probes along both strands of each chromosome in steps of 8 bases. The
$y$-axis shows the generalized logarithm~\cite{Huber2002ismb} of the
background-corrected and scaled hybridization intensities, the
$x$-axis corresponds to the genomic coordinates (in bp) of the
probes. Upper and lower scatter plots correspond to Watson and Crick
strands, respectively. Annotated features are shown as boxes for each
strand. Vertical lines are segment boundaries estimated through a
change point detection algorithm. The background threshold is shown as
a horizontal line. The abbreviation CDS in the legend refers to 
coding sequence; uORF, upstream open
reading frame; ncRNA, non-coding RNA; TF, transcription factor.}

%------------------------------------------------------------
%% Figure: fig_tiling_heatmap
%------------------------------------------------------------
\myincfig{fig_tiling_heatmap}{\textwidth}{Visualization of
hybridization intensities along 6.5 kB of yeast chromosome 1 for 24
time points $t=0\mbox{ min}, 10 \mbox{ min}, $\ldots$, 230 \mbox{
min}$. This time span corresponds to about two full cell cycles. The
genomic location is plotted along the $x$--axis, analogous to
Figure~\ref{fig_tiling_dotsSeg}, time along the $y$--axis, and
hybridization intensity is represented by a false-color scheme in
which dark colors represent high values. Due to the limited dynamic
range of such color scales, the choice of mapping between data values
and colors is crucial. Here, intensities were rank transformed and
then mapped to an interpolation between the 9 colors of the
\emph{YlGnBu} palette of the \Rpackage{RcolorBrewer}
package~\cite{Brewer:1994a, Brewer:1994b}}.


%-------------------------------------------------
\subsection{Genome browsers}\label{sec:genbrowser}
%-------------------------------------------------
There are a number of publicly funded genome annotation projects that
are trying to integrate, annotate, and interpret the genome and
transcriptome sequence data and related information that have been
obtained through world-wide efforts over the recent years. So-called
genome browsers are provided that can navigate and visualize
these data and metadata. They are freely available and can be accessed
through the world-wide web using a generic web
browser~\cite{UCSCgenomebrowser,Ensembl2006,NCBI:2005}.

An example from Ensembl is shown in Figure~\ref{fig:genomebrowser}. Again, we
recommend inspecting a colored version of the figure from the
online-complements since genome-browsers make extended use of color coding and
most of the features will not be clear in black and white. The size of features with
which the genomic sequence is annotated ranges from Megabases down to
individual bases, and the hierarchy of size ranges is used to organize the
navigation and information display.  Figure~\ref{fig:genomebrowser}a shows the
cytogenetic bands of human chromosome 3, which has a length of $2\times10^8$
basepairs.  A region near the telomere of the p-arm is marked by a box. An
overview over this region of about $10^6$ basepairs is shown in
Figure~\ref{fig:genomebrowser}b, which displays regions of synteny with other
animals and the loci of genes. A region in the middle around the VHL gene is
marked by a box.  Figure~\ref{fig:genomebrowser}c spans about $10^4$ basepairs
and shows the current experimental evidence for the structure of the VHL gene
(introns, exons) and its products (transcripts and proteins). A region in the
middle is marked. It leads to a fourth panel (not shown), which goes down to
the resolution of individual basepairs and shows the encoded protein sequence
and restriction enzyme sites.

The distributed annotation system (DAS)~\cite{DAS} allows users to add
additional annotation tracks along the genomic coordinates to such
displays without going through the effort of installing and
configuring their own server. These tracks can be obtained from
other public databases, allowing configuration of the display in ways the
maintainers of the genome browser did not consider, or they can be
derived from a user's own data, facilitating viewing them in the context of
genome annotation, as in
Figures~\ref{fig_tiling_dotsSeg} and \ref{fig_tiling_heatmap}.

%------------------------------------------------------------
%% Figure: genome browser
%------------------------------------------------------------
\begin{figure}[tp]
\myhead{a}\\ \includegraphics[width=\textwidth, trim=42 15 20 7, clip=TRUE]{ensembl-chromosomeview}\\[3ex]
\myhead{b}\\ \includegraphics[width=\textwidth, trim=40 5 20 5, clip=TRUE]{ensembl-regionoverview}\\[3ex]
\myhead{c}\\\includegraphics[width=\textwidth, trim=42 30 20 48, clip=TRUE]{ensembl-detailview}
%%\includegraphics[width=\textwidth]{ensembl-basepairview}
\caption{\label{fig:genomebrowser} 
Genome browser visualization of genomic annotation at three different 
levels of resolution. The plots
are taken from the Ensemble genome browser
(http://www.ensembl.org). See main text for details.} 
% caption
\end{figure}

%--------------------------------------------------
\section{Graphs}
%--------------------------------------------------

A graph is a set of \emph{nodes} and a set of \emph{edges}, which we
shall denote $G=(V,E)$. The term \emph{vertices} is often used
interchangeably with nodes.  Our treatment is incomplete, more details
on graph theory can be found in \cite{Gross} while details on
capabilities in R and Bioconductor can be found in
\cite{biocbook2005}. Graphs can be used to represent binary
relationships between the entities represented by the nodes, where the
different relationships could be encoded using different types of
edges. For genomic data, and especially for recent work in systems
biology there is a growing interest in tools for representing,
rendering and computing various statistics or quantities on graphs.

The Bioconductor packages, \Rpackage{graph}, \Rpackage{RBGL} and
\Rpackage{Rgraphviz}, provide software tools for representing graphs,
for graph algorithms and for graph layout, respectively. The tools in
\Rpackage{RBGL} largely rely on the Boost Graph Library \cite{Siek},
and those in \Rpackage{Rgraphviz} rely largely on Graphviz
\cite{graphviz}. 

There are many different specializations of graphs, for example a
directed graph is a graph where all of the edges have a direction, and
directed acyclic graphs (referred to as DAG) arise in different
settings. The Gene Ontology (GO), \cite{GO} provides a structured vocabulary,
or ontology, for genes and gene products in the form of a DAG. 

Other specialized graphs of some interest in biology are bipartite
graphs. A graph is said to be a bipartite graph if the nodes can be
divided into two disjoint sets where all edges are between members of
one set and members of the other and there are no within-set edges.
Bipartite graphs arise in many contexts such as co-citation,
where we would like to study genes that are cited in the same paper
(here one set of nodes are the genes, the other set the papers and
hence the conditions for a bipartite graph are trivially true). A
second, similar example is the bipartite graph that arises when
studying the association between genes and pathways. While there is no
specific definition of a pathway, it is generally taken to be a set of
genes that operate in some coordinated fashion to achieve a major
biological objective. Things such as apoptosis, integrin mediated cell
adhesion etc. are pathways, and KEGG \cite{KEGG} is one source of
pathway data. 

%------------------------------------------------------------
\subsection{The different graph layout engines in graphviz}
%------------------------------------------------------------

%------------------------------------------------------------
% Figure: Graph layout engines
%------------------------------------------------------------
<<FileDep,results=hide,echo=FALSE>>=
data(FileDep)
fdnatt <- makeNodeAttrs(FileDep, label="", shape="circle",
                        fillcolor=colorRampPalette(
      c(brewer.pal(9, "Pastel1"), brewer.pal(8, "Pastel2")))(numNodes(FileDep)))
attr <- list(node = list(width="0.45", height="0.45"), 
             edge = list(arrowsize= "0.7"), graph=list())
@
%
<<filedepdot,fig=TRUE,results=hide,include=FALSE,echo=FALSE,width=6,height=6>>=
par(mar=c(0, 0, 0, 0))
plot(FileDep, "dot", nodeAttrs=fdnatt, attrs=attr, name="", main="")
@
<<filedepneato,fig=TRUE,results=hide,include=FALSE,echo=FALSE,width=6,height=6>>=
par(mar=c(0, 0, 0, 0))
plot(FileDep, "neato", nodeAttrs=fdnatt, attrs=attr, name="", main="")
@
<<filedeptwopi,fig=TRUE,results=hide,include=FALSE,echo=FALSE,width=6,height=6>>=
par(mar=c(0, 0, 0, 0))
plot(FileDep, "twopi", nodeAttrs=fdnatt, attrs=attr, name="", main="")
par(opar)
@
%
\begin{figure}[tp]
\begin{center}
\begin{tabular}{lll}
\myhead{a}&\myhead{b}&\myhead{c}\\
\includegraphics[width=.32\textwidth, trim=0 0 0 60, clip=TRUE]{visualization-filedepdot}&
\includegraphics[width=.32\textwidth, trim=0 0 0 60, clip=TRUE]{visualization-filedepneato}&
\includegraphics[width=.32\textwidth, trim=0 0 0 60, clip=TRUE]{visualization-filedeptwopi}
\end{tabular}
\end{center}
\caption{\label{fig:dotneatotwopi}%
Three different graph layout algorithms applied to the same directed
graph.
\emph{a}: \textbf{dot:} aims at visualizing the hierarchies in a directed graph.
\emph{b}: \textbf{neato:} tries to arrange the nodes
in a way that, as much as possible, the edges do not overlap and
have the same length.
\emph{c} \textbf{twopi:} aims at visualizing the radial structure of the graph.
}
\end{figure}
%

In Figure~\ref{fig:dotneatotwopi} the same graph is laid out using three
different graph layout algorithms. The views are remarkably different,
and the important message, is that the algorithm chosen matters.
In some sense graph layout algorithms are not really visualization methods. 
Most layout algorithms are based on some optimization problem, minimizing
edge length, minimizing edge crossings, a spring model and so on, rather
than on enhancing a particular visual impression. But it is also the
case that a well laid out graph, such as some of the pathway graphs in KEGG 
is incredibly informative. These graphics are no different from any
other plot and the effort expended in selecting appropriate values for the
many parameters will be repaid in terms of effective visualization.

%------------------------------------------------------------
% Figure: GO graph example from bioc book
%------------------------------------------------------------

<<compHyper, results=hide, echo=FALSE>>=
fsubset = sel2 & (rwtt$p.value < 0.0005)
CLL.diss = CLL.exprs[fsubset, goodCell]

gnames <- mget(geneNames(CLL.diss), env = hgu95av2SYMBOL, ifnotfound=NA)
gde <- unlist(gnames)

gNll <- unlist(mget(names(gde), hgu95av2LOCUSID))
gNll <- as.character(gNll)
gGO  <- cache("gGo", makeGOGraph(gNll, "MF"))

nAgo <- makeNodeAttrs(gGO, shape="ellipse", label=substr(nodes(gGO), 7, 10))
gGopen <- agopen(gGO, recipEdges="distinct", layoutType="dot", 
                 nodeAttrs=nAgo, name="")
gNsLL <- unique(unlist(mget(names(gde),
              env=hgu95av2LOCUSID, ifnotfound=NA)))
gGhyp    <- cache("gGhyp", GOHyperG(gNsLL))
gGopenP <- gGopen
agnd    <- AgNode(gGopenP)
pthresh <- 0.1
stopifnot(!any(is.na(gGhyp$pv)))
for(i in seq(along=agnd)) {
  mt <- match(name(agnd[[i]]), names(gGhyp$pv))
  stopifnot(!is.na(mt))
  agnd[[i]]@fillcolor <- ifelse(gGhyp$pv[mt] < pthresh, "#e31a1c", "#edf8fb")
  agnd[[i]]@txtLabel@labelText <- paste(signif(gGhyp$pv[mt], 2))
}
gGopenP@AgNode <- agnd
@ 

<<plotHyper, fig=TRUE, echo=FALSE, results=hide, include=FALSE, width=6, height=6>>=
plot(gGopenP)
@

\begin{figure}[tp]
\begin{center}
\includegraphics[width=\textwidth]{visualization-plotHyper}
\caption{The induced GO graph colored according to unadjusted Hypergeometric
$p$-values, whose values are given in the nodes. Nodes where
the $p$-values are less than $0.1$ are colored. \label{fig:indGG}}
\end{center}
\end{figure}

Figure~\ref{fig:indGG} shows a plot of a portion of one of the ontologies
from GO. GO defines three ontologies that describe genes and gene products; 
the molecular
function ontology, the biological process ontology and the cellular component
ontology. Each ontology is a set of terms, that are related to each other
and are represented as a directed acyclic graph (or DAG), with a root node. 
In Figure~\ref{fig:indGG} each node represents a specific term, and
edges go from more specific terms to related less specific terms. 
Genes are mapped to the different terms in the ontology by
a different initiative, named GOA, \citep{GOA}. In this graphic
we show the subgraph of the molecular function ontology that is induced
by a set of genes selected to distinguish between the stable and progressive
disease in the CLL sample. The filtering of genes was as described
in Section~\ref{sec:Data} except that we reduced the $p$-value criterion to
$0.0001$ in order to produce a plot that would be readable.

\subsection{Bipartite graphs}

Using the same subset of the genes as for Figure~\ref{fig:indGG} 
we found all papers from PubMed that refer to those genes and
created a bipartite graph.  The resultant graph is shown in
Figure~\ref{fig:bppwgraph}. It can be seen that one paper cites all
genes, while three are cited together in one other paper. Starting
from this, an investigator can follow up by reading these papers
and determine if any relationships are revealed in the data.

\begin{figure}
\begin{center}
\includegraphics[width=\textwidth]{ccGraphNew}
\caption{The bipartite graph linking genes to papers, via PubMed.
\label{fig:bppwgraph}}
\end{center}
\end{figure}

\section{Acknowledgements}
We would like to thank Dorit Arlt, Sabina Chiaretti, Sandra
Clauder-M\"unster, Lior David, Jerome Ritz, Annemarie Poustka, Lars Steinmetz,
Holger S\"ultmann, and Stefan Wiemann for allowing us the use of their
data. Ross Ihaka provided expert advice on the use of
colors. Ting-Yuan Liu provided help in producing some of the figures
used in this chapter.

<<cleanup, echo=FALSE, results=hide>>=
graphics.off()
@ 

\bibliographystyle{abbrvnat}
\bibliography{visualization}
\end{document}
