%\VignetteIndexEntry{CCl4}
%\VignetteDepends{Biobase,limma}
%\VignetteKeywords{ExpressionData}
%\VignettePackage{CCl4}

\documentclass[a4paper]{article}

\usepackage{times}
\usepackage{a4wide}
\usepackage{verbatim}

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

\SweaveOpts{keep.source=TRUE,eps=FALSE,include=FALSE,width=4,height=4.5} 

\begin{document}

\title{From the Genepix data files to RGList to NChannelSet}
\author{Audrey Kauffmann, Wolfgang Huber}
\maketitle

\section*{Load the required packages}

<<loadlibs>>=
library("Biobase")
library("limma")
library("CCl4")
@ 

\section*{Read the data and convert them into an RGList}  
The Genepix (\texttt{.gpr}) data files are in the \texttt{extdata} 
directory of the \Rpackage{CCl4} package.
If you have the package installed, we can locate them 
on your filesystem with the function \Rfunction{system.file}.
If the files are somewhere else, please adapt the below assignment
to \Robject{datapath}.
%
<<datapath>>=
datapath = system.file("extdata", package="CCl4")
@ 
%
<<RGList, results=hide>>=
p = read.AnnotatedDataFrame("samplesInfo.txt", path=datapath)

CCl4_RGList = read.maimages(files=sampleNames(p), 
   path = datapath, 
   source = "genepix", 
   columns = list(R = "F635 Median", Rb = "B635 Median", 
                  G = "F532 Median", Gb = "B532 Median"))
@
% 
If this code is run in the \texttt{inst/doc} directory of the 
\Rpackage{CCl4} (source) package,
the output data files will be written directly into the  
\texttt{data} directory of the package. Otherwise, just write into a temporary 
directory.
%
<<outdir>>=
outdir = file.path("..", "..", "data")
if(!isTRUE(file.info(outdir)$isdir))
  outdir = tempdir()

save(CCl4_RGList, file = file.path(outdir, "CCl4_RGList.RData"))
@ 

The function \Rfunction{read.maimages} from the \Rpackage{limma} package reads
the \texttt{.gpr} files andbuilds an \Rclass{RGList} object from it.

The output is written to
<<tempdir>>=
outdir
@ 

\section*{Build an NChannelSet from the RGList} 
 
Once the \Rclass{RGList} object has been created, 
we can build an \Rclass{NChannelSet}.

<<CCl4-NChannelSet>>=

featureData = new("AnnotatedDataFrame", data = CCl4_RGList$genes)

assayData = with(CCl4_RGList, assayDataNew(R=R, G=G, Rb=Rb, Gb=Gb))

varMetadata(p)$channel=factor(c("G", "R", "G", "R"), 
                    levels=c(ls(assayData), "_ALL_"))

CCl4 <- new("NChannelSet",
              assayData = assayData,
              featureData = featureData,
              phenoData = p)
save(CCl4, file = file.path(outdir, "CCl4.RData"))
@ 



\begin{table*}[tbp]
\begin{minipage}{\textwidth}
{\small
<<sessionInfo, print=TRUE>>=
sessionInfo()
@ 
}\end{minipage}
\caption{\label{tab:sessioninfo}%
The output of \Rfunction{sessionInfo} on the build system 
after running this vignette.}
\end{table*}




\end{document}



