It's very simple in R, but I would use the Annotation packages rather than biomaRt, so you don't have to send a query through the wires each time. First of all, install Homo sapiens from Bioconductor:
> source("https://bioconductor.org/biocLite.R")
> biocLite("Homo.sapiens")
> library(Homo.sapiens)
This will also install a TxDb object for homo sapiens, called TxDb.Hsapiens.UCSC.hg19.knownGene.
To get all the gene coordinates, use the genes() function:
> genes(TxDb.Hsapiens.UCSC.hg19.knownGene)
To get the intersection with your coordinates, you must first convert them to a GenomicRanges list. The easiest way is to convert the list to a dataframe, and then use the makeGRangesFromDataFrame function, which should have already been loaded when with Homo.sapiens. Remember to append the prefix 'chr' to your chromosome names. Coordinates should be 1-based.
> library(dplyr)
> mycoords.gr = lapply(mycoords.list, function (x) {res=strsplit(x, ':')}) %>%
unlist %>%
as.numeric %>%
matrix(ncol=3, byrow=T) %>%
as.data.frame %>%
select(chrom=V1, start=V2, end=V3) %>%
mutate(chrom=paste0('chr', chrom)) %>%
makeGRangesFromDataFrame
> mycoords.gr
GRanges object with 20 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr1 [ 4864876, 5864876] *
[2] chr1 [14283067, 15283067] *
[3] chr1 [21786817, 22786817] *
[4] chr1 [33465769, 34465769] *
[5] chr1 [45300539, 46300539] *
... ... ... ...
[16] chr1 [166112356, 167112356] *
[17] chr1 [174453227, 175453227] *
[18] chr1 [185347260, 186347260] *
[19] chr1 [194299241, 195299241] *
[20] chr1 [205731116, 206731116] *
-------
At this point you can simply use subsetByOverlaps or mergeByOverlaps, to get the genes of interest:
> subsetByOverlaps(genes(TxDb.Hsapiens.UCSC.hg19.knownGene), mycoords.gr)
GRanges object with 188 ranges and 1 metadata column:
seqnames ranges strand | gene_id
<Rle> <IRanges> <Rle> | <character>
100126349 chr1 [166123980, 166124035] - | 100126349
100129405 chr1 [155715559, 155720673] + | 100129405
100132406 chr1 [145209111, 146467744] + | 100132406
100288142 chr1 [144146811, 146467744] + | 100288142
100302117 chr1 [117214371, 117214449] + | 100302117
... ... ... ... ... ...
9674 chr1 [175126123, 175162229] - | 9674
9829 chr1 [ 65720148, 65881552] + | 9829
9910 chr1 [174128552, 174964445] + | 9910
9923 chr1 [ 22778344, 22857650] + | 9923
998 chr1 [ 22379120, 22419436] + | 998
The gene_id column in this dataframe contains the Entrez ID of the human gene overlapping the coordinates. If you also want the gene symbols, or any other ID, you can get it from org.Hs.db:
> as.data.frame(org.Hs.egSYMBOL) %>% head
gene_id symbol
1 1 A1BG
2 2 A2M
3 3 A2MP1
4 9 NAT1
5 10 NAT2
6 11 NATP
Just type "org.Hs.eg" and hit tab to see all the possible Entrez Gene to ID conversion available.