I believe the answer lies in the ChIPpeakAnno
package.
Here is a sample code:
require(ChIPpeakAnno)
peak <- RangedData(space="chr4", IRanges(39610956, 39611545))#chromosome start, end
data (TSS.human.GRCh37)
ap <- annotatePeakInBatch(peak,Annotation=TSS.human.GRCh37 , PeakLocForDistance="end")
The output would look like this:
> ap
RangedData with 1 row and 9 value columns across 1 space
space ranges | peak strand
<factor> <IRanges> | <character> <character>
1 ENSG00000163683 4 [39610956, 39611545] | 1 -
feature start_position end_position insideFeature
<character> <numeric> <numeric> <character>
1 ENSG00000163683 ENSG00000163683 39552535 39640513 inside
distancetoFeature shortestDistance fromOverlappingOrNearest
<numeric> <numeric> <character>
1 ENSG00000163683 28968 28968 NearestStart
To retrieve refseq or gene symbol for ENSEMBL ids:
require (org.Hs.eg.db)
gene.anno <- select(org.Hs.eg.db, keys= ap$feature,keytype = "ENSEMBL", columns=c("ENSEMBL",
"SYMBOL"))
The retrieved gene:
> gene.anno
ENSEMBL ENTREZID SYMBOL
1 ENSG00000163683 201895 SMIM14