%
\documentclass[16pt]{article}
%
% modified from default setup for knitr
%
\usepackage[]{graphicx}
\usepackage[]{color}
\usepackage{framed}
% recommended with 'knitr'
\usepackage{alltt}
\usepackage{mathtools}
\usepackage[sc]{mathpazo}
\usepackage{geometry}
\geometry{verbose, tmargin=2.5cm, bmargin=2.5cm,
  lmargin=2.5cm, rmargin=2.5cm}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\usepackage{url}
\usepackage{hyperref}
\hypersetup{unicode=true, pdfusetitle}
\hypersetup{bookmarks=true, bookmarksnumbered=true}
\hypersetup{bookmarksopen=true, bookmarksopenlevel=2}
\hypersetup{breaklinks=false, pdfborder={0 0 1}}
\hypersetup{backref=false}
\hypersetup{colorlinks=true}
\definecolor{myDarkBlue}{rgb}{0, 0, 0.5}
\hypersetup{linkcolor=myDarkBlue}
\hypersetup{citecolor=myDarkBlue}
\hypersetup{pdfstartview={XYZ null null 1}}
%
% Allows the use of OpenType fonts
% Needs to be placed after maths font packages
% particularly 'euler'
\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
% Main text font
\setmainfont[Numbers={Lowercase}]{Desyrel}
\setsansfont[Scale=MatchLowercase]{Latin Modern Sans}
\setmonofont[Scale=MatchLowercase]{Inconsolata}
%
% other useful additions
%
% to keep floats in same section
\usepackage[section]{placeins}
% for tables > 1 page
\usepackage{longtable}
%% for nice tables
\usepackage{booktabs}
\usepackage{multirow}
%
%----------------------------------------
%
\begin{document}

% knitr chunks
<<setup, include=FALSE>>=
library(knitr)
### Set global chunk options
opts_chunk$set(
    eval=TRUE,
    ## text results
    echo=TRUE,
    results=c('markup', 'asis', 'hold', 'hide')[1],
    collapse=FALSE,
    warning=TRUE, message=TRUE, error=TRUE,
    split=FALSE, include=TRUE, strip.white=TRUE,
    ## code decoration
    tidy=FALSE, prompt=FALSE, comment='##',
    highlight=TRUE, size='normalsize',
    background=c('#F7F7F7', colors()[479], c(0.1, 0.2, 0.3))[1],
    ## cache
    cache=FALSE,
    ## plots
    fig.path=c('figure', 'figure/minimal-'),
    fig.keep=c('high', 'none', 'all', 'first', 'last')[1],
    fig.align=c('center', 'left', 'right', 'default')[1],
    fig.show=c('hold', 'asis', 'animate', 'hide')[1],
    dev=c('pdf', 'png', 'tikz')[1],
    fig.width=7, fig.height=7, #inches
    fig.env=c('figure', 'marginfigure')[1],
    fig.pos=c('', 'h', 't', 'b', 'p', 'H')[1])
### Set R options
options(formatR.arrow=TRUE, width=60)
knit_hooks$set(inline = function(x) {
## if (is.numeric(x)) return(knitr:::format_sci(x, 'latex'))
    highr::hi_latex(x)
})
## uncomment below to change theme
## knit_theme$get()
## opts_knit$set(out.format='latex')
## thm1 <- knit_theme$get('acid')
## knit_theme$set(thm1)
@
% knitr read chunks
<<readChunks, include=FALSE>>=
read_chunk('sa.R')
@

\title{Scratch Assay}
\author{Eric C Woolf \& Chris Dardis}

\maketitle
% page numbers appear top-right
\pagestyle{headings}
\tableofcontents

\section{Aim}

Investigate whether migration of the B16-F1-Luc2-BR2 melanoma cell line is impaired in the presence of \emph{beta}-hydroxybutyrate (BHB).

\section{Reagents}

