
% NOTE -- ONLY EDIT THE .Rnw FILE!!!  The .tex file is
% likely to be overwritten.
%
% \VignetteIndexEntry{How to apply the ddCt method}
%\VignetteDepends{Biobase,prada}
%\VignetteKeywords{}
%\VignettePackage{none}
\documentclass[12pt]{article}

\usepackage{times}
\usepackage{hyperref}

\usepackage[authoryear,round]{natbib}
\usepackage{times}
\usepackage{comment}

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

\newcommand{\scscst}{\scriptscriptstyle}
\newcommand{\scst}{\scriptstyle}

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


\bibliographystyle{plainnat}

\begin{document}
\title{How to apply the ddCt method}
\author{Markus Ruschhaupt}
\maketitle


In this vignette we describe how the functions \Rfunction{ddCt},
\Rfunction{readSDM} and \Rfunction{eSetWrite}, available in the package \Rpackage{prada},
can be used to perform the ddCt method for a given set of data. First the
files including the data must be specified. Here the files 'Experiment1.txt' and 'Experiment2.txt'are the output files
of SDS, Version 2.1. Furthermore it is possible to include sample specific information.
In this example these informations are stored as the tab-delimited text file
'sampleData.txt'. The warnings that appear during the calculation process, e.g. if the
Ct value for the housekeeping gene is missing, are saved as
a text file specified by the parameter 'warningFile'.

<<specifyFiles,results=hide>>=
library(prada)
datadir <- function(x) file.path(.path.package("prada"), "extdata", x)
savedir <- function(x) file.path(.path.package("prada"), "extdata", x)

file.names <- c(datadir("Experiment1.txt"),datadir("Experiment2.txt"))
info <- datadir("sampleData.txt")
warningFile <- savedir("warning.output.txt")
@
The housekeeping gene and the calibration sample/s must be specified. If there
is more than one calibration sample the mean of the Ct values will be uses for calibration. 
<<readingData>>=
name.referenz.sample <- c("Sample1")
name.referenz.gene <- "Gene2"
@
Now the data from the experiment files will be read.
<<readData,results=hide>>=
library(Biobase)  
CtData <- readSDM(file.names)
sampleInformation <- read.phenoData(info,header=TRUE)
@
With this information we can start the calculation of the ddCt method.

<<calculating>>=
result <- ddCt(CtData,calibrationSample=name.referenz.sample,housekeepingGene=name.referenz.gene,sampleInformation=sampleInformation,filename=warningFile)
@
\Robject{result} is a member of the class \Rclass{eSet} from the
\Rpackage{Bioconductor} package. The function \Rfunction{ddCt} performs several steps to calculate the ddCt and
other values. 
\begin{enumerate}
\item{The median of each triplet is the Ct value.}
\item{The Ct values of the housekeeping gene are subtracted from the other
corresponding Ct values. The results are the dCt values.}
\item{The dCt values of the calibration sample (or the mean of the dCt values
of several calibration samples) are subtracted from the other corresponding dCt
values. This gives the ddCt values.}
\item{The transformation $x \rightarrow 2^{-x}$ is applied to the ddCt values. This
gives the levels.}
\end{enumerate}
Additionally the MAD of each triplet is calculated (if you have three different
points the MAD is the shorter of the two neighbour points distances). 
The longer distance(if there is a triplet without
NA values) and the number of NA values for each triplet is also
calculated. All these values are stored in the corresponding slots of the
eList of the \Robject{result} object. For example the MAD of all triplets is
accessible through
<<showMAD>>=
assayData(result)$Ct.error
@
We save the results as tab-delimited text files. Therefor we use the function 
\Rfunction{eListWrite}.
<<write Tables>>=
eListWrite(result,file=savedir("allValues.txt"),sep="\t",row.names=FALSE)
write.table(exprs(result),file=savedir("level_matrix.txt"), sep = "\t", col.names = NA)
write.table((result)$dCt,file=savedir("dCt_matrix.txt"), sep = "\t", col.names =NA)
@

\end{document}





