%\VignetteIndexEntry{UniProt.ws: A package for retrieving data from the UniProt web service}
%\VignetteDepends{UniProt.ws}

\documentclass[11pt]{article}

\usepackage{Sweave}
\usepackage[usenames,dvipsnames]{color}
\usepackage{graphics}
\usepackage{latexsym, amsmath, amssymb}
\usepackage{authblk}
\usepackage[colorlinks=true, linkcolor=Blue, urlcolor=Blue,
  citecolor=Blue]{hyperref}

%% Simple macros

\newcommand{\code}[1]{{\texttt{#1}}}
\newcommand{\file}[1]{{\texttt{#1}}}

\newcommand{\software}[1]{\textsl{#1}}
\newcommand\R{\textsl{R}}
\newcommand\Bioconductor{\textsl{Bioconductor}}
\newcommand\Rpackage[1]{{\textsl{#1}\index{#1 (package)}}}
\newcommand\Biocpkg[1]{%
  {\href{http://bioconductor.org/packages/devel/bioc/html/#1.html}%
    {\textsl{#1}}}%
  \index{#1 (package)}}
\newcommand\Rpkg[1]{%
  {\href{http://cran.fhcrc.org/web/devel/#1/index.html}%
    {\textsl{#1}}}%
  \index{#1 (package)}}
\newcommand\Biocdatapkg[1]{%
  {\href{http://bioconductor.org/packages/devel/data/experiment/html/#1.html}%
    {\textsl{#1}}}%
  \index{#1 (package)}}
\newcommand\Robject[1]{{\small\texttt{#1}}}
\newcommand\Rclass[1]{{\textit{#1}\index{#1 (class)}}}
\newcommand\Rfunction[1]{{{\small\texttt{#1}}\index{#1 (function)}}}
\newcommand\Rmethod[1]{{\texttt{#1}}}
\newcommand\Rfunarg[1]{{\small\texttt{#1}}}
\newcommand\Rcode[1]{{\small\texttt{#1}}}

%% Question, Exercise, Solution
\usepackage{theorem}
\theoremstyle{break}
\newtheorem{Ext}{Exercise}
\newtheorem{Question}{Question}


\newenvironment{Exercise}{
  \renewcommand{\labelenumi}{\alph{enumi}.}\begin{Ext}%
}{\end{Ext}}
\newenvironment{Solution}{%
  \noindent\textbf{Solution:}\renewcommand{\labelenumi}{\alph{enumi}.}%
}{\bigskip}




\title{UniProt.ws: A package for retrieving data from the UniProt web service}
\author{Marc Carlson}

\SweaveOpts{keep.source=TRUE}
\begin{document}

\maketitle

\section{Configuring  \Robject{uniport.ws}}

The \Rpackage{UniProt.ws} package provides a \Rmethod{select}
interface to the UniProt web service.  

<<loadPkg>>=
library(UniProt.ws)
up <- UniProt.ws(taxId=9606)
@ 

If you already know about the select interface, you can immediately
learn about the various methods for this object by just looking it's
the help page.

<<help,eval=FALSE>>=
help("UniProt.ws")
@ 


When you load the \Rpackage{UniProt.ws} package, it creates a
\Robject{UniProt.ws} object.  If you look at the object you will see
some helpful information about it.

<<show>>=
up
@ 

By default, you can see that the \Robject{UniProt.ws} object is set to
retrieve records from Homo sapiens.  But you can change that of
course.  In order to change it, you first need to look up the
appropriate taxonomy ID for the species that you are interested in.
Uniprot provides support for over 20 thousand species, so there are a
few to choose from!  In order to make this easier, we have provided
the helper function \Rfunction{availableUniprotSpecies} which will
list all the supported species along with their taxonomy ids. When you
call the \Rfunction{availableUniprotSpecies} function, it's
recommended that you make use of the pattern argument to limit your
queries like this:

<<availSpecies>>=
availableUniprotSpecies(pattern="musculus")
@ 

Once you have learned the taxonomy ID for the species of interest, you
can then change the taxonomy id for the \Robject{UniProt.ws} object
using \Rmethod{taxId} setter or by calling the constructor for
\Rfunction{UniProt.ws}

<<setTaxID>>=
mouseUp <- UniProt.ws(10090)
mouseUp
@ 

As you can see the species is different for the
\Robject{mouseUp} new object.


\section{Using \Robject{uniport.ws}}

Once you are safisfied that you have an \Robject{uniport.ws} that is
using the appropriate organsims, you can make use of the standard set
of methods in a \Rmethod{select} interface.  Specifically:
\Rmethod{columns},\Rmethod{keytypes},\Rmethod{keys} and
\Rmethod{select}.

You will probably notice that there are a large number of columns that can be
retrieved.

<<columns>>=
head(keytypes(up))
@ 

And most (but not all) of these fields can also be used as keytypes.

<<keytypes>>=
head(columns(up))
@ 

If necessary you can also look up the keys of a given type.  But
please be warned that the web service is slow at this particular kind
of lookup.  So if you really want to do this kind of operation you are
probably going to want to save the result to your R session.

<<keys,eval=FALSE>>=
egs = keys(up, "ENTREZ_GENE")
@ 

Finally, you can loop up whatever combinations of columns, keytypes and keys
that you need when using \Rmethod{select}.

<<select>>=
keys <- c("1","2")
columns <- c("PDB","UNIGENE","SEQUENCE")
kt <- "ENTREZ_GENE"
res <- select(up, keys, columns, kt)
head(res)
@ 



\end{document}




