I'm looking for an efficient way to compare genes between two genomic regions of an annotated genome. Basically, I'm interested in comparing GO-terms of genes located in one genomic region to another genomic region to see whether and how they differ.
But does anyone know how to extract GO-terms for a specific genomic region (e.g., bp-position 250,000-550,000 on chromosome 1) and compare it to another one (e.g., bp-position 1,500,000-1,750,000 on chromosome 1) within an annotated genome (e.g. bovine)?
You will first need a TranscriptDB object. For that you want to use makeTxDbPackageFromUCSC() in the GenomicFeatures package. Or if you don't need it to be persistent, you can use makeTxDbFromUCSC(), which will make the DB, but not the package. Once you have done that, you can do something like
gns <- genes(TxDb.Btaurus.UCSC.bosTau8.knownGene) ## assuming that's what you called it
library(org.Bt.eg.db)
gos.region1 <- select(org.Bt.eg.db, names(gns[gns %over% GRanges("chr1", IRanges(250000, 550000)),]), "GO")
Do the same for the other, and then you can compare the terms. I don't know what you mean by 'compare', nor how one would do that efficiently, so I leave that up to you.