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

Paste the chrom and strand then split as usual:

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

gr.plus   <- tmp.gr[strand( tmp.gr) == "+"]
gr. minus <- tmp.gr[strand( tmp.gr) == "-"]
ADD COMMENTlink modified 11 months ago by zx87549.1k • written 12 months ago by ATpoint32k

But how do I merge the resulting lists?

ADD REPLYlink written 12 months ago by endrebak810
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 months ago • written 12 months ago by ATpoint32k

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

ADD REPLYlink written 12 months ago by endrebak810

I cannot blame the markdown for this ;-)

ADD REPLYlink written 12 months ago by ATpoint32k

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

ADD REPLYlink written 12 months ago by endrebak810
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: 1282 users visited in the last hour