\begin{itemize}
\item \textbf{B16-F1-Luc2-BR2} cells.\\
 These were generated as follows:
  \begin{itemize}
  \item B16 cells were obtained from American Type Culture Collection (ATCC).
  \item To facilitate quantitative measurement of tumor growth, they were modified as described previously \cite{Abdel2012}. \\
    The cells were stably transfected with the gene encoding luc2 (luciferase) using the pGL4.51 [luc2/CMV/Neo] vector (Promega Corp, Madison, WI) and FuGENEH 6 Transfection Reagent (Roche Applied Science, Indianapolis, IN) following conditions specified by the manufacturer.
  \item They were then injected into the right ventricle of a mouse.\\
    These animals were sacraficed when bioluminescence was detected in the brain.
  \item Cells metastatic to the brain were recovered put into culture.
  \end{itemize}
  \item (R)-(-)-3-hydroxy butyric acid sodium salt (Sigma-Aldrich, St. Louis, MO).
\item Media: DMEM (Gibco \textregistered) +10\% FCS +
  600 ug/mL G418 + 1x glutamine. pH 7.4.\\
  FCS = fetal calf serum.
\item PBS = phosphate buffered saline.
\end{itemize}

\section{Equipment}
\begin{itemize}
  \item 6-well plastic culture plate (Falcon\textregistered)
  \item Multi-channel pipette
  \item Sharpie\textregistered permanent marker
  \item Image J software. Freely available from \url{http://imagej.nih.gov/ij/}.
\end{itemize}

\section{Methods}

\subsection{Preparation}

Incubate the cells at 37 C, in 5\% CO2, overnight.

\subsection{-1 Hours}

\begin{enumerate}
  \item Ensure the cells have reached 95\% confluency.
  \item Attach 3 consecutive 200uL pipette tips to athe multi-channel pipetter and 'scratch' each well.
  \item Draw a line with the marker perpendicular to the scratches in each well.
  \item Gently rinse wells with PBS and replace media with either:
    \begin {itemize}
    \item DMEM + 10\% FCS with normal saline.
    \item DMEM + 10\% FCS with 10mmol/L BHB.
    \end{itemize}
\end{enumerate}

\subsection{0, 3, 6, 20 hours}

\begin{enumerate}
  \item For each well: take a photograph above and below the perpendicular 'scratch' line.
  \item Return the cells to the incubator.
\end{enumerate}

\subsection{Analysis}
\begin{enumerate}
  \item Select the 'scratch area' using the 'free hand' tool.
  \item Obtain the 'area density' of the scratch area. This reflects the distance between the cellular elements on either side of the original scratch. As the cells migrate, this decreases over time.
\end{enumerate}

\section{Results}

The key to the data is shown in table~\ref{tab:key}.

\subsection{Key}

<<Key, echo=FALSE, results="hide">>=
@

<<Show key, results="asis">>=
@

Results of the image density for each well and scratch, for each time point (0, 3, 6 and 20 hours) are given below. A sample of the data to indicate the layout is given in table~\ref{tab:data}.

\subsection{Data}

<<Data, echo=FALSE, results="hide">>=
@

<<Show data, results="asis">>=
@

\subsection{t Tests}

We assume that the density is normally distributed at each time~point.

The results of a t-test performed at each time~point are shown in table~\ref{tab:tt}.

For the calculation, we perform a one-sided test. That is, we test whether cell migration was slower i.e. we test whether the density is lower in the wells that were incubated without BHB.

We assume unequal variances for the samples, and the test is cacluated using the standard Welch-Satterthwaite equation:

\begin{equation}
  t = \frac{\bar{x_1} - \bar{x_2}}{
    \sqrt{\frac{s^2_1}{n_1} + \frac{s^2_2}{n_2}}}
\end{equation}

where $\bar{x}$ is the mean, $s^2$ is the variance and $n$ is the size of each sample. The null hypothesis is that the difference in means, $\bar{x_1} - \bar{x_2} = 0$.

The degrees of freedom for the test is calculated from:
\begin{equation}
  df = \frac{ (\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2})^2}{
    (\frac{s_1^2}{n_1})^2 / (n_1 - 1) + (\frac{s_2^2}{n_2})^2 / (n_2 - 1)}
\end{equation}

<<t Tests, results="asis">>=
@

\subsection{Standard error}

For plotting, we first calculate the standard error at each time~point:

