【问题标题】:Deconstruct DNAstringsSets into normal strings将 DNAstringsSet 解构为普通字符串
【发布时间】:2019-01-16 13:52:26
【问题描述】:

这来自一个名为 "VariantAnnotation" 的 R 库及其依赖项 "Biostrings"

我有一个 DNAstringsSetList,我想将其转换为普通列表或字符串向量。

library(VariantAnnotation)

fl <- system.file("extdata", "chr22.vcf.gz", package="VariantAnnotation")

vcf <- readVcf(fl, "hg19")

tempo <- rowRanges(vcf)$ALT  # Here is the DNAstringsSetList I mean.

print(tempo)

A DNAStringSet instance of length 10376
    width seq
[1]     1 G
[2]     1 T
[3]     1 A
[4]     1 T
[5]     1 T
...   ... ...
[10372]     1 G
[10373]     1 G
[10374]     1 G
[10375]     1 A
[10376]     1 C

tempo[[1]]
A DNAStringSet instance of length 1
width seq
[1]     1 G

但我不想要这种格式。我只想要碱基字符串,以便将它们作为列插入新数据框中。我想要这个:

G
T
A
T
T

我用这个封装方法完成了这个:

as.character(tempo@unlistData)

但是,它返回的行数比 tempo 多 10 行!这个结果的头部和尾部和节奏是完全一样的,所以中间的某个地方有10个额外的不应该形成的行(不是NA)

【问题讨论】:

  • 一个可重现的例子在这里会有所帮助!
  • 那么你的问题是什么?我们当然需要查看重现错误的数据,以帮助您解决长度问题,如果这是您的问题
  • 对不起,我将编辑问题以使其更清晰,也许可以重现。我的问题是:如何将 DNAstringsSetList 转换为普通列表或字符串向量?

标签: r bioinformatics vcf-variant-call-format


【解决方案1】:

您可以通过DNAStringDNAStringSet 致电as.character

as.character(tempo[1 : 5])
# [1] "G" "T" "A" "T" "T"

【讨论】:

  • 我已经尝试了几次:并得到错误:“ as.vector(x, mode = "character") 中的错误:没有将这个 S4 类强制为向量的方法” 它适用于你呢?
  • @RicardoGuerreiro 这绝对有效。确保实际加载了 {Biostrings} 包。如果问题仍然存在,请重新启动您的 R 会话。如果它仍然仍然存在,请重新安装 {Biostrings} 包。
【解决方案2】:

一个简单的循环解决了这个问题,使用同一个库的 toString 函数:

ALT <-0
for (i in 1:nrow(vcf)){ ALT[i] <- toString(tempo[[i]]) }

但是,我不知道为什么 tempo@unlistData 检索到太多行。不靠谱。

【讨论】:

    猜你喜欢
    • 2015-05-27
    • 2017-11-30
    • 2011-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多