%%%%%%%%%%%%%%%%%%%
% prepare the files
%%%%%%%%%%%%%%%%%%%
\newpage
\section{Preparing the input files}
A data file and a design file should be prepared manually. 
\subsection{Preparing the data files}
There should be only ONE data file. Most gridding software produces one file
for each slide. Thus especially when you use two-color array and have multiple files, you have to combine these files to get one data file as a input for {\em R/maanova}. \\
{\bf Input data file} Data file can be two kinds of type.
\begin{itemize}
\item matrix type {\em R} object : {\em R/maanova} can read matrix
{\em R} object including the output of {\tt exprs()} from {\em affy} or {\em
beadarray} package. {\tt Rowname} of the matrix is used as probe (clone) ID, and it is assumed that the data is started from the first column. 
\item TAB delimited text file : This can be a typical input file for two-color
array. {\em R/maanova} assumes that first colum is
probe (clone) ID, and intensity data is saved from the second column
(i.e. {\tt probeid} = 1, {\tt intensity} = 2). Otherwise user needs to specify the column number storing
probe ID and column number from which data starts by using {\tt probeid} and {\tt intensity}, respectively. When clone ID is not provided, 1,2,$\ldots$ are used as a probe ID. 
\end{itemize}
{\bf Input data file for N-day array} For N-dye arrays, the N channel intensity data for one array needs to be
adjacent to each other (in consecutive columns). The order (dye1, dye2, ...)
must be consistent across all of the slides. You can put the spot flag as a
column after intensity data for each array. (Note that if you have flag, you
will have N+1 columns of data for each array. Again, this must be consistent
for all arrays in the data set.) If you have duplicated spots 
within one array, replicated measurements of the same clone on the same array
should appear in adjacent rows. This can be easily done by sorting on
probeid. The number of replicates must be constant for all genes. As an
example, you have four slides for a two-dye array experiment scanned by
GenePix. Then you will have four output files. Following the steps to create your data file:
\begin{enumerate}
\item Open your favorite spread sheet editor, e.g., MS Excel and 
create a new file.
\item Paste your clone ID, Gene names, Cluster ID and whatever
information you want to keep into the first several columns.
\item Open your first GenePix file in another window, 
copy the grid location into next 4 columns (you only need to do this once
because they are all the same for four slides).
\item Copy the two columns of foreground mean value (if you want to use it)
and one column of flag to the file in the order of Cy5, Cy3, flag.
\item Open your other 3 files and repeat step 4.
\item Select the whole file and sort the row according to Clone ID.
\item Save the file as tab delimited text file and you are done. 
\end{enumerate}
CAMDA kidney data file at {\tt
http://research.jax.org/faculty/churchill/software} can provide a good example.\\
{\bf No missing in input} The data file must be ``full'', that is, all rows
have to have the same number of columns. Also data should not have any missing
value. If so, you want to either check the experiment to get the data or
use {\tt fill.missing()} function to fill in the missing value. 

Sometimes reading and trailing TAB in the text file can cause
problems, depending on the operating system. So the you should be careful
about that. Sometimes the special characters in gene description can
cause reading problem. We don't encourage you to put the gene description
in the data file. If you have to do that, you must be careful (sometimes
you need to remove the special characters manually).
\subsection{Preparing the design file}
{\bf Design file} Design file can be three kinds of type.
\begin{itemize}
\item TAB delimited text file : should be saved at the working directory.
\item {\tt data.frame} {\em R} object
\item {\tt matrix} {\em R} object. 
\end{itemize}
{\bf Size of design file} The number of row in design file should be the
number of array times N (the number of dyes) (plus one for column header, if
the design file is TAB delimited text file, and header = T). The number of columns in this file depends on the experimental design. You can
specify all information related to experiment at the {\tt designfile}, but do
not necessarily need to use all of them to specify your model. Among factors
in {\tt designfile}, you can specify only some of them in a formula at {\tt fitmaanova()}.\\
{\bf Required fields in design file} You must have an {\tt Array} column in the
design file (column headers are case sensitive). For two-color (or
multi-color) array, user needs two more extra columns, {\tt Dye} and {\tt Sample}. {\tt Dye} is reserved for the dye
name, and {\tt Sample} is reserved to identify biological replicates and
reference samples. Usually you should assign each biological individual a
unique sample number. Reference samples are represented by zero(0). Reference
sample are treated differently. They will always be treated as fixed factor in
the model and not involved in statistical tests. 

{\tt Sample} is not an
required field in one-color array, however if the experiment has technical
replicate, {\tt Sample} field should be included to get a valid result. Refer
to Section 5.2 for an example.  

{\tt Sample} column in design file
need to be continuous integer. All other columns can be either integers or
characters. \\
{\bf Names must not used in design file} You must not have following columns in the design file:
\begin{itemize}
\item Spot: reserved for spot effect
\item Label: reserved for labeling effect
\item covM: reserved for covariate matrix 
\end{itemize}

\subsection{Preparing the covariate matrix}
{\bf Array specific covariate} If you want to include array specific
covariate, it should be included in the design file and specified in the {\tt fitmaanova()}. The covariate variable
should be an integer and the size should equal to the number of arrays. \\
{\bf Gene specific covariate} If you have a gene specific covariate variable,
you need to prepare the
covariate matrix, {\tt covM}, and include it at the {\tt read.madata()} and the
formula in {\tt fitmaanova()}. {\tt covM} can be either {\tt matrix} R object or
TAB delimited tex file. When it is a delimited file, {\tt covM} should have
column name (if header = T ) but no row name, and the covariate variable size should equal to
the size of {\tt datafile}. Currently this only works for the fixed model. \\
Refer to {\tt help(read.madata)} and {\tt help(fitmaanova)} for more
information. 
