如何将因子 Rle 转换为有序保留字符串列表?右

发布于 2025-01-14 06:29:43 字数 1374 浏览 3 评论 0原文

好吧,我有一个对象,我恢复了一个看起来像这样的因子-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文