%\VignetteIndexEntry{crlmm Vignette - Illumina 370k chip}
%\VignetteKeywords{genotype, crlmm, Illumina}









\title{Using \Rpackage{crlmm} to genotype data from Illumina's Infinium BeadChips}
\author{Matt Ritchie}

\section{Getting started}

In this user guide we read in and genotype data from 40 HapMap samples
which have been analyzed using Illumina's 370k Duo BeadChips.
This data is available in the \Rpackage{hapmap370k} package.
Additional chip-specific model parameters and basic SNP annotation
information used by CRLMM is stored in the \Rpackage{human370v1cCrlmm} package.
The required packages can be installed in the usual way using the \Rfunction{biocLite} function.

<<echo=TRUE, results=hide, eval=FALSE>>=
if (!requireNamespace("BiocManager", quietly=TRUE))
BiocManager::install(c("crlmm", "hapmap370k", "human370v1cCrlmm"))

\section{Reading in data}
The function \Rfunction{readIdatFiles} extracts the Red and Green intensities
from the binary {\tt idat} files output by Illumina's scanning device.
The file {\tt samples370k.csv} contains information about each sample.

<<echo=FALSE, results=hide, eval=TRUE>>=

<<read, results=hide, eval=TRUE>>=

data.dir = system.file("idatFiles", package="hapmap370k")

# Read in sample annotation info
samples = read.csv(file.path(data.dir, "samples370k.csv"), as.is=TRUE)


Next we use the function \Rfunction{crlmmIllumina} which performs preprocessing followed by genotyping using the CRLMM algorithm.
It reads in data from idat files and stores results in a \Rclass{CNSet} object.

<<genotype, results=hide, cache=TRUE>>=
crlmmResult = crlmmIllumina(samples, path=data.dir,
				saveDate=TRUE, cdfName="human370v1c", verbose=FALSE)

calls(crlmmResult)[1:10, 1:5]

If GenCall output is available instead of idat files, the function \Rfunction{readGenCallOutput} can be
used to read in the data.
This function assumes the GenCall output is formatted to have samples listed one below the other,
and that the columns 'X Raw' and 'Y Raw' are available in the file.
The resulting \Robject{NChannelSet} from this function can be used as input to 
\Rfunction{crlmmIllumina} (or equivalently \code{genotype.Illumina}) via the \Robject{XY} argument 
(instead of the usual \Rfunction{RG} argument used when the data has been read in from idat files).

Plotting the {\it SNR} reveals no obvious batch effects in this data set (different symbols are used for
arrays scanned on different days).

<<snr,  fig=TRUE, width=8, height=6>>=
plot(crlmmResult[["SNR"]], pch=scanbatch, xlab="Array", ylab="SNR",
     main="Signal-to-noise ratio per array",las=2)

<<plotsamples, fig=TRUE, width=8, height=8>>=
plotSamples(crlmmResult, col=1:4)

<<plotsnps, fig=TRUE, width=8, height=8>>=
plotSNPs(crlmmResult, row=1:4)

\section{System information}

This analysis was carried out on a linux machine with 32GB of RAM
using the following packages: