%\VignetteDepends{}
%\VignetteIndexEntry{NetCDF Slides}
%\VignettePackage{AdvancedR2011}

\documentclass{beamer}

\usepackage{BioconductorSlides}
\SweaveOpts{keep.source=TRUE}

\title{Interfacing With Common Resources: NetCDF}
\author{Nishant Gopalakrishnan \\ Fred Hutchinson Cancer Research Center}
\date{17-18 February, 2011}

\begin{document}

<<setup, echo=FALSE>>=
options(width = 40)
@ 

\frame{\titlepage}

\section[Outline]{}
\frame{\tableofcontents}

\section{Introduction}
\begin{frame}{Handling Large Data}

\begin{itemize}
\item text files
\item binary files
\item read and process in chunks
\item NetCDF
\end{itemize}
\end{frame}

\begin{frame}{Network Common Data Form (NetCDF)}
Set of data formats, programming interfaces and software libraries to
read/write  array oriented scientific data
    \begin{itemize}
    \item NetCDF software library
        \begin{itemize}
            \item NetCDF version 3
            \item NetCDF version 4 
        \end{itemize}
    \item R packages
        \begin{itemize}
            \item ncdf
                \begin{itemize}
                \item Warning: character array implementation is inefficient.
                \end{itemize}
                
            \item ncdf4
                \begin{itemize}
                    \item Multiple unlimited dimensions
                    \item Data compresssion
                    \item Not available on Windows
                \end{itemize}

        \end{itemize}
    \end{itemize}
\end{frame}

\begin{frame}{NetCDF Model}
    \begin{itemize}
        \item Variables : N-dimensional arrays of data: byte, short, integer,
        float, double
        \item Dimensions
            \begin{itemize}
                \item Axes of data arrays
                \item Name, length
                \item Unlimited dimension   
            \end{itemize}  
        \item Attributes : Annotate Variables with meta data 
    \end{itemize}
\end{frame}

\section{ncdf R package}

\begin{frame}[fragile]{Using ncdf R package}
\begin{itemize}
\item Define dimensions
\begin{verbatim}
sampDim <- dim.def.ncdf(name = "sampleDim", 
    units = "id", vals = seq_len(NROWS))
snpDim <- dim.def.ncdf(name = "snpDim",
    units = "id", vals = seq_len(NCOLS))
\end{verbatim}
\item Define variable
\begin{verbatim}
snpDat <- var.def.ncdf(name = "snpData",
    units ="0: missing, 1: AA, 2: AB, 3: BB",
    dim = list(sampDim, snpDim),
    missval = 0L, prec = "byte")
\end{verbatim}
\end{itemize}
\end{frame}

\begin{frame}[fragile]{Using ncdf R package}
\begin{itemize}
\item Create file, write variable
\begin{verbatim}
nc <-open.ncdf("myFile.nc")
put.var.ncdf(nc, varid = "snpData", vals = mat)
\end{verbatim}
\item Write slice
\begin{verbatim}
## samples 1:10,  snps 1:20
put.var.ncdf(nc, varid = "snpData", vals = slice, 
    start = c(1,1), count =c(10, 20))
close(nc)
\end{verbatim} 
\end{itemize}
\end{frame}


\begin{frame}[fragile]{Using ncdf R package}
\begin{itemize}
\item Read variable from file
\begin{verbatim}
nc <-open.ncdf("myFile.nc")
myVar <- get.var.ncdf(nc, varid = "snpData")
close(nc)
\end{verbatim}
\item Read slices of data 
\begin{verbatim}
nc <-open.ncdf("myFile.nc")
## samples 30:40, snps 100:120
slice1 <- get.var.ncdf(nc, "snpData", 
    start =c(30, 100), count  =c(10, 20)) 
## all samples, snps 1000:1100
slice2 <- get.var.ncdf(nc, "snpData", 
    start =c(1, 1000), count  =c(-1,100)) 
close(nc)       
\end{verbatim} 
\end{itemize}
\end{frame}

\section{Resources}

\begin{frame}{Resources}
\begin{itemize}
     \item http://cran.r-project.org/web/packages/ncdf/ncdf.pdf
     \item http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-tutorial.html
\end{itemize}
\end{frame}

\end{document}
