%\VignetteIndexEntry{HOWTO: Load Genotype Data}
%\VignetteDepends{GeneticsBase}
%\VignetteKeywords{Genetics}
%\VignettePackage{GeneticsBase}

\documentclass[10pt]{article}
\usepackage{url}
\usepackage{amsmath}
\usepackage{natbib}
\usepackage{isorot}
\usepackage{fullpage} % standard 1 inch margins 

\newcommand{\Robject}[1]{{\texttt{#1}}}
\newcommand{\Rfunction}[1]{{\texttt{#1}}}
\newcommand{\Rpackage}[1]{{\textit{#1}}}
\newcommand{\Rclass}[1]{{\textit{#1}}}
\newcommand{\Rmethod}[1]{{\textit{#1}}}
\newcommand{\code}[1]{\texttt{#1}}
\newcommand{\email}[1]{\texttt{#1}}

%%% Hyperlinks for ``PDF Latex'' :
\ifx\pdfoutput\undefined%%--- usual ``latex'' :
  %% Stuff w/out hyperref
\else%%---------------------- `` pdflatex '' : -- still gives funny errors
  \RequirePackage{hyperref}
  %% The following is R's share/texmf/hyperref.cfg :
  %% Stuff __with__ hyperref :
  \hypersetup{%
    %default: hyperindex,%
    colorlinks,%
    %default: pagebackref,%
    linktocpage,%
    %%plainpages=false,%
    linkcolor=Green,%
    citecolor=Blue,%
    urlcolor=Red,%
    pdfstartview=Fit,%
    pdfview={XYZ null null null}%
    }
  \RequirePackage{color}
  \definecolor{Blue}{rgb}{0,0,0.8}
  \definecolor{Green}{rgb}{0.1,0.75,0.1}
  \definecolor{Red}{rgb}{0.7,0,0}
  %% ESS JCGS v2 :
  %%\hypersetup{backref,colorlinks=true,pagebackref=true,hyperindex=true}
  %%\hypersetup{backref,colorlinks=false,pagebackref=true,hyperindex=true}
\fi


\usepackage{Sweave}
\begin{document}

\title{HOWTO: Loading Genotype Data}
\author{
        Gregory Warnes\\
        \email{gregory\_warnes\@urmc.rochester.edu},
        \\
        Nitin Jain\\
        \email{nitin.jain\@pfizer.com}
        }       

\maketitle

\section{Introduction}

This document demonstrates how to use the \Rpackage{GeneticsBase}
package to generate marker summary tables \emph{for
  studies with a small number of markers}.  It is written as a
step-by-step tutorial. For additional details on each of the R
functions utilized, please see the individual help pages

\textbf{Note: The textual displays described here are not suitable
for large numbers of markers.  They are intended for reviewing
detailed information on a small number of markers, such as those in
candidate gene studies, or a small set of markers achieving a 'quality'
or 'significance' cutoff from a larger set.}



\section{Example}

\subsection{Prepare phenotype data \label{data}}

The first step is to prepare the phenotype data.  It may be in the
form of a SAS dataset, SAS export file, comma-delimited text file
(CSV), tab-delimited text file (TSV), or Microsoft Excel spreadsheet
file (XLS).  It should have one row per observation and one column
per variable, and must contain a subject identifier variable that
can be used to match observations with the corresponding genotype
data.

\subsection{Prepare genotype data \label{data}}

You also need to store the genetic call data in a file that can be
read into R.  GeneticsBase packge accepts genotype data in a variety
of formats:

\begin{itemize}

\item standard pedigree (ped) format. 
  
\begin{verbatim}
a2m apoe
    50103    5010004    5090005    5090004          2          2          1
      2          3          4
    50103    5010005    5090005    5090004          2          2          1
      1          3          4
    50105    5010049    5090021    5090022          2          2          1
      1          4          4
    50105    5010070    5090020    5090019          1          2          1
      1          3          4

\end{verbatim}


\item hapmap format : The hapmap .ped format is a variant of the
  standard pedigree format.  A portion of the first two lines of
  the hapmap file for chrmosome 1 are shown below:

\begin{verbatim}
rs2298011 rs1320571 rs11721 rs4018608 rs6685064 rs604618 ....
1347 14 0 0 1 1 1 1 3 3 3 3 1 1 2 2 3 3 3 3 2 2 3 3 2  .....
\end{verbatim}

\item Pfizer format: First few lines of an example file in Pfizer's
  data format are shown below:

\begin{verbatim}
Locus,Gene Marker,Locus Start,Project,Protocol,Sample ID,Donor ID,Genotype
A1A,C1556G,-1243,P234,103,1028022.1,1028022,G/G
A1B,T127A,20141,P234,103,1028022.1,1028022,A/T
A1B,T5094A,102358,P234,103,1028022.1,1028022,A/T
A1A,C1556G,-1243,P234,103,1035130.1,1035130,G/G
\end{verbatim}

\item Perlegen format: A portion of first two lines of data in the
  Perlegen format are shown below:

\begin{verbatim}
snp_id  genotype
753527  rrrrrrrrrrrrrrrrhrrrrrrrrrrrrrrrrrrrrrrrrrr......
752848  hhahaararhhhahrhhhahaharhaahhahrhhahhahnhha......
\end{verbatim}


\end{itemize}

\subsection{Load the genotype and phenotype data}

In GeneticsBase, both genotype and phentype data is loaded by a single
function \emph{readgenes}. This function \emph{readGenes} has four
primary arguments: \emph{gfile}, \emph{gfromat}, \emph{file}, and
\emph{pformat}. Arguments \emph{gfile} and \emph{pfile} are the names
of files containing the genotype and phenotype data (respectively), and
arguments \emph{gformat} and \emph{pformat} are the corresponding file
formats for the genotype and phenotype data.


Various types of data can be loaded by readGenes function.  Example
files are provided in \code{data} subdirectory of the
\code{GeneticsBase} package.  To access these execute

<<eval=FALSE,print=TRUE>>=
library(GeneticsBase)
setwd(file.path(.path.package("GeneticsBase"), "data"))
@

\noindent%
Supported file formats include:

\begin{itemize}

\item fbat .ped format 

  The Alzheimer's example dataset is stored in the Fbat variant of the
  .ped Pedigree Format. As it does not include phenotype data, we only
  use the genotyep filename and file type arguments:

<<echo=TRUE,eval=FALSE>>=
ALZH <- readGenes(gfile="ALZH.ped", gformat="fbat.ped")
@

The CAMP example dataset is from from the `Childhood Asthma Management
Program (CAMP)' and incudes both genotype and phenotype
information. It can be loaded by:

<<echo=TRUE,eval=FALSE>>=
CAMP <- readGenes(gfile="CAMP.ped", gformat="fbat.ped",
                  pfile="CAMPZ.phe", pformat="fbat.phe")
@

\item HAPMAP .ped format

  A subset of the data for the International HapMap project is
  available in the hapmap example data set.  This file can be loaded
  via:

<<echo=TRUE,eval=FALSE>>=
hapmapchr1 <- readGenes(gfile="hapmapchr1.ped", gformat="hapmap")
@

\item Pfizer genetics data format

<<echo=TRUE,eval=FALSE>>=
PfizerExample <- readGenes.pfizer("PfizerExample.txt", format="Listing")
@

\item Perlegen data format

<<echo=TRUE,eval=FALSE>>=
PerlegenExample <- readGenes("PerlegenExample.txt", gformat="perlegen")
@

\end{itemize}

\end{document}
