\documentclass{article}
\usepackage{Sweave}
\begin{document}

\title{Generating weights to score pathway activity for Dressman et al.}
\author{VJ Carey}

\section{Introduction}

The \textit{dressCheck} package includes \texttt{pwLines}, a
retrieval of GSE3151 based on a standard GEOquery call.
The labeling of pathways perturbed is taken from the GEO web
page and merged on to the phenoData.
\begin{Schunk}
\begin{Sinput}
> library(dressCheck)
> data(pwLines)
\end{Sinput}
\end{Schunk}

\section{The Src pathway}

We have the Src-associated genes from Bild et al.
\begin{Schunk}
\begin{Sinput}
> data(Src.probes)
\end{Sinput}
\end{Schunk}
Reduce the expression data to these probes,
and then to the controls and Src-perturbed samples.
\begin{Schunk}
\begin{Sinput}
> src = pwLines[Src.probes, ]
> src = src[, src$perturb %in% c("GFP", "Src")]
> esrc = exprs(src)
\end{Sinput}
\end{Schunk}
We center and scale genes:
\begin{Schunk}
\begin{Sinput}
> scesrc = t(scale(t(esrc)))
\end{Sinput}
\end{Schunk}
Here is the heatmap:
\begin{Schunk}
\begin{Sinput}
> heatmap(scesrc)
\end{Sinput}
\end{Schunk}
\includegraphics{doPW2-doaa}
We use SVD to obtain the weights, saved to \texttt{swt}:
\begin{Schunk}
\begin{Sinput}
> swt = svd(scesrc)$u[, 1]
> names(swt) = rownames(scesrc)
> sco = t(esrc) %*% swt
\end{Sinput}
\end{Schunk}
Show the reweighted combinations:
\begin{Schunk}
\begin{Sinput}
> plot(sco, col = ifelse(src$perturb == "GFP", "green", "red"))
> table(sco > 0, src$pert)
\end{Sinput}
\begin{Soutput}
        GFP Src
  FALSE  10   7
\end{Soutput}
\begin{Sinput}
> srcWts = swt
> save(srcWts, file = "srcWts.rda")
\end{Sinput}
\end{Schunk}
\includegraphics{doPW2-doso}

\section{The E2F3 pathway}

We have the E2F3-associated genes from Bild et al.
\begin{Schunk}
\begin{Sinput}
> data(E2F3sig.probes)
\end{Sinput}
\end{Schunk}
Reduce the expression data to these probes,
and then to the controls and Src-perturbed samples.
\begin{Schunk}
\begin{Sinput}
> e2f3 = pwLines[E2F3sig.probes, ]
> e2f3 = e2f3[, e2f3$perturb %in% c("GFP", "E2F3")]
> ee2f3 = exprs(e2f3)
\end{Sinput}
\end{Schunk}
We center and scale genes:
\begin{Schunk}
\begin{Sinput}
> scee2f3 = t(scale(t(ee2f3)))
\end{Sinput}
\end{Schunk}
Here is the heatmap:
\begin{Schunk}
\begin{Sinput}
> heatmap(scee2f3)
\end{Sinput}
\end{Schunk}
\includegraphics{doPW2-doaa2}
We use SVD to obtain the weights, saved to \texttt{ewt}:
\begin{Schunk}
\begin{Sinput}
> ewt = svd(scee2f3)$u[, 1]
> names(ewt) = rownames(ee2f3)
> scoe = t(ee2f3) %*% ewt
\end{Sinput}
\end{Schunk}
Show the reweighted combinations:
\begin{Schunk}
\begin{Sinput}
> plot(scoe, col = ifelse(e2f3$perturb == "GFP", "green", "red"))
> table(scoe > median(scoe), e2f3$pert)
\end{Sinput}
\begin{Soutput}
        E2F3 GFP
  FALSE    9   1
  TRUE     0   9
\end{Soutput}
\begin{Sinput}
> e2f3Wts = ewt
> save(e2f3Wts, file = "e2f3Wts.rda")
\end{Sinput}
\end{Schunk}
\includegraphics{doPW2-doso2}

\end{document}
