%% \VignetteIndexEntry{Talk: Annotation}

\documentclass[a4paper, notitlepage]{beamer}

\usepackage{BioconductorSlides}

\title{Annotation }
\author{
  Martin
  Morgan\footnote{\href{mailto:mtmorgan@fhcrc.org}{mtmorgan@fhcrc.org}}
}
\date{June 23 -- 28, 2013}

<<setup, echo=FALSE>>=
library(Morgan2013)
op <- options(prompt="  ", continue="  ")
@ 

\begin{document}

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

\begin{frame}{Overview}
  \begin{enumerate}
  \item Annotation
    \begin{itemize}
    \item Genes
    \item Gene models
    \item Web / cloud resources
    \end{itemize}
  \item Called variants
    \begin{itemize}
    \item VCF files
    \item Variant annotation
    \end{itemize}
  \end{enumerate}
\end{frame}

\begin{frame}[fragile]{Genes: \Rpackage{org.*} \& friends}
  Gene-centric annotation packages\footnote{\url{http://bioconductor.org/packages/release/BiocViews.html}}
  \begin{itemize}
  \item Organism: \Biocannopkg{org.Hs.eg.db}, \ldots
  \item Pathway: \Biocannopkg{GO.db}, \ldots
  \item Microarray: \Biocannopkg{hgu95av2.db}, \ldots
  \item And: \Biocpkg{MotifDb}, \ldots
  \end{itemize}
  The `select' interface
<<select, eval=FALSE>>=
library(org.Hs.eg.db)
keytypes(org.Hs.eg.db)       # available queries
keys(org.Hs.eg.db, "SYMBOL") # possible 'SYMBOL' values
cols(org.Hs.eg.db)           # available return values
select(org.Hs.eg.db, "TERT", keytype="SYMBOL",
    c("ENTREZID", "GENENAME", "GO"))
@ 
\end{frame}

\begin{frame}[fragile]{Gene models: \Rpackage{TxDb.*}}
  \begin{itemize}
  \item Exon and transcript coordinates for model organisms
  \item `Select' interface -- \Rfunction{keytypes}, \Rfunction{keys},
    \Rfunction{cols}, \Rfunction{select}
  \end{itemize}
<<TxDb-select, eval=FALSE>>=
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
select(txdb, "7015", keytype="GENEID", "TXNAME")
@ 
  \begin{itemize}
  \item \Rclass{GRanges} queries: \Rfunction{transcripts},
    \Rfunction{exons}, \Rfunction{cds}, \Rfunction{promoters}
  \item \Rclass{GRangesList} queries: \Rfunction{transcriptsBy},
    \Rfunction{exonsBy}, \Rfunction{cdsBy},
    \Rfunction{intronsByTranscript}, \Rfunction{fiveUTRsByTranscript},
    \Rfunction{threeUTRsByTranscript}
  \end{itemize}
<<TxDb-exonsBy, eval=FALSE>>=
exonsBy(txdb, "tx")
exonsBy(txdb, "gene")["7015"]
@ 
\end{frame}

\begin{frame}[fragile]{Web resources: \Biocpkg{biomaRt} \& friends}
  Ensembl Biomart\footnote{\url{http://www.ensembl.org/biomart}} queries
  \bigskip
\begin{Schunk}
\begin{Sinput}
library(biomaRt)
listMarts()                      # many marts!
listDatasets(useMart("ensembl")) # many datasets!
ensembl <- 
    useMart("ensembl", dataset="hsapiens_gene_ensembl")

listFilters(ensembl)             # restrict query
listAttributes(ensembl)          # specify return values

getBM(mart=ensembl,
    filters="chromosome_name", values=c("21", "22"),
    attributes=c("ensembl_gene_id", "chromosome_name"))
\end{Sinput}
\end{Schunk}
\end{frame}

\begin{frame}[fragile]{Web resources: \Biocpkg{biomaRt} \& friends}
  Also:
  \begin{itemize}
  \item \Biocpkg{KEGGREST}, \Biocpkg{uniprot.ws}, \ldots
  \item \Rfunction{GenomicFeatures::makeTranscriptDbFromBiomart}
  \end{itemize}
  \Rpackage{org.*} vs.\ \Biocpkg{biomaRt}?
  \begin{itemize}
  \item Scope: \Biocpkg{biomaRt} much more extensive
  \item Convenience: \Biocpkg{org.Hs.eg.db} passes the `airplane' test
  \item Reproducibility: \Biocpkg{org.Hs.eg.db} data consistent within
    each \Bioconductor{} release
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Cloud resources: \Biocpkg{AnnotationHub}}
  Goal
  \begin{itemize}
  \item 'Mirror' large resources in \Bioconductor-friendly formats
  \item Easily retrieve into \R{} session
  \item Embody \Bioconductor{} principles, e.g., metadata, versioning, \ldots
  \end{itemize}
  Available -- examples
  \begin{itemize}
  \item Ensembl FASTA (\Rclass{FaFile}), GTF (\Rclass{GRanges}), release 69$+$
  \item ENCODE tracks at UCSC (\Rclass{GRanges})
  \item dbSNP VCF files (\Rclass{GRanges})
  \end{itemize}
  Use
<<AnnotationHub, eval=FALSE>>=
library(AnnotationHub)
hub <- AnnotationHub()  # query for available resources
## metadata(hub) -- info. about available resources
## hub$<tab> -- tab completion to select resource
@ 
\end{frame}

\begin{frame}{Variants: VCF files}
  \begin{itemize}
  \item Text file describing called variants (SNPs or more complicated)
  \item Metadata, header, and then rows for each variant
  \item Exact content described by metadata, depends on source of VCF
  \end{itemize}
  9 fields plus fields for each sample
  \begin{itemize}
  \item \texttt{CHROM}, \texttt{POS}, \texttt{ID}
  \item \texttt{REF}, \texttt{ALT}: Reference and alternate
    (variant) sequence
  \item \texttt{QUAL}, \texttt{FILTER}
  \item \texttt{INFO}: Per-variant information
  \item \texttt{FORMAT}: Instructions for interpreting per-sample
    information
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Variants: VCF files}
  \begin{itemize}
  \item Example: 1000 genomes chr22, five samples.
  \end{itemize}
  Metadata:
  \begin{itemize}
  \item \verb|##INFO=<ID=AN,Number=1,Type=Integer,|
    \verb|Description="Total Allele Count">|
  \end{itemize}
  One row:
  \begin{itemize}
  \item \verb|22	50300078	rs7410291|
  \item \verb|A	G|
  \item \verb|100	PASS|
  \item \verb|AN=2184;AVGPOST=0.9890;THETA=0.0005;VT=SNP;|
    \verb|RSQ=0.9856;ERATE=0.0020;SNPSOURCE=LOWCOV;|
    \verb|AA=N;AC=751;LDAF=0.3431;AF=0.34;ASN_AF=0.19;|
    \verb|AMR_AF=0.20;AFR_AF=0.83;EUR_AF=0.22|
  \item \verb|GT:DS:GL|
  \item \verb!0|0:0.000:-0.00,-2.77,-5.00! (similar for each sample)
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Variants: \Biocpkg{VariantAnnotation}}
  Index
<<tabix, eval=FALSE>>=
library(Rsamtools)
indexTabix("chr22.vcf.gz", type="vcf4")
@ 
  Discovery
<<vcf-discovery, eval=FALSE>>=
library(VariantAnnotation)
scanVcfHeader("chr22.vcf.gz")
@ 
  Query: \Rclass{SummarizedExperiment}-like \Rclass{VCF} class
<<vcf-query, eval=FALSE>>=
which <- GRanges("22", 
    IRanges(c(321680, 14477080), c(321689, 14477090)))
param <- ScanVcfParam(info=c("AN", "LDAF"), geno=NA,
    which=which)
readVcf("chr22.vcf.gz", "hg19", param=param)
@ 
  In devel
  \begin{itemize}
  \item \Rfunction{readInfo}, \Rfunction{readGeno}, \Rfunction{readGT}
    for simple queries
  \end{itemize}
\end{frame}

\begin{frame}{Variant annotation}
  \Bioconductor{}
  \begin{itemize}
  \item \Rfunction{locateVariants} with \Rclass{TranscriptDb} /
    \Rclass{GRangesList}
  \item \Rfunction{predictCoding} with \Rclass{TranscriptDb} and
    \Rclass{BSgenome} / \Rclass{FaFile}
  \item \Rfunction{find} / \Rfunction{countOverlaps}
  \end{itemize}
  SIFT / PolyPhen
  \begin{itemize}
  \item \Biocannopkg{SIFT.Hsapiens.dbSNP132},
    \Biocannopkg{PolyPhen.Hapiens.dbSNP131.db}: rsid look-up via
    `select' interface
  \end{itemize}
  \Biocpkg{ensemblVEP}
  \begin{itemize}
  \item Interface to Ensembl Variant Effect Predictor using Ensembl
    perl script and web interface
  \end{itemize}
\end{frame}

\begin{frame}{Summary \& Acknowledgments}
  \begin{columns}[t]
    \column{.4\textwidth}
    Summary
    \begin{enumerate}
    \item Annotation
      \begin{itemize}
      \item Genes
      \item Gene models
      \item Web / cloud resources
      \end{itemize}
    \item Called variants
      \begin{itemize}
      \item VCF files
      \item Variant annotation
      \end{itemize}
    \end{enumerate}
    \column{.6\textwidth}
    Acknowledgments
    \begin{itemize}
    \item Marc Carlson (Genes, gene models)
    \item Valerie Obenchain (Variants)
    \item Dan Tenenbaum (\Biocpkg{AnnotationHub})
    \item Herv\'e Pag\`es (Gene models)
    \item Paul Shannon (\Biocpkg{MotifDb}, \Biocpkg{AnnotationHub})
    \end{itemize}
    And
    \begin{itemize}
    \item Steffen Durink (\Biocpkg{biomaRt})
    \end{itemize}
  \end{columns}
\end{frame}

\end{document}
