This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How do I split a genomicrange on chromosome and strand?
library(GenomicRanges)

gr <- GRanges(Rle(c("chr2", "chr2", "chr1", "chr3"), c(1, 3, 2, 4)),
                   IRanges(1:10, width=10:1, names=head(letters, 10)),
                   Rle(strand(c("-", "+", "*", "+", "-")), c(1, 2, 2, 3, 2)),
                   score=1:10, GC=seq(1, 0, length=10))
split(gr, seqnames(gr))

Gives me a list of chromosomes, but how do I get a list split on chromosome and strand?

genomicranges r bioconductor

1 answer

Paste the chrom and strand then split as usual:

split(gr, paste(seqnames(gr), strand(gr)))

Wonderful, thanks for the help!

I am trying to split just by chromosome but this does not work for me.

split(gr, seqnames(gr))

Will split everything by chromosome but the object for each chromosome will be the same length, which I assume is the number of sequences in chr1.

Please advise :/

Log in to answer this question.