\begin{equation}
  SE_{\bar{x}} = \frac{s}{\sqrt{n}}
\end{equation}

where $s$ is the sample standard deviation ($s=\sqrt{\mathrm{variance}}$).

<<Standard error>>=
@

\subsection{Density over time}

Here we plot the change in density over time.

A linear decrease over time is evident. The density of the wells with BHB begins at a slightly higher value, but the difference becomes more pronounced over time.

<<Density over time>>=
@

\subsection{Express as percentage of starting value}

A more intuitive graph expressed the density as a percentage of the starting value for each sample. Thus time=0 is 100\% and subsequent values are taken in comparison to this.

The calculations are shown below. Again, we calculate the standard errors for each timepoint by treatment group.

<<Express as percentage of starting value>>=
@

\subsection{Check t-tests again}

t-tests are again significant as we can see.

<<Check t-tests again, results="asis">>=
@

\subsection{Plot of percentage of starting value}

Again we plot mean and standard error, this time in terms of percentage of the starting value.

<<Plot of percentage of starting value, results="asis">>=
@

\subsection{Linear model}

As the decrease in density appears to be linear over time and the standard errors are similar at each time~point, a simple linear model appears a good approximation:

\begin{equation}
  Y_i = \beta_0 + \beta_1X_1 + \beta_2X_2, \quad i=1,2,...,n
\end{equation}

The estimated coefficients of such a model and their associated Wald statistics are shown in table~\ref{tab:lm}.

We proceed to an analysis of variane, shown in table~\ref{tab:anova}. While time is the more important factor, treatment is also clearly hightly significant.

<<Linear model, results="asis">>=
@

\section{Conclusions}

In the presence of BHB, there is impaired migration of these cells.\\
This is apparent from a t-test at 20 hours ($p=0.01$).\\
This is emphasised by comparing linear models with and without treatment ($p=0.0006$).

\appendix

\Large{Appendix}

\section{Images}

\setlength{\tabcolsep}{1pt}

\begin{figure}[ht]
  \centering
  \begin{tabular}{lccc}
    \multirow{2}{*}{\LARGE 0h} &
    \includegraphics{w1t0la} &
    \includegraphics{w1t0ca} &
    \includegraphics{w1t0ra} \\
    &
    \includegraphics{w1t0lb} &
    \includegraphics{w1t0cb} &
    \includegraphics{w1t0rb} \\
    \multirow{2}{*}{\LARGE 3h} &
    \includegraphics{w1t3la} &
    \includegraphics{w1t3ca} &
    \includegraphics{w1t3ra} \\
    &
    \includegraphics{w1t3lb} &
    \includegraphics{w1t3cb} &
    \includegraphics{w1t3rb} \\
    \multirow{2}{*}{\LARGE 6h} &
    \includegraphics{w1t6la} &
    \includegraphics{w1t6ca} &
    \includegraphics{w1t6ra} \\
    &
    \includegraphics{w1t6lb} &
    \includegraphics{w1t6cb} &
    \includegraphics{w1t6rb} \\
    \multirow{2}{*}{\LARGE 20h} &
    \includegraphics{w1t20la} &
    \includegraphics{w1t20ca} &
    \includegraphics{w1t20ra} \\
    &
    \includegraphics{w1t20lb} &
    \includegraphics{w1t20cb} &
    \includegraphics{w1t20rb} \\
  \end{tabular}
  \caption{Mock - well 1}
\end{figure}

