Question: How do I split a genomicrange on chromosome and strand?
1
gravatar for endrebak
12 days ago by
endrebak740
endrebak740 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?

ADD COMMENTlink modified 10 days ago by zx87547.1k • written 12 days ago by endrebak740
3
gravatar for zx8754
10 days ago by
zx87547.1k
London
zx87547.1k wrote:

Paste the chrom and strand then split as usual:

split(gr, paste(seqnames(gr), strand(gr)))
ADD COMMENTlink written 10 days ago by zx87547.1k
1
gravatar for ATpoint
12 days ago by
ATpoint15k
Germany
ATpoint15k wrote:
tmp.gr <- split(gr, seqnames(gr))

gr.plus   <- tmp.gr[strand( tmp.gr) == "+"]
gr. minus <- tmp.gr[strand( tmp.gr) == "-"]
ADD COMMENTlink modified 10 days ago by zx87547.1k • written 12 days ago by ATpoint15k

But how do I merge the resulting lists?

ADD REPLYlink written 12 days ago by endrebak740
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 12 days ago • written 12 days ago by ATpoint15k

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

ADD REPLYlink written 12 days ago by endrebak740

I cannot blame the markdown for this ;-)

ADD REPLYlink written 12 days ago by ATpoint15k

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

ADD REPLYlink written 12 days ago by endrebak740
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: 1801 users visited in the last hour