library(TxDb.Dmelanogaster.UCSC.dm3.ensGene)
txdb <- TxDb.Dmelanogaster.UCSC.dm3.ensGene
gr <- GRanges("chr2L", IRanges(c(7500, 8400, 9000), width = 200,
names = LETTERS[1:3]))
## Coding region coordinates relative to transcript:
cdsbytx <- cdsBy(txdb, "tx")
map1 <- mapCoords(gr, cdsbytx)
map1
## Range A is not translated because it does not fall completely
## 'within' any ranges.
findOverlaps(gr["A"], cdsbytx, type = "any")
findOverlaps(gr["A"], cdsbytx, type = "within")
## Exon region coordinates relative to trancript:
exonsbytx <- exonsBy(txdb, "tx")
map2 <- mapCoords(gr, exonsbytx)
## Add exon coordinates relative to the individual exons:
map3 <- mapCoords(gr, exonsbytx, elt.hits=TRUE, elt.loc=TRUE)
map3
## Extract the individual exons hit:
unlist(exonsbytx, use.names=FALSE)[mcols(map3)$eltHits]
Run the code above in your browser using DataLab