Question: How do I split a genomicrange on chromosome and strand?
1
gravatar for endrebak
17 months ago by
endrebak830
github.com/endrebak
endrebak830 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 • 570 views
ADD COMMENTlink modified 17 months ago by zx87549.6k • written 17 months ago by endrebak830
3
gravatar for zx8754
17 months ago by
zx87549.6k
London
zx87549.6k wrote:

Paste the chrom and strand then split as usual:

split(gr, paste(seqnames(gr), strand(gr)))
ADD COMMENTlink written 17 months ago by zx87549.6k
1
gravatar for ATpoint
17 months ago by
ATpoint38k
Germany
ATpoint38k wrote:
tmp.gr <- split(gr, seqnames(gr))

gr.plus   <- tmp.gr[strand( tmp.gr) == "+"]
gr. minus <- tmp.gr[strand( tmp.gr) == "-"]
ADD COMMENTlink modified 17 months ago by zx87549.6k • written 17 months ago by ATpoint38k

But how do I merge the resulting lists?

ADD REPLYlink written 17 months ago by endrebak830
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 17 months ago • written 17 months ago by ATpoint38k

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

ADD REPLYlink written 17 months ago by endrebak830

I cannot blame the markdown for this ;-)

ADD REPLYlink written 17 months ago by ATpoint38k

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

ADD REPLYlink written 17 months ago by endrebak830
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: 1260 users visited in the last hour