%% \VignetteIndexEntry{Talk: Introduction to R / Bioconductor}

\documentclass[]{beamer}

\usepackage{BioconductorSlides}
\title{Introduction to \R{} and \Bioconductor{}}
\author{
  Martin
  Morgan\footnote{\href{mailto:mtmorgan@fhcrc.org}{mtmorgan@fhcrc.org}}
}
\date{June 23 -- 28, 2013}

<<setup, echo=FALSE>>=
library(Morgan2013)
@ 

\begin{document}

\begin{frame}
  \maketitle
\end{frame}

\begin{frame}{Overview}
\begin{columns}[t]
  \column{.5\textwidth}\R{}
  \begin{enumerate}
  \item Vectors, data frames, arrays
  \item Statistical concepts
  \item Functions
  \item Packages
  \item From script to collaboration
  \item HELP!
  \end{enumerate}
  \column{.5\textwidth}\Bioconductor{}
  \begin{enumerate}
  \item A short history
  \item Sequence analysis
  \item Classes, generics and methods
  \item HELP!
  \end{enumerate}
\end{columns}
\end{frame}

\section{R}

\begin{frame}[fragile]
  \frametitle{Vectors, data frames, arrays}
<<vectors>>=
x <- c(1, 2, 3, 4, 5)
x
log(x)
x[c(3, 2)]
x[3:2]
x[c(TRUE, FALSE)]
@ 
\end{frame}

\begin{frame}[fragile]
  \frametitle{Vectors, data frames, arrays}
<<data-frames>>=
df <- data.frame(
    age = c(17, 23, 32, 37),
    sex = c("Male", "Female", "Female", "Male"))
df
df[df$age < 30 & df$sex == "Male", ]
@ 
\end{frame}

\begin{frame}[fragile]
  \frametitle{Vectors, data frames, arrays}
<<matrixs>>=
m <- matrix(1:8, 2, 4)
m
log(m)
rowSums(m)
@ 
\end{frame}

\begin{frame}[fragile]
  \frametitle{Statistical concepts}
<<stat-concepts>>=
df$sex
df$height <- c(180, 172, NA, 177)
df
@ 
\end{frame}

\begin{frame}{Functions}
  \begin{description}
  \item[\Rfunction{dir}, \Rfunction{read.table} (and friends),
    \Rfunction{scan}] List files, input data.
  \item[\Rfunction{c}, \Rfunction{factor}, \Rfunction{data.frame},
    \Rfunction{matrix}] Create objects.
  \item[\Rfunction{summary}, \Rfunction{table}, \Rfunction{xtabs}]
    Summarize, cross-tabulate variables.
  \item[\Rfunction{t.test}, \Rfunction{aov}, \Rfunction{lm},
    \Rfunction{anova}, \Rfunction{chisq.test}] Compare groups.
  \item[\Rfunction{dist}, \Rfunction{hclust}] Cluster data.
  \item[\Rfunction{plot}] Visualize data.
  \item[\Rfunction{lapply}, \Rfunction{sapply}, \Rfunction{mapply},
    \Rfunction{aggregate}] Apply a function to each element of a list or
    vector.
  \item[\Rfunction{ls}, \Rfunction{str}] List objects and their
    structure.
  \item[\Rfunction{library}, \Rfunction{search}] Attach to
    or describe the library search path.
  \end{description}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Packages}
  \begin{description}
  \item[Base] \Rpackage{base}, \Rpackage{stats}, \Rpackage{graphics},
    \ldots
  \item[Recommended] \Rpackage{lattice}, \ldots
  \item[Contributed] \Rpackage{data.table}, \Rpackage{XML},
    \Rpackage{biglm}, \ldots
  \end{description}
  \begin{itemize}
  \item Install a contributed package
<<biocLite, eval=FALSE>>=
source("http://bioconductor.org/biocLite.R")
biocLite("data.table")
@ 
  \item Use during a session
<<library, eval=FALSE>>=
library(lattice)
@ 
  \end{itemize}
%% 
\end{frame}

\begin{frame}[fragile]
  \frametitle{From script to collaboration}
  Increasingly complicated tasks
  \begin{enumerate}
  \item Commands entered at the prompt
  \item Scripts and functions saved in \texttt{.R} files
  \item \texttt{.R} files and documentation ordered in packages
\begin{verbatim}
% dir MyPackage
data/ NAMESPACE DESCRIPTION man/ R/ vignettes/
\end{verbatim}
  \item Packages shared with colleagues
  \end{enumerate}
  Net result: sophisticated, highly reproducible research
\end{frame}

\begin{frame}[fragile]
  \frametitle{HELP!}
