gpt4 book ai didi

r - 在 ATAC-seq 的 R 工作流程中使用 makeGRangesFromDataFrame 时出错

转载 作者:行者123 更新时间:2023-12-02 04:39:39 26 4
gpt4 key购买 nike

R 新手。最近正在研究 ATAC-seq workshow in R

在第 5.1 节中,我调用 makeGRangesFromDataFrame 函数,出现以下错误 -

> atac_esca.gr <- makeGRangesFromDataFrame(atac_esca,keep.extra.columns = T)
Error in makeGRangesFromDataFrame(atac_esca, keep.extra.columns = T) : could not find function "makeGRangesFromDataFrame"

我之前安装了 GenomicRanges 软件包,并再次尝试。没有喜悦。所以我附上了包 require(GenomicRanges) 现在,当我重复相同的调用时收到以下错误 -

> atac_esca.gr <- makeGRangesFromDataFrame(atac_esca,keep.extra.columns = T)
Error in inherits(object, class2) : 'what' must be a character vector

[编辑]:输出结果

> dput(head(atac_esca,10))
structure(list(seqnames = c("chr1", "chr1", "chr1", "chr1", "chr1",
"chr1", "chr1", "chr1", "chr1", "chr1"), start = c(1290095, 1291115,
1291753, 1440824, 1630188, 2030218, 2184484, 2185113, 2185905,
2186860), end = c(1290596, 1291616, 1292254, 1441325, 1630689,
2030719, 2184985, 2185614, 2186406, 2187361), name = c("ESCA_107",
"ESCA_108", "ESCA_109", "ESCA_160", "ESCA_179", "ESCA_341", "ESCA_539",
"ESCA_540", "ESCA_541", "ESCA_542"), score = c(2.46437811814343,
2.58792851900195, 7.57996223017863, 4.46727398384637, 20.6213237496952,
15.5725811237533, 19.2854359599157, 11.1907656456091, 22.2148888990001,
22.8844119795596), annotation = c("3' UTR", "3' UTR", "3' UTR",
"3' UTR", "3' UTR", "3' UTR", "3' UTR", "3' UTR", "3' UTR", "3' UTR"
), percentGC = c(0.676646706586826, 0.702594810379242, 0.63872255489022,
0.658682634730539, 0.728542914171657, 0.6187624750499, 0.578842315369261,
0.604790419161677, 0.63872255489022, 0.439121756487026), percentAT = c(0.323353293413174,
0.297405189620758, 0.36127744510978, 0.341317365269461, 0.271457085828343,
0.3812375249501, 0.421157684630739, 0.395209580838323, 0.36127744510978,
0.560878243512974)), spec = structure(list(cols = list(seqnames = structure(list(), class = c("collector_character",
"collector")), start = structure(list(), class = c("collector_double",
"collector")), end = structure(list(), class = c("collector_double",
"collector")), name = structure(list(), class = c("collector_character",
"collector")), score = structure(list(), class = c("collector_double",
"collector")), annotation = structure(list(), class = c("collector_character",
"collector")), percentGC = structure(list(), class = c("collector_double",
"collector")), percentAT = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1), class = "col_spec"), row.names = c(NA,
10L), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"))

> head (atac_esca)
seqnames start end name score annotation percentGC percentAT
1 chr1 1290095 1290596 ESCA_107 2.464378 3' UTR 0.6766467 0.3233533
2 chr1 1291115 1291616 ESCA_108 2.587929 3' UTR 0.7025948 0.2974052
3 chr1 1291753 1292254 ESCA_109 7.579962 3' UTR 0.6387226 0.3612774
4 chr1 1440824 1441325 ESCA_160 4.467274 3' UTR 0.6586826 0.3413174
5 chr1 1630188 1630689 ESCA_179 20.621324 3' UTR 0.7285429 0.2714571
6 chr1 2030218 2030719 ESCA_341 15.572581 3' UTR 0.6187625 0.3812375

> packageVersion("GenomicRanges")
[1] ‘1.38.0’

> class(atac_esca)
[1] "spec_tbl_df" "tbl_df" "tbl" "data.frame"

谁能告诉我我在这里做错了什么?

[使用 R Studio 1.2.5033 - R 3.6.3 - Windows 10]

提前致谢,

R。

最佳答案

您有一个 tibble,并且函数 makeGRangesFromDataFrame 与 data.frame 一起使用。处理额外的列时会引发一些问题:

str(atac_esca)
Classes ‘spec_tbl_df’, ‘tbl_df’, ‘tbl’ and 'data.frame': 10 obs. of 8 variables:
$ seqnames : chr "chr1" "chr1" "chr1" "chr1" ...
$ start : num 1290095 1291115 1291753 1440824 1630188 ...
$ end : num 1290596 1291616 1292254 1441325 1630689 ...
$ name : chr "ESCA_107" "ESCA_108" "ESCA_109" "ESCA_160" ...
$ score : num 2.46 2.59 7.58 4.47 20.62 ...
$ annotation: chr "3' UTR" "3' UTR" "3' UTR" "3' UTR" ...
$ percentGC : num 0.677 0.703 0.639 0.659 0.729 ...
$ percentAT : num 0.323 0.297 0.361 0.341 0.271 ...
- attr(*, "spec")=List of 3
..$ cols :List of 8
.. ..$ seqnames : list()
.. .. ..- attr(*, "class")= chr "collector_character" "collector"
.. ..$ start : list()
.. .. ..- attr(*, "class")= chr "collector_double" "collector"

这有效:

 makeGRangesFromDataFrame(atac_esca)
GRanges object with 10 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr1 1290095-1290596 *
[2] chr1 1291115-1291616 *
[3] chr1 1291753-1292254 *

要保留其他列,您需要转换为 data.frame:

makeGRangesFromDataFrame(as.data.frame(atac_esca),keep.extra.columns = TRUE)
GRanges object with 10 ranges and 5 metadata columns:
seqnames ranges strand | name score
<Rle> <IRanges> <Rle> | <character> <numeric>
[1] chr1 1290095-1290596 * | ESCA_107 2.46437811814343
[2] chr1 1291115-1291616 * | ESCA_108 2.58792851900195
[3] chr1 1291753-1292254 * | ESCA_109 7.57996223017863
[4] chr1 1440824-1441325 * | ESCA_160 4.46727398384637

关于r - 在 ATAC-seq 的 R 工作流程中使用 makeGRangesFromDataFrame 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60990559/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com