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

Paste the chrom and strand then split as usual:

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

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

But how do I merge the resulting lists?

ADD REPLYlink written 21 months ago by endrebak840
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 21 months ago • written 21 months ago by ATpoint44k

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

ADD REPLYlink written 21 months ago by endrebak840

I cannot blame the markdown for this ;-)

ADD REPLYlink written 21 months ago by ATpoint44k

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

ADD REPLYlink written 21 months ago by endrebak840
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: 989 users visited in the last hour