1 year ago

#294560

test-img

Sky Scraper

How to convert factor Rle to order perserved string list? R

Ok so I have an object and I recovered a factor-RLE that looks sort of like this:

x <- rle(c(1,1,1,2,2,3,4,4,4))

and I would want to do something to x such that this returned:

1 1 1 2 2 3 4 4 4

My example is a little more complex as my object looks like this:

factor-Rle of length 622253 with 50 runs
  Lengths: 32201 28715 22210 25478 20264 19072 15278 12130 14763 12299 13659 16494 ...
  Values :     +     -     +     -     +     -     +     -     +     -     +     - ...
Levels(3): + - *

because the original object has 62090 elements, and each element has >=1 entry that has a value, +, -, or *

In this example, I want to know how can I recover the values (+, -, or *) in the same order they appear.

This would be more reproducible example:

if (!require("BiocManager"))
install.packages("BiocManager")
BiocManager::install("GenomicRanges")
library(GenomicRanges)

gr <- GRanges(seqnames = Rle(c("chr1"), c(3)), ranges = IRanges(c(1, 13, 22), width=c(12, 6, 6)), strand = "+")
gr2 <- GRanges(seqnames = "chr1", ranges = IRanges(c(15, 30), width=c(15, 6)), strand = "+")
gr3 <- GRanges(seqnames = "chr1", ranges = IRanges(c(34, 40, 58), width=c(2, 7, 7)), strand = "-")
gr4 <- GRanges(seqnames = "chr1", ranges = IRanges(c(80, 92, 105,140), width=c(5,3,9,15)), strand = "+")

And, from this, I want to get an object that contains:

+ + - +

Once again, my attempted leads me to the factor Rle object:

> grl@unlistData@strand
factor-Rle of length 12 with 3 runs
Lengths: 5 3 4
Values : + - +
Levels(3): + - *

r

extract

rle

iranges

0 Answers

Your Answer

Accepted video resources