Is possible to convert BSgenome object to GRange?
1
2
Entering edit mode
6.9 years ago
Lila M ★ 1.3k

Hi everybody, I was wondering if there is any way to convert BSgenome object to GRange. I'm using library(BSgenome.Dmelanogaster.UCSC.dm3)

and I want a GR object like this:

FBgn0000003     chr3R [ 2648220, 2648518] + | FBgn0000003
FBgn0000008     chr2R [18024494, 18060346] + | FBgn0000008
.........

Any function for doing that? Thanks!

BSgenome GRanges • 4.2k views
ADD COMMENT
2
Entering edit mode
6.9 years ago

A BSgenome object is essentially a sequence and mask database. A GRanges object is a set of regions with optional metadata. While you can use these together, unless you want a GRanges object having the chromosome/contig lengths then your question is essentially like asking "Can I use purple to make a car?"

Having said that, perhaps you've created a view of a BSgenome that you want to make a GRanges object out of. In that case, use the granges() function.

ADD COMMENT
0
Entering edit mode

I understand what you say. My concern is if there is an easy option to construct a GRange (ranges and strand) object using the complete Dmelanogaster genome, let's say something like that, in a fast way:

 genes <- GRanges(seqnames=c("chr2L" , "chr2R" , "chr3L" , "chr3R" , "chr4"  , "chrX"  , "chrU" , "chrM"  , "chr2LHet" , "chr2RHet" , "chr3LHet" , "chr3RHet" , "chrXHet"  , "chrYHet"  , "chrUextra"),
                       ranges=IRanges(
                       start=c(?,?,?,?),
                       end=c(?,?,?,?))),
                       strand=c("?", "?"),
                     seqlengths=c( chr2L= 23011544,   chr2R= 21146708,  chr3L=24543557,  chr3R=27905053,   chr4=1351857,   chrX=22422827,  chrU= 10049037,     chrM= 19517,   chr2LHet= 368872,   chr2RHet= 3288761,    chr3LHet= 2555491,  chr3RHet=  2517507, chrXHet=204112,   chrYHet= 347038 , chrUextra= 29004656)
ADD REPLY
3
Entering edit mode
library("BSgenome.Dmelanogaster.UCSC.dm6")
library("GenomicRanges")
nContigs = length(seqnames(Dmelanogaster))
gr = GRanges(seqnames=seqnames(Dmelanogaster),
                      ranges=IRanges(start=rep(1, nContigs), end=seqlengths(Dmelanogaster)),
                      strand=rep("*", nContigs))

BSgenome objects have no concept of genes, so that sort of information isn't there.

ADD REPLY
0
Entering edit mode

That exactly what I was looking for! Thanks!

ADD REPLY
5
Entering edit mode

A slightly quicker way:

GRanges(seqinfo(BSgenome.Dmelanogaster.UCSC.dm6))
ADD REPLY
0
Entering edit mode

Super quick! Thanks very much!!

ADD REPLY
0
Entering edit mode

I think it would be great to promote this comment as an answer, so that it can be upvoted at the top.

ADD REPLY

Login before adding your answer.

Traffic: 1754 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