%\VignetteDepends{}
%\VignetteIndexEntry{}
%\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}{Network Common Data Form (NetCDF)}
Set of data formats, programming interfaces software libraries to
read/write scientific data
    \begin{itemize}
    \item NetCDF software library
        \begin{itemize}
            \item NetCDF version 3
            \item NetCDF4 
        \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: char, byte, int, 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
<<code-block, eval = FALSE, keep.source = TRUE>>=
sampDim <- dim.def.ncdf("Sample", "id", seq_len(NROWS))
snpDim <- dim.def.ncdf("SNP", "id", seq_len(NCOLS))
@ 
\item Define variable
<<code-block, eval = FALSE, keep.source = TRUE>>=
snpDat <- var.def.ncdf("Genotype", units ="", dim = list(sampDim, snpDim),
                  missval = - 1L, prec = "byte")
@ 

\end{itemize}
\end{frame}

\begin{frame}[fragile]{Using ncdf R package}
\begin{itemize}
\item Create file, write variable
<<code-block, eval = FALSE, keep.source = TRUE>>=
 nc <- create.ncdf("myFile.nc", snpDat)
 put.var.ncdf(nc, "Genotype", mat)
 close(nc)
@ 
\end{itemize}
\end{frame}


\begin{frame}[fragile]{Using ncdf R package}
\begin{itemize}
\item Read variable from file
<<code-block, eval = FALSE, keep.source = TRUE>>=
 nc <-open.ncdf("myFile.nc")
 myVar <- get.var.ncdf(nc, "Genotype")
 close(nc)
@ 
\item Read slices of data 
<<code-block, eval = FALSE, keep.source = TRUE>>=
 nc <-open.ncdf("myFile.nc")
 sliceRow <- get.var.ncdf(nc, "Genotype", start =c(30, 100), count  =c(10, 20))  ## samples 30:40, snps 100:120
 sliceRow <- get.var.ncdf(nc, "Genotype", start =c(1, 1000), count  =c(-1,100))  ## all samples , snps 1000:1100
 close(nc)        
@ 
\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}
