\HeaderA{readCelUnits}{Reads probe-level data ordered as units (probesets) from one or several Affymetrix CEL files}{readCelUnits}
\keyword{file}{readCelUnits}
\keyword{IO}{readCelUnits}
\begin{Description}\relax
Reads probe-level data ordered as units (probesets) from one or several Affymetrix CEL files by using the unit and group definitions in the
corresponding Affymetrix CDF file.
\end{Description}
\begin{Usage}
\begin{verbatim}readCelUnits(filenames, units=NULL, stratifyBy=c("nothing", "pmmm", "pm", "mm"), cdf=NULL, ..., addDimnames=FALSE, dropArrayDim=TRUE, transforms=NULL, reorder=TRUE, readMap=NULL, verbose=FALSE)\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{filenames}] The filenames of the CEL files.
\item[\code{units}] An \code{\LinkA{integer}{integer}} \code{\LinkA{vector}{vector}} of unit indices specifying which
units to be read.  If \code{\LinkA{NULL}{NULL}}, all units are read.
\item[\code{stratifyBy}] Argument passed to low-level method
\code{\LinkA{readCdfUnits}{readCdfUnits}}.
\item[\code{cdf}] A \code{\LinkA{character}{character}} filename of a CDF file, or a CDF \code{\LinkA{list}{list}}
structure.  If \code{\LinkA{NULL}{NULL}}, the CDF file is searched for by
\code{\LinkA{findCdf}{findCdf}}() first starting from the current directory and
then from the directory where the first CEL file is.
\item[\code{...}] Arguments passed to low-level method
\code{\LinkA{readCel}{readCel}}, e.g. \code{readXY} and \code{readStdvs}.
\item[\code{addDimnames}] If \code{\LinkA{TRUE}{TRUE}}, dimension names are added to arrays,
otherwise not.  The size of the returned CEL structure in bytes
increases by 30-40\% with dimension names.
\item[\code{dropArrayDim}] If \code{\LinkA{TRUE}{TRUE}} and only one array is read, the elements of
the group field do \emph{not} have an array dimension.
\item[\code{transforms}] A \code{\LinkA{list}{list}} of exactly \code{length(filenames)}
\code{\LinkA{function}{function}}s.  If \code{\LinkA{NULL}{NULL}}, no transformation is performed.
Intensities read are passed through the corresponding transform
function before being returned.
\item[\code{reorder}] If \code{\LinkA{TRUE}{TRUE}}, cell indices are read in order to speed up the
reading.  If \code{\LinkA{FALSE}{FALSE}}, cells are read in the order as given.  For
more details, see help on the same argument in \code{\LinkA{readCel}{readCel}}().
\item[\code{readMap}] A \code{\LinkA{vector}{vector}} remapping cell indices to file indices.
If \code{\LinkA{NULL}{NULL}}, no mapping is used.
\item[\code{verbose}] Either a \code{\LinkA{logical}{logical}}, a \code{\LinkA{numeric}{numeric}}, or a \code{\LinkA{Verbose}{Verbose}}
object specifying how much verbose/debug information is written to
standard output. If a Verbose object, how detailed the information is
is specified by the threshold level of the object. If a numeric, the
value is used to set the threshold of a new Verbose object. If \code{\LinkA{TRUE}{TRUE}},
the threshold is set to -1 (minimal). If \code{\LinkA{FALSE}{FALSE}}, no output is written
(and neither is the \pkg{R.utils} package required).

\end{ldescription}
\end{Arguments}
\begin{Value}
A named \code{\LinkA{list}{list}} with one element for each unit read.  The names
corresponds to the names of the units read.
Each unit element is in
turn a \code{\LinkA{list}{list}} structure with groups (aka blocks).
Each group contains requested fields, e.g. \code{intensities},
\code{stdvs}, and \code{pixels}.
If more than one CEL file is read, an extra dimension is added
to each of the fields corresponding, which can be used to subset
by CEL file.

Note that neither CEL headers nor information about outliers and
masked cells are returned.  To access these, use \code{\LinkA{readCelHeader}{readCelHeader}}()
and \code{\LinkA{readCel}{readCel}}().
\end{Value}
\begin{Author}\relax
Henrik Bengtsson (\url{http://www.braju.com/R/})
\end{Author}
\begin{References}\relax
[1] Affymetrix Inc, Affymetrix GCOS 1.x compatible file formats,
June 14, 2005.
\url{http://www.affymetrix.com/support/developer/}
\end{References}
\begin{SeeAlso}\relax
Internally, \code{\LinkA{readCelHeader}{readCelHeader}}(), \code{\LinkA{readCdfUnits}{readCdfUnits}}() and
\code{\LinkA{readCel}{readCel}}() are used.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
##############################################################
if (require("AffymetrixDataTestFiles")) {            # START #
##############################################################

# Search for some available CEL files
path <- system.file("rawData", package="AffymetrixDataTestFiles")
files <- findFiles(pattern="[.](cel|CEL)$", path=path, recursive=TRUE, firstOnly=FALSE)
files <- grep("FusionSDK_Test3", files, value=TRUE)
files <- grep("Calvin", files, value=TRUE)

# Fake more CEL files if not enough
files <- rep(files, length.out=5)

print(files);

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Benchmarking reading cells in order or not.
#
# The difference will be large the more files that are read.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
units <- 56:256
nunits <- length(units);

nfiles <- length(files);

t1 <- system.time({
  cel <- readCelUnits(files, units=units, reorder=TRUE)
})[3]
cat(sprintf("Time   [ordered]: %6.2fs = %.2fms/(unit & array) [1.00x]\n",
                                          t1, 1000*t1/nunits/nfiles))
rm(cel); gc()

t2 <- system.time({
  cel <- readCelUnits(files, units=units, reorder=FALSE)
})[3]
cat(sprintf("Time [unordered]: %6.2fs = %.2fms/(unit & array) [%.2fx]\n",
                                   t2, 1000*t2/nunits/nfiles, t2/t1))
rm(cel); gc()

# Clean up
rm(files, t1, t2)

##############################################################
}                                                     # STOP #
##############################################################
\end{ExampleCode}
\end{Examples}

