\HeaderA{findClosestGene}{Find closest refseq gene}{findClosestGene}
\keyword{IO}{findClosestGene}
\begin{Description}\relax
This function is used to find the nearest refseq transcript(s) to a
point in the genome specified.  Note that it is limited to the refseq
transcripts listed at genome.ucsc.edu, where this function goes for
information.
\end{Description}
\begin{Usage}
\begin{verbatim}
findClosestGene(chrom, pos, genome = "hg17", position = "txStart")
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{chrom}] Usually specified like 'chr1', 'chr2', etc. 
\item[\code{pos}] A position in base pairs in the genome 
\item[\code{genome}] Something like 'hg16', 'hg17', 'mm6', etc. 
\item[\code{position}] The location to measure distance from: one of
'txStart', 'txEnd', 'cdsStart', 'cdsEnd'
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The first time the function is run, it checks to see if the refflat
table for the given genome is present in the package environment.  If
not, it downloads it to the /tmp directory and gunzips it (using
\LinkA{getRefflat}{getRefflat}.  It is then stored so that in future calls, there
is no re-download required.
\end{Details}
\begin{Value}
A data frame with the gene name, refseq id(s), txStart, txEnd,
cdsStart, cdsEnd, exon count, and distance.  Note that distance is
measured as pos-position, so negative values mean that the point in
the gene is to the left of the point specified in the function call
(with the p-tel on the left).
\end{Value}
\begin{Note}\relax
The function may return more than one transcript, as several
transcripts may have the same start site
\end{Note}
\begin{Author}\relax
Sean Davis <sdavis2@mail.nih.gov>
\end{Author}
\begin{Examples}
\begin{ExampleCode}
findClosestGene('chr1',100000000,'hg17')
\end{ExampleCode}
\end{Examples}

