Question: Annotating a GenomicRanges object in R
0
gravatar for ElCascador
10 weeks ago by
ElCascador20
European Union
ElCascador20 wrote:

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

R annotation • 150 views
ADD COMMENTlink modified 10 weeks ago • written 10 weeks ago by ElCascador20
0
gravatar for dr_bantz
10 weeks ago by
dr_bantz80
dr_bantz80 wrote:

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 COMMENTlink modified 10 weeks ago • written 10 weeks ago by dr_bantz80
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1037 users visited in the last hour