\documentclass[10pt,xcolor=x11names,compress]{beamer}

\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage[round]{natbib}
\renewcommand{\newblock}{} % Get natbib and beamer working together: http://tex.stackexchange.com/questions/1969/beamer-and-natbib

%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{jtGWAS}

\newcommand{\R}{\texttt{R}}
\newcommand{\pkgname}{\texttt{jtGWAS}}
\newcommand{\Rcpp}{\texttt{Rcpp}}
\newcommand{\openmp}{\texttt{OpenMP}}

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[frame number]

\setbeamertemplate{enumerate item}{\insertenumlabel}
\setbeamertemplate{enumerate subitem}{\alph{enumii}.}


\begin{document}
<<setup1, include=FALSE>>=
require(knitr)
@

<<setup2, include=FALSE>>=
options(width=80)  # make the printing fit on the page
set.seed(1121)     # make the results repeatable
stdt<-date()
@

\begin{frame}
	\title{\pkgname}
	\subtitle{Efficient Jonckheere-Terpstra Test Statistics}
	\date{2017-08-14}
	\titlepage
\end{frame}


\begin{frame}{Outline}
	\tableofcontents[]
\end{frame}


\section{Introduction}
\begin{frame}{Introduction}
  \begin{itemize}
    \item This document provides an example for using the \pkgname{} package to calculate the Jonckheere-Terpstra test statistics for large data sets (multiple markers and genome-wide SNPs) commonly encountered in GWAS.
    \item The calculation of the standardized test statistic employs the null variance equation as defined by \citet[eq. 6.19]{HollanderBook} to account for ties in the data.
    \item The major algorithm in this package is written in C++, which is ported to \R{} by \Rcpp{}, to facilitate fast computation. 
	\item Features of this package include:
      \begin{enumerate}
        \item \openmp{} supported parallelization
        \item Customized output of top $m$ significant SNPs for each marker
		\item $O(N\times\log(N))$ computational complexity (where $N$ is the number of the samples)
      \end{enumerate}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{jtGWAS}
<<function mutiple threads, eval=FALSE>>=
res <- jtGWAS(X, G, outTopN=15, numThreads=1, standardized=TRUE)
@
Function aguments:\\
\begin{description}
	\item[\texttt{X}:] Matrix of marker levels, with sample IDs as row names and marker IDs as column names.
 	\item[\texttt{G}:] Matrix of genotypes, with sample IDs as row names and SNP IDs as column names.
 	\item[\texttt{outTopN}:] Number of top statistics to return (i.e., the largest $n$ standardized statistics). The default value is 15. If \texttt{outTopN} is set to \texttt{NA}, all results will be returned.
	\item[\texttt{numThreads}:] Number of threads to use for parallel computation. The default value is 1 (sequential computation).
	\item[\texttt{standardized}:] A boolean to specify whether to return standardized statistics or non-standardized statistics. The default value is \texttt{TRUE}, returning standardized statistics.
\end{description}
Users may wish to consider the \texttt{dplyr::recode()} function for converting non-numeric group indices into ordinal values for argument \texttt{G}.
\end{frame}


\begin{frame}[fragile]{Returned Values}
Function returns:
\begin{description}
 	\item[\texttt{J}:] A matrix of standardized/non-standardized Jonckheere Terpstra test statistics, depending on option \texttt{standardized}, with column names from input \texttt{X}. If \texttt{outTopN} is not \texttt{NA}, results are sorted within each column.
	\item[\texttt{gSnipID}:] If \texttt{outTopN} is not \texttt{NA}, this is a matrix of column names from \texttt{G} associated with top standardized Jonckheere Terpstra test statistics from \texttt{J}. Otherwise this is an unsorted vector of column names from input \texttt{G}.
\end{description}
\end{frame}


\section{Example}
\begin{frame}[fragile]{Simulate Data}
  \begin{enumerate}
  \item Define the number of markers, patients, and SNPs:
<<inputPara,size='tiny'>>=
num_patient	<- 100
num_marker 	<- 4
num_SNP 	<- 50
@ 
  \item Create two matrices containing marker levels and genotype information.
    \begin{enumerate}
      \item \texttt{X\_pat\_mak} contains the patients' marker levels.
      \item \texttt{G\_pat\_SNP} contains the patients' genotypes.
    \end{enumerate}	

<<markers_levels_geno_types,size='tiny'>>=
set.seed(12345);
X_pat_mak <- matrix(rnorm(num_patient*num_marker),
                    num_patient,
                    num_marker)
G_pat_SNP <- matrix(rbinom(num_patient*num_SNP,2,0.5),
                    num_patient,
                    num_SNP)
colnames(X_pat_mak) <- colnames(X_pat_mak, do.NULL = FALSE, prefix = "Mrk:" )
colnames(G_pat_SNP) <- colnames(G_pat_SNP, do.NULL = FALSE, prefix = "SNP:" )
@ 
  \end{enumerate}
\end{frame}


\begin{frame}[fragile]{Load Package}
Load \pkgname{} (after installing its dependent packages):
<<loadpkg>>=
library(jtGWAS)
@ 
\end{frame}


\begin{frame}[fragile]{Example Execution}
<<exp3, results='hide'>>=
JTStat <- jtGWAS(X_pat_mak, G_pat_SNP, outTopN=10)
summary(JTStat, marker2Print=1:4, SNP2Print=1:5)
@
<<exp4, echo=FALSE, size='tiny'>>=
summary(JTStat, marker2Print=1:4, SNP2Print=1:5)
@
\end{frame}

\begin{frame}[fragile]{Example Execution: Statistics in the Summary}
<<exp5, results='hide'>>=
summary(JTStat, marker2Print=1:4, SNP2Print=1:5, printP=FALSE)
@
<<exp6, echo=FALSE, size='tiny'>>=
summary(JTStat, marker2Print=1:4, SNP2Print=1:5, printP=FALSE)
@
\end{frame}

\begin{frame}[fragile]{Example Execution: Sorting in the Summary}
<<exp7, results='hide'>>=
JTAll <- jtGWAS(X_pat_mak, G_pat_SNP, outTopN=NA)
summary(JTAll, marker2Print=1:4, SNP2Print=1:3)
summary(JTAll, marker2Print=1:4, outTopN=3)
@
<<exp8, echo=FALSE, size='tiny'>>=
summary(JTAll, marker2Print=1:4, SNP2Print=1:3)
summary(JTAll, marker2Print=1:4, outTopN=3)
@
\end{frame}

\section*{}
\begin{frame}[fragile]{References}
% {\footnotesize
\begin{thebibliography}{9}
\setbeamertemplate{bibliography item}[text]
\bibitem[Hollander and Wolfe(1999)]{HollanderBook}
	Hollander, M. and Wolfe, D. A.,
	\emph{Nonparametric Statistical Methods}.
        New York, Wiley,
        2nd edition,
	1999.
\end{thebibliography}
% }
\end{frame}


\section{Session Information}
\begin{frame}[fragile]{Session Information}
<<sessinfo, echo=FALSE, include=TRUE, results='asis'>>=
toLatex(sessionInfo(), locale=FALSE)
@ 
<<times, echo=FALSE, include=TRUE>>=
print(paste("Start Time",stdt))
print(paste("End Time  ",date()))
@ 
\end{frame}

\end{document}























