Annotating a GenomicRanges object in R
1
0
Entering edit mode
5.7 years ago
ElCascador ▴ 30

Hi,

I have a GenomicRange object that I want to annotate. It's region based. There's obviously numerous way to do it but I would like to do it in R.

I'm looking at the annotatr Bioconductor package: https://bioconductor.org/packages/release/bioc/html/annotatr.html

Is there a better way to do it ? Other good packages ?

Edit: To be clear I would like to automatically populate my GR object with relevant biological information based on public DB. Like Annovar but for GR objects.

Cheers

annotation R • 3.5k views
ADD COMMENT
1
Entering edit mode
5.7 years ago
dr_bantz ▴ 110

You can add annotations as metadata columns (mcols) in the Granges object:

library(GenomicRanges)

# Make the Granges object
ranges_df <- data.frame(chrom = c("I", "I", "III"), start = c(100, 10000, 200), end = c(200, 10200, 250), strand = c("-", "-", "+")) 
regions <- makeGRangesFromDataFrame(ranges_df)

# Make new metadata column called "feature"
mcols(regions)$feature <- ""

# Assign feature based on position
mcols(regions[seqnames(regions) == "I" & start(regions) >200]) <- "gene"

Alternatively, you might have a list of features and you might want to annotate your regions based on whether they overlap with the features:

# Make new metadata column called "feature"
mcols(regions)$feature <- ""

# Make Granges object for the feature of interest
genes_df <- data.frame(chrom = c("I", "IV", "III"), start = c(150, 700, 500), end = c(250, 10200, 750), strand = c("-", "-", "+"))
genes <- makeGRangesFromDataFrame(genes_df)

# Find overlaps and assign feature to regions
hits <- findOverlaps(query = regions, subject = genes, ignore.strand = TRUE)
mcols(regions[queryHits(hits)])$feature <- "gene"
ADD COMMENT

Login before adding your answer.

Traffic: 2611 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6