<<help, eval=FALSE>>=
help.start()
?t.test
vignette("datatable-faq")
@ 
\begin{itemize}
\item Books and training resources
\item \R{} web site and mailing
  list\footnote{\url{http://r-project.org}}
\item
  StackOverflow\footnote{\url{http://stackoverflow.com/questions/tagged/r}}
\end{itemize}
\end{frame}

\section{Bioconductor}

\begin{frame}{\Bioconductor: A short history}
  \begin{columns}[t]
    \column{.5\textwidth}
    Then
    \begin{itemize}
    \item Founded 2001
    \item Analysis and \emph{comprehension} of high throughput genomic
      data
    \item Initial focus: microarrays
    \item Reproducibility, statistical analysis, computation
    \end{itemize}

    \column{.5\textwidth}
    Now
    \begin{itemize}
    \item $>670$ software packages
    \item World-wide contributions
    \item Sequence analysis, microarrays, systems biology, flow cytometry,
      \ldots
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}
  \includegraphics[width=\textwidth, height=!]{Bioc_website}
\end{frame}

\begin{frame}[fragile]
  \frametitle{\Bioconductor: A short history}
  \begin{center}
    \includegraphics[height=.18\textheight, width=!]{access_counts}
    \par
    \includegraphics[height=.67\textheight, width=!]{access_map}
  \end{center}
\end{frame}

\begin{frame}{Sequence Analysis (many packages!)}
\begin{tabular}{lp{.65\textwidth}}
  I/O & \Biocpkg{ShortRead} (FASTQ), \Biocpkg{Rsamtools}
  (BAM), \Biocpkg{rtracklayer} (GFF, WIG, BED),
  \Biocpkg{VariantAnnotation} (VCF), \ldots\\

  Representation & \Biocpkg{IRanges}, \Biocpkg{GenomicRanges},
  \Biocpkg{GenomicFeatures}, \Biocpkg{Biostrings},
  \Biocpkg{BSgenome}, \ldots\\


  Annotation & \Biocpkg{GenomicFeatures}, \Biocpkg{biomaRt}, 
  \Biocpkg{AnnotationHub}, \ldots.\\

  Alignment & \Biocpkg{gmapR}, \Biocpkg{Rsubread}, \Biocpkg{Biostrings}, 
  \ldots\\

  Visualization & \Biocpkg{ggbio}, \Biocpkg{Gviz}, \ldots\\

  RNA-seq & \Biocpkg{DESeq}, \Biocpkg{edgeR}, \Biocpkg{DEXSeq}, 
  \Biocpkg{cummeRbund}, \ldots \\

  ChIP-seq & \Biocpkg{DiffBind}, \Biocpkg{ChIPpeakAnno}, \ldots \\
  
  Variants & \Biocpkg{VariantAnnotation}, \Biocpkg{VariantTools}, \ldots \\
  
  Motifs & \Biocpkg{MotifDb}, \Biocpkg{seqLogo}, \ldots\\

  Work flows & \Biocpkg{QuasR},  \ldots \\

  \ldots & \ldots
\end{tabular}
\end{frame}

<<setup, echo=FALSE>>=
library(ShortRead)
op <- options(showHeadLines=3, showTailLines=1)
@ 

\begin{frame}[fragile]
  \frametitle{Classes, generics and methods}
<<readFastq>>=
library(ShortRead)
fq <- 
  readFastq("~/BigData/fastq/SRR031724_1_subset.fastq")
fq          # 'S4' class
sread(fq)   # 'generic' and 'method'; another S4 class
@ 
\end{frame}

\begin{frame}[fragile]
  \frametitle{HELP!}
  \begin{itemize}
  \item Use tab completion to find help on \emph{generics} and \emph{methods}
<<S4-help, eval=FALSE>>=
?sread
?"reverseComplement<tab>"  # tab key for completions!
?"reverseComplement,DNAStringSet-method"
@ 
  \item Discover available functions and their definition.
<<S4-discovery, eval=FALSE>>=
showMethods("reverseComplement")
showMethods(class="DNAStringSet", where=search())
selectMethod("reverseComplement", "DNAStringSet")
@ 
  \end{itemize}
\end{frame}

\begin{frame}{Acknowledgements}
  \begin{columns}[t]
    \column{.35\textwidth}
    \Bioconductor{} core
    \begin{itemize}
    \item Vince Carey
    \item Wolfgang Huber
    \item Robert Gentleman
    \item Rafael Irizzary
    \item Sean Davis
    \item Kasper Hansen
    \end{itemize}
    \column{.65\textwidth}
    \Bioconductor{} team
    \begin{itemize}
    \item Marc Carlson (annotation)
    \item Valerie Obenchain (variants, ranges)
    \item Herv\'e Pag\`es (ranges, strings)
    \item Paul Shannon (systems biology)
    \item Dan Tenenbaum (web, build)
    \end{itemize}
  \end{columns}
  \par\bigskip
  And the \Bioconductor{} community!
\end{frame}

\end{document}
