vignettes/aqm.Rnw
7d1ebb43
 %\VignetteIndexEntry{Advanced topics: Customizing arrayQualityMetrics reports and programmatic processing of the output}
9212b1e0
 %\VignetteDepends{CCl4,vsn}
4377060e
 %\VignettePackage{arrayQualityMetrics}
8d922132
 %\VignetteEngine{knitr::knitr}
fd788a8f
 
 \documentclass[11pt]{article}
 
8d922132
 <<style, eval=TRUE, echo=FALSE, results="asis">>=
9212b1e0
 knitr::opts_chunk$set(message=FALSE, warning=FALSE, error=FALSE, tidy=FALSE) # turn off verbosity
e584e554
 BiocStyle:::latex()
5e77d5c9
 @
fd788a8f
 
 \begin{document}
 
9212b1e0
 \bioctitle[Advanced topics]%
     {Advanced topics: Customizing arrayQualityMetrics reports and programmatic processing of the output}
7d1ebb43
 \author{Audrey Kauffmann, Wolfgang Huber}
fd788a8f
 \maketitle
 \tableofcontents
 
9212b1e0
 <<dummy1, include=FALSE>>=
 ##options(error=recover)
b82fcc9f
 options(bitmapType = "cairo")
 .HaveDummy = !interactive()
   if(.HaveDummy) pdf("dummy.pdf")
4377060e
 @ 
 
 %--------------------------------------------------
 \section{Introduction}
 %--------------------------------------------------
6f09c17b
 If you are new to this package, then please consult the vignette
7d1ebb43
 \emph{Introduction: microarray quality assessment with arrayQualityMetrics}.
 
 This vignette addresses advanced topics. It explains how to customize
 the report by selecting specific modules and sections, or by adding
 your own ones. Furthermore, we will see how to (programmatically)
 postprocess the results of the outlier detection, or how to adapt the
 detection criteria to your needs.
6f09c17b
 
7d1ebb43
 \emph{Terminology:} In the documentation of this package, we
6f09c17b
 refer to a \emph{module} as a self-contained element of a report that
 investigates one particular quality metric. A module consists of a
7d1ebb43
 figure and an explanatory text. It may also contain a data structure
 (an object of class \Rclass{outlierDetection}) that
 marks a subset of the arrays in the dataset as outliers
 according to the particular metric investigated in the module.  We
6f09c17b
 refer to a \emph{section} as a collection of one or more modules that
 are thematically related.
fd788a8f
 
4377060e
 For the following examples, let us load the needed packages and some data.
 
5e77d5c9
 <<loading, results="hide">>=
4377060e
 library("arrayQualityMetrics")
7195eda6
 library("ALLMLL")
 data("MLL.A")
4377060e
 @
fd788a8f
 
 
4377060e
 %--------------------------------------------------
 \section{Data preparation}
 %--------------------------------------------------
68fe1452
 Some of the computations that are needed for the modules are common
 between several modules, and thus we perform them once,
 beforehand. These functions are called \Rfunction{prepdata} and
 \Rfunction{prepaffy}, and we refer to their manual page for 
4377060e
 details. For example,
fd788a8f
 
4377060e
 <<DataPreparation>>=
7195eda6
 preparedData = prepdata(expressionset = MLL.A, 
9212b1e0
                         intgroup = c(), 
                         do.logtransform = TRUE)
4377060e
 @ 
 
022d77ed
 The arguments \Robject{intgroup} and \Robject{do.logtransform} are the
 same as for \Rfunction{arrayQualityMetrics}, but in
 \Rfunction{prepdata} they have no defaults, so we need to set them
 explicitely.
4377060e
 
 %--------------------------------------------------
68fe1452
 \section{Module generating functions}
4377060e
 %--------------------------------------------------
68fe1452
 The package contains a variety of functions that compute modules, and they are
 listed on a manual page which you can access by typing:
4377060e
 
8d922132
 <<boxplot, eval=FALSE>>=
68fe1452
 ?aqm.boxplot
 @ 
fd788a8f
 
4377060e
 Here, let us create a report with only two quality metrics modules: 
 boxplots and density plots.
fd788a8f
 
 <<metrics>>=
7d1ebb43
 bo = aqm.boxplot(preparedData)
 de = aqm.density(preparedData)
fd788a8f
 qm = list("Boxplot" = bo, "Density" = de)
 @ 
 
7d1ebb43
 The objects \Robject{bo} and \Robject{de} are of class
 \Rclass{aqmReportModule}; please consult the class' manual page for
 more information.
 
8792a5b1
 If you want to create your own modules, please have a look at the code
 for the various existing functions for this purpose, and adapt it.
6f09c17b
 The function \Rfunction{aqm.pca} is a good place to start.
4377060e
 
7d1ebb43
 %--------------------------------------------------
 \section{Outlier detection}
 %--------------------------------------------------
 Some of the modules perform outlier detection. For instance, in the
 default report produced by \Rfunction{arrayQualityMetrics}, the
7195eda6
 module headed \emph{Boxplots} is followed by one headed \emph{Outlier
7d1ebb43
   detection for Boxplots}. In the corresponding
 \Rclass{aqmReportModule} object, this is reflected by a non-trivial
 value for the slot named \Robject{outliers}:
 %
 <<booutliers>>=
 bo@outliers
 @ 
 %
7195eda6
 The slot named \Robject{statistic} contains, for each array, a
 single number based on which outlier detection is performed.  For
 instance, in the case of \Robject{bo}, the slot
 \Robject{bo@outliers@statistic} is the Kolmogorov-Smirnov statistic
 for the comparison between each array's intensity distribution and the
 distribution of the pooled data. The slot \Robject{threshold} contains
 the threshold against which the valuess of \Robject{statistic} were
 compared. Arrays with a value of \Robject{statistic} greather than
 \Robject{threshold} are called outliers. Their indices are listed in
 the vector \Robject{which}.  Finally, the slot \Robject{description}
 contains a textual description of the definition of
 \Robject{statistic} and indicates how the \Robject{threshold} was chosen.
 
 The actual details of outlier detection are different for each report
 module, and are documented in the figure caption of the report
 module. For more information, please look at the code of
 the report module generating function of interest -- for instance, at the first few
 lines of the \Rfunction{boxplot} function. The code there uses the helper
f6311cf4
 functions \Rfunction{outliers} and \Rfunction{boxplotOutliers}, which
7195eda6
 are documented in their manual pages.
7d1ebb43
 
4377060e
 %--------------------------------------------------
 \section{Rendering the report}
 %--------------------------------------------------
 A report is rendered by calling the function
7195eda6
 \Rfunction{aqm.writereport} with a list of \Rclass{aqmReportModule}
 objects.
4377060e
 
fd788a8f
 <<shortReport>>=
 outdir = tempdir()
6f09c17b
 aqm.writereport(modules = qm, reporttitle = "My example", outdir = outdir, 
7195eda6
                 arrayTable = pData(MLL.A))
fd788a8f
 outdir
 @ 
 
6f09c17b
 Point your browser to the \texttt{index.html} file in that directory.
 
4377060e
 %--------------------------------------------------
fd788a8f
 \subsection*{Session Info}
4377060e
 %--------------------------------------------------
9212b1e0
 <<dummy2, include=FALSE>>=
b82fcc9f
 if(.HaveDummy) dev.off()
 @ 
 
 
9212b1e0
 <<pkgs, echo=FALSE, results="asis">>=
fd788a8f
 toLatex(sessionInfo())
 @
 
 \end{document}