Split GRanges to GRangeList based on mcols value
1
0
Entering edit mode
@unamourdeswann-12423
Last seen 3.3 years ago
France

I have a GRanges with a factor in mcols

gr <- GRanges(seqnames = c("1", "2"), IRanges(start=c(1000, 2000), width=100), strand = c("+", "+"), category = c("A", "B"))

I would like to split gr based on category, in order to have a GRangesList that would be similar to:

grl <- GRangesList(A=gr[1], B=gr[2])

Is there a simple/best way to do it?

Thank you very much to everyone!

granges • 1.7k views
ADD COMMENT
2
Entering edit mode
@michael-lawrence-3846
Last seen 3.1 years ago
United States

You could just use split(), like

split(gr, ~ category)
ADD COMMENT
0
Entering edit mode
I did know `split`, but only in combination with another GRL (or seqnames). Glad to know `split` + `~`, thanks!
ADD REPLY
0
Entering edit mode
That's a convenience; of course `split(gr, gr$category)` is also possible.
ADD REPLY
0
Entering edit mode
Cool! Did not know either.
ADD REPLY

Login before adding your answer.

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