\begin{figure}[ht]
  \centering
  \begin{tabular}{lccc}
    \multirow{2}{*}{\LARGE 0h} &
    \includegraphics{w2t0la} &
    \includegraphics{w2t0ca} &
    \includegraphics{w2t0ra} \\
    &
    \includegraphics{w2t0lb} &
    \includegraphics{w2t0cb} &
    \includegraphics{w2t0rb} \\
    \multirow{2}{*}{\LARGE 3h} &
    \includegraphics{w2t3la} &
    \includegraphics{w2t3ca} &
    \includegraphics{w2t3ra} \\
    &
    \includegraphics{w2t3lb} &
    \includegraphics{w2t3cb} &
    \includegraphics{w2t3rb} \\
    \multirow{2}{*}{\LARGE 6h} &
    \includegraphics{w2t6la} &
    \includegraphics{w2t6ca} &
    \includegraphics{w2t6ra} \\
    &
    \includegraphics{w2t6lb} &
    \includegraphics{w2t6cb} &
    \includegraphics{w2t6rb} \\
    \multirow{2}{*}{\LARGE 20h} &
    \includegraphics{w2t20la} &
    \includegraphics{w2t20ca} &
    \includegraphics{w2t20ra} \\
    &
    \includegraphics{w2t20lb} &
    \includegraphics{w2t20cb} &
    \includegraphics{w2t20rb} \\
  \end{tabular}
  \caption{Mock - well 2}
\end{figure}

\begin{figure}[ht]
  \centering
  \begin{tabular}{lccc}
    \multirow{2}{*}{\LARGE 0h} &
    \includegraphics{w3t0la} &
    \includegraphics{w3t0ca} &
    \includegraphics{w3t0ra} \\
    &
    \includegraphics{w3t0lb} &
    \includegraphics{w3t0cb} & & \\
    \multirow{2}{*}{\LARGE 3h} &
    \includegraphics{w3t3la} &
    \includegraphics{w3t3ca} &
    \includegraphics{w3t3ra} \\
    &
    \includegraphics{w3t3lb} &
    \includegraphics{w3t3cb} & & \\
    \multirow{2}{*}{\LARGE 6h} &
    \includegraphics{w3t6la} &
    \includegraphics{w3t6ca} &
    \includegraphics{w3t6ra} \\
    &
    \includegraphics{w3t6lb} &
    \includegraphics{w3t6cb} &
    \includegraphics{w3t6rb} \\
    \multirow{2}{*}{\LARGE 20h} &
    \includegraphics{w3t20la} &
    \includegraphics{w3t20ca} &
    \includegraphics{w3t20ra} \\
    &
    \includegraphics{w3t20lb} &
    \includegraphics{w3t20cb} &
    \includegraphics{w3t20rb} \\
  \end{tabular}
  \caption{Mock - well 1}
\end{figure}

\begin{figure}[ht]
  \centering
  \begin{tabular}{lccc}
    \multirow{2}{*}{\LARGE 0h} &
    \includegraphics{Bw1t0la} &
    \includegraphics{Bw1t0ca} &
    \includegraphics{Bw1t0ra} \\
    &
    \includegraphics{Bw1t0lb} &
    \includegraphics{Bw1t0cb} &
    \includegraphics{Bw1t0rb} \\
    \multirow{2}{*}{\LARGE 3h} &
    \includegraphics{Bw1t3la} &
    \includegraphics{Bw1t3ca} &
    \includegraphics{Bw1t3ra} \\
    &
    \includegraphics{Bw1t3lb} &
    \includegraphics{Bw1t3cb} &
    \includegraphics{Bw1t3rb} \\
    \multirow{2}{*}{\LARGE 6h} &
    \includegraphics{Bw1t6la} &
    \includegraphics{Bw1t6ca} &
    \includegraphics{Bw1t6ra} \\
    &
    \includegraphics{Bw1t6lb} &
    \includegraphics{Bw1t6cb} &
    \includegraphics{Bw1t6rb} \\
    \multirow{2}{*}{\LARGE 20h} &
    \includegraphics{Bw1t20la} &
    \includegraphics{Bw1t20ca} &
    \includegraphics{Bw1t20ra} \\
    &
    \includegraphics{Bw1t20lb} &
    \includegraphics{Bw1t20cb} &
    \includegraphics{Bw1t20rb} \\
  \end{tabular}
  \caption{BHB - well 1}
\end{figure}

