Question: Split GRanges to GRangeList based on mcols value
0
gravatar for unamourdeswann
12 months ago by
unamourdeswann10 wrote:

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 • 267 views
ADD COMMENTlink modified 12 months ago by Michael Lawrence11k • written 12 months ago by unamourdeswann10
Answer: Split GRanges to GRangeList based on mcols value
2
gravatar for Michael Lawrence
12 months ago by
United States
Michael Lawrence11k wrote:

You could just use split(), like

split(gr, ~ category)
ADD COMMENTlink written 12 months ago by Michael Lawrence11k
I did know `split`, but only in combination with another GRL (or seqnames). Glad to know `split` + `~`, thanks!
ADD REPLYlink written 12 months ago by unamourdeswann10
That's a convenience; of course `split(gr, gr$category)` is also possible.
ADD REPLYlink written 12 months ago by Michael Lawrence11k
Cool! Did not know either.
ADD REPLYlink written 12 months ago by unamourdeswann10
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 16.09
Traffic: 286 users visited in the last hour