Question: How do I split a genomicrange on chromosome and strand?
1
gravatar for endrebak
9 months ago by
endrebak800
github.com/endrebak
endrebak800 wrote:
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 bioconductor R • 283 views
ADD COMMENTlink modified 9 months ago by zx87548.9k • written 9 months ago by endrebak800
3
gravatar for zx8754
9 months ago by
zx87548.9k
London
zx87548.9k wrote:

Paste the chrom and strand then split as usual:

split(gr, paste(seqnames(gr), strand(gr)))
ADD COMMENTlink written 9 months ago by zx87548.9k
1
gravatar for ATpoint
9 months ago by
ATpoint28k
Germany
ATpoint28k wrote:
tmp.gr <- split(gr, seqnames(gr))

gr.plus   <- tmp.gr[strand( tmp.gr) == "+"]
gr. minus <- tmp.gr[strand( tmp.gr) == "-"]
ADD COMMENTlink modified 9 months ago by zx87548.9k • written 9 months ago by ATpoint28k

But how do I merge the resulting lists?

ADD REPLYlink written 9 months ago by endrebak800
unlistranges.gr)

At least on my machine the markdown currently does not display the code I entered correctly. Some braces are missing. In the answer it should be:

enter image description here

ADD REPLYlink modified 9 months ago • written 9 months ago by ATpoint28k

Also it should be tmp.gr not tmp.split in the first line :)

ADD REPLYlink written 9 months ago by endrebak800

I cannot blame the markdown for this ;-)

ADD REPLYlink written 9 months ago by ATpoint28k

How do I merge the lists of reverse strand and forward strand genomicranges?

ADD REPLYlink written 9 months ago by endrebak800
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: 816 users visited in the last hour