我有以下数据:
# you can input data by run following script in Rstudio R_gui or R
# this is a dput output
# so you can run it for import data
library(GenomicRanges)
gr_test <- new("GRanges", seqnames = new("Rle", values = structure(1L,
levels = c("2", "6"), class = "factor"), lengths = 1L,
elementMetadata = NULL,
metadata = list()), ranges = new("IRanges", start = 46550131L,
width = 26786L, NAMES = NULL, elementType = "ANY", elementMetadata = NULL,
metadata = list()), strand = new("Rle", values = structure(3L, levels = c("+", "-", "*"), class = "factor"), lengths = 1L,
elementMetadata = NULL,
metadata = list()), seqinfo = new("Seqinfo", seqnames = c("2", "6"), seqlengths = c(243199373L, 171115067L), is_circular = c(FALSE,
FALSE), genome = c("GRCh37.p13", "GRCh37.p13")), elementMetadata =
new("DFrame",
rownames = NULL, nrows = 1L, elementType = "ANY", elementMetadata = NULL,
metadata = list(), listData = list(hap_id = "2_46500819_46600894",
chr = 2L, hap_start = 46500819L, hap_end = 46600894L,
hap_num_id = 1113L, alelles_start = 46550130, alelles_end = 46576916,
alelles_count = 12L, HAN_freq = 0.0512821, TIB_freq = 0.7763155,
HAN_count = 36L, TIB_count = 57L, min_TIB_count = 36L,
min_HAN_count = 57L, HAN_freq_mean = 0.0630342083333333,
TIB_freq_mean = 0.75438575, diff_median = 0.6724019,
diff_mean = 0.691351541666667, gene_symbol = "EPAS1",
name = "NM_001430", score = 0, itemRgb = NA_character_,
thick = new("IRanges", start = 46525051L, width = 86749L,
NAMES = NULL, elementType = "integer", elementMetadata = NULL,
metadata = list()), blocks = new("CompressedIRangesList",
unlistData = new("IRanges", start = c(1L, 49472L,
58750L, 59323L, 63237L, 63484L, 72426L, 78289L, 79138L,
80493L, 81256L, 82826L, 84195L, 84574L, 85024L, 87108L
), width = c(536L, 191L, 152L, 85L, 119L, 206L, 107L,
148L, 215L, 194L, 111L, 491L, 127L, 115L, 174L, 2195L
), NAMES = NULL, elementType = "integer", elementMetadata = NULL,
metadata = list()), elementType = "IRanges",
elementMetadata = NULL, metadata = list(), partitioning = new("PartitioningByEnd",
end = 16L, NAMES = NULL, elementType = "ANY",
elementMetadata = NULL, metadata = list())),
SYMBOL = "EPAS1")), elementType = "ANY", metadata = list())
我尝试将其转换为data.frame,但我看到一些错误,我不知道为什么
df <- as.data.frame(gr_test)
df
Error in h(simpleError(msg, call)) :
在为'unname'函数选择方法时评估'obj'参数出了错: IRanges objects don't support [[, as.list(), lapply(), or unlist() at the moment
问题是mcols(gr_test)$blocks
是一个IRangesList,没有办法将其有意义地转换为数据框架的一列,因为您的GRanges对象有一行,而该列表中的IRanges对象有许多。您可以删除它以使转换成为可能mcols(gr_test)$blocks<-NULL
。