\begin{figure}[ht]
  \centering
  \begin{tabular}{lccc}
    \multirow{2}{*}{\LARGE 0h} &
    \includegraphics{Bw2t0la} &
    \includegraphics{Bw2t0ca} &
    \includegraphics{Bw2t0ra} \\
    &
    \includegraphics{Bw2t0lb} &
    \includegraphics{Bw2t0cb} &
    \includegraphics{Bw2t0rb} \\
    \multirow{2}{*}{\LARGE 3h} &
    \includegraphics{Bw2t3la} &
    \includegraphics{Bw2t3ca} &
    \includegraphics{Bw2t3ra} \\
    &
    \includegraphics{Bw2t3lb} &
    \includegraphics{Bw2t3cb} &
    \includegraphics{Bw2t3rb} \\
    \multirow{2}{*}{\LARGE 6h} &
    \includegraphics{Bw2t6la} &
    \includegraphics{Bw2t6ca} &
    \includegraphics{Bw2t6ra} \\
    &
    \includegraphics{Bw2t6lb} &
    \includegraphics{Bw2t6cb} &
    \includegraphics{Bw2t6rb} \\
    \multirow{2}{*}{\LARGE 20h} &
    \includegraphics{Bw2t20la} &
    \includegraphics{Bw2t20ca} &
    \includegraphics{Bw2t20ra} \\
    &
    \includegraphics{Bw2t20lb} &
    \includegraphics{Bw2t20cb} &
    \includegraphics{Bw2t20rb} \\
  \end{tabular}
  \caption{BHB - well 2}
\end{figure}

\begin{figure}[ht]
  \centering
  \begin{tabular}{lccc}
    \multirow{2}{*}{\LARGE 0h} &
    \includegraphics{Bw3t0la} &
    \includegraphics{Bw3t0ca} &
    \includegraphics{Bw3t0ra} \\
    &
    \includegraphics{Bw3t0lb} &
    \includegraphics{Bw3t0cb} &
    \includegraphics{Bw3t0rb} \\
    \multirow{2}{*}{\LARGE 3h} &
    \includegraphics{Bw3t3la} &
    \includegraphics{Bw3t3ca} &
    \includegraphics{Bw3t3ra} \\
    &
    \includegraphics{Bw3t3lb} &
    \includegraphics{Bw3t3cb} &
    \includegraphics{Bw3t3rb} \\
    \multirow{2}{*}{\LARGE 6h} &
    \includegraphics{Bw3t6la} &
    \includegraphics{Bw3t6ca} &
    \includegraphics{Bw3t6ra} \\
    &
    \includegraphics{Bw3t6lb} &
    \includegraphics{Bw3t6cb} &
    \includegraphics{Bw3t6rb} \\
    \multirow{2}{*}{\LARGE 20h} &
    \includegraphics{Bw3t20la} &
    \includegraphics{Bw3t20ca} &
    \includegraphics{Bw3t20ra} \\
    &
    \includegraphics{Bw3t20lb} &
    \includegraphics{Bw3t20cb} &
    \includegraphics{Bw3t20rb} \\
  \end{tabular}
  \caption{BHB - well 3}
\end{figure}

\begin{figure}[ht]
  \centering
  \begin{tabular}{lccc}
    \multirow{2}{*}{\LARGE Mock} &
    \includegraphics{w1t20la} &
    \includegraphics{w1t20ca} &
    \includegraphics{w1t20ra} \\
    &
    \includegraphics{w1t20lb} &
    \includegraphics{w1t20cb} &
    \includegraphics{w1t20rb} \\
    \multirow{2}{*}{\LARGE BHB} &
    \includegraphics{Bw1t20la} &
    \includegraphics{Bw1t20ca} &
    \includegraphics{Bw1t20ra} \\
    &
    \includegraphics{Bw1t20lb} &
    \includegraphics{Bw1t20cb} &
    \includegraphics{Bw1t20rb} \\
  \end{tabular}
  \caption{Images at 20h}
\end{figure}

\section{Key}

<<Key, tidy=TRUE>>=
@

\section{Data}

<<Data, tidy=TRUE>>=
@

\bibliographystyle{plain}
\begin{thebibliography}{99}

\bibitem{Abdel2012}
 Abdelwahab, Mohammed G., et al. The ketogenic diet is an effective adjuvant to radiation therapy for the treatment of malignant glioma. PloS one 7.5 (2012): e36197.

\end{thebibliography}

\end{document}