%
% NOTE -- ONLY EDIT THE .Rnw FILE!!!  The .tex file is
% likely to be overwritten.
%
% \VignetteIndexEntry{HOWTO Get HTML Output}
% \VignetteDepends{annotate, hgu95av2}
% \VignetteKeywords{Expression Analysis, Annotation}
%\VignettePackage{annotate}
\documentclass{article}

\newcommand{\Rfunction}[1]{{\texttt{#1}}}
\newcommand{\Rmethod}[1]{{\texttt{#1}}}

\newcommand{\Robject}[1]{{\texttt{#1}}}
\newcommand{\Rpackage}[1]{{\textit{#1}}}
\newcommand{\Rclass}[1]{{\textit{#1}}}

\usepackage{hyperref}

\usepackage[authoryear,round]{natbib}
\usepackage{times}

\bibliographystyle{plainnat}

\usepackage{hyperref}

\begin{document}
\title{HowTo: get pretty HTML output for my gene list}
\author{R. Gentleman}
\maketitle{}

\section{Overview}

This document demonstrates how you can get a nice--ish annotated html
(web--page) output for the genes or probes that you have selected.
To do this you will need both the \Rpackage{Biobase} and \Rpackage{annotate}
packages. You will also need to obtain annotation data for the
experiment itself. In the example here the data come from Affymetrix
U95A chips and that annotation is supplied by the Bioconductor
Project.

First we load the \Rpackage{annotate} package (this will automatically load
\Rpackage{Biobase}  as well) and then obtain our test data.
We have arbitrarily selected 15 genes of {\em interest}, you will have
obtained your list in some meaningful way!

<<>>=
library("annotate")
library("hgu95av2")
data(eset)
igenes <- geneNames(eset)[245:260]
igenes
@

Now, given this set of genes (or Affymetrix identifiers) we would like
to provide some meaningful output.

The example data in \verb+eset+ has three (made--up) covariates.

<<>>=

eset

@
We will use \verb+cov2+. The function \verb+esApply+ takes an {\em
exprSet} and applies a function to it. So, suppose we are interested
in differences in the mean expression for these genes, between the two
groups defined by \verb+cov2+.
We can obtain the $t$--tests by using \verb+esApply+
First, we make up an function that can be used by \verb+esApply+ to do
what we want\footnote{See the {\tt esApply} man pages and HOWTO's for
more details on this function}.

<<>>=
mytt <- function(y) {
      ys <- split( y, cov2 )
      t.test( ys[[1]], ys[[2]] )
      }

ttout <- esApply(eset[245:260,], 1, mytt)
length(ttout)
ttout[1]
igenes.pvals <- sapply(ttout, function(x) x$p.value)
igenes.pvals
igenes.gp1mean <- sapply(ttout, function(x) x$estimate[1])
igenes.gp2mean <- sapply(ttout, function(x) x$estimate[2])
@
And we see that \verb+ttout+ contains the output for the $t$--tests
for the 16 genes. Notice that none of the $p$--values or test statistics
are unusual -- that is because we simply choose genes at random. You
should see small $p$--values and large test statistics (we hope).

Now, to assemble our web page we need to get the annotation data and
to then associate the annotation with the $t$--test results.
We first obtain gene symbol and the LocusLink identifier data by
loading the appropriate environments using \verb+data+.
We extract the data from the
environment using either \verb+get+ or \verb+multiget+.

<<>>=
igenes.ll <- getLL(igenes, "hgu95av2")
igenes.sym <- getSYMBOL(igenes, "hgu95av2")
@

And now we are ready to wrap this all up using
\verb+ll.htmlpage+. This function takes the LocusLink identifiers and
wraps them in an HTML anchor that is linked to the appropriate
LocusLink web page.

<<>>=
ll.htmlpage(igenes.ll, "HOWTO.igenes",
            "Genes seleced in an arbitrary way",
            list(igenes.sym, igenes, round(igenes.gp1mean, 3),
                 round(igenes.gp2mean, 3),round(igenes.pvals, 3)))
@
And you can load this page up in your favorite browser. The genes are
clickable.
An \verb+NA+ in the output for LocusLink represents a gene or EST that
we have not yet successfully mapped to a LocusLink identifier.


\end{document}
