New to R. Recently working through an ATAC-seq workshow in R.
In Section 5.1 of where I call the makeGRangesFromDataFrame function I get the following error -
> atac_esca.gr <- makeGRangesFromDataFrame(atac_esca,keep.extra.columns = T)
Error in makeGRangesFromDataFrame(atac_esca, keep.extra.columns = T) : could not find function "makeGRangesFromDataFrame"
I had previously installed the GenomicRanges package and I tried again. No joy. So I attached the package require(GenomicRanges)
and now when I receive the following error when I go to repeat the same call -
> atac_esca.gr <- makeGRangesFromDataFrame(atac_esca,keep.extra.columns = T)
Error in inherits(object, class2) : 'what' must be a character vector
[Edit]: dput results
> 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"
Can anyone tell me what I am doing wrong here?
[Using R Studio 1.2.5033 - R 3.6.3 - Windows 10]
Thanks in advance,
R.
You have a tibble, and the function makeGRangesFromDataFrame
works with a data.frame. It throws some problems when dealing with the extra columns:
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"
This works:
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 *
To keep the other columns, you need to convert to 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