% NOTE -- ONLY EDIT THE .Rnw FILE!!!  The .tex file is
% likely to be overwritten.
%
%\VignetteIndexEntry{Combining prada output and cellHTS2}
%\VignetteDepends{prada}
%\VignetteKeywords{}
%\VignettePackage{none}
\documentclass[11pt]{article}
\usepackage{times}

\textwidth=6.2in
\textheight=8.5in
%\parskip=.3cm
\oddsidemargin=.1in
\evensidemargin=.1in
\headheight=-.3in

\newcommand{\Rfunction}[1]{{\texttt{#1}}}
\newcommand{\Robject}[1]{{\texttt{#1}}}
\newcommand{\Rpackage}[1]{{\textit{#1}}}
\newcommand{\Rvariable}[1]{{\textit{#1}}}

\begin{document}
\title{Feeding the output of a flow cytometry assay into cellHTS2}
\author{Florian Hahne}
\maketitle

The package \Rpackage{prada} can be used to analyze flow cytometry raw
data derived from cell-based assays. The output of these analyses are
highly processed data or even scored hit lists. However, for some
applications it might also be useful to integrate this output into the
\Rpackage{cellHTS2} package in order to make use of its excellent
visualization and QA features.  Although \Rpackage{cellHTS2} is more
geared towards the analysis of unprocessed raw data data the process
is rather straight forward. To exemplify the procedure we added some
sample files derived from an apoptosis assay to this package which
contain all the necessary information to be provided for
\Rpackage{cellHTS2}. The generation of these files can be accomplished
using the available file handling functions provided by R or by
using text processing software.
The data consist of scored effect sizes (odds ratios) for two
replicates of two 96 well plates. Cells in each well were transfected
with a different overexpression construct for a protein of unknown
function and the induction of apoptosis was measured using FACS
readout. The file \emph{Platelist.txt} maps the contents of the data
files for each plate to plate and replicate identifiers.
We first load the package.
%
<<prepare, results=hide>>=
library("cellHTS2")
@
%
By calling \Rfunction{readPlateData} we can import the
data and generate a \Rpackage{cellHTS} object. In the import
function we also want to calculate the negative log transformation of the
odds ratio to ensure symmetry around zero.
<<readPlateData>>=
experimentName = "ApoptosisScreen"
dataPath = system.file("extdata", package = "prada")
x = readPlateList("Platelist.txt", name = experimentName,
                  path = dataPath, verbose = FALSE,
                  importFun=function(file, path){
                      data <- read.delim(file, header=FALSE, as.is=TRUE)
                      return(list(data.frame(well=I(as.character(data[,2])), val=-log10(data[,3])),
                                  readLines(file)))
                  })
x
@

In a second step we tell \Rpackage{cellHTS2} where to expect controls
on the plates and also give some details about the experiment. This
information is provided by the files \emph{Plateconf.txt},
\emph{Screenlog.txt} and \emph{Description.txt}.

<<configure>>=
x = configure(x, confFile="Plateconf.txt", descripFile="Description.txt", path=dataPath)
@

In the next step we include annotation information for both plates
(provided by the file \emph{GeneIDs}.

<<annotate>>=
geneIDFile = file.path(dataPath, "GeneIDs.txt")
x = annotate(x, geneIDFile)
@

We ask \Rpackage{cellHTS2} to do a simple mean normalization even
though rough normalization has already been done
during our analysis. We also sumarize replicates and score.

<<normalize>>=
xn <- normalizePlates(x, method="mean")
xsc <- scoreReplicates(xn, sign="-", method="zscore")
xsc <- summarizeReplicates(xsc, summary="mean")
@

In the final step we generate the HTML report.

<<report, eval=FALSE>>=
od <- tempfile()
writeReport(raw=x, normalized=xn, scored=xsc, force = TRUE, outdir=od)
@

The final report can now be inspected in the subfolder
\emph{ApoptosisScreen} of the temporary working directory. For more
information on each individual step and the content of the report
please consult the vignette of the \Rpackage{cellHTS2} package.


\end{document}
