如何将因子 Rle 转换为有序保留字符串列表?右
好吧,我有一个对象,我恢复了一个看起来像这样的因子-RLE:
x <- rle(c(1,1,1,2,2,3,4,4,4))
我想对 x 做一些事情,这样就返回了:
1 1 1 2 2 3 4 4 4
我的例子有点复杂,因为我的对象看起来像这样:
factor-Rle of length 622253 with 50 runs
Lengths: 32201 28715 22210 25478 20264 19072 15278 12130 14763 12299 13659 16494 ...
Values : + - + - + - + - + - + - ...
Levels(3): + - *
因为原始对象有 62090 个元素,并且每个元素都有 >=1 个具有值 +、- 或 * 的条目
在这个示例中,我想知道如何恢复值 (+, -, 或 *) 以相同的顺序 出现。
这将是更可重现的示例:
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 = "+")
并且,从此,我想获得一个包含以下内容的对象:
+ + - +
再一次,我的尝试将我引向因子 Rle 对象:
> grl@unlistData@strand
factor-Rle of length 12 with 3 runs
Lengths: 5 3 4
Values : + - +
Levels(3): + - *
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): + - *
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论