Hi, I am trying to annotate CpG calls ( a methylkit object). meth_gr has CpG calls coerced into GRanges. gene_bodies_hg38 has the gene body information extracted from a TXDB object made with Gencode 39 GTF.
I have used the findOverlaps function to find the matches between "gene_bodies_hg38" and "meth_gr" and coerce them into a data frame. My code is provided sequentially below:
matches <- findOverlaps(meth_gr,gene_bodies_hg38) names(meth_gr) <- NULL names(gene_bodies_hg38) <- NULL meth_gr[matches@from]
gene_bodies_hg38[matches@to]
Problematic code
mcols(meth_gr[matches@from]) <- as.data.frame(gene_bodies_hg38[matches@to])`
Error in validObject(object) : invalid class “GRanges” object: names of metadata columns cannot be one of "seqnames", "ranges", "strand", "seqlevels", "seqlengths", "isCircular", "start", "end", "width", "element"
How can I resolve this error?
please also include the results of running the following in an R session
sessionInfo( )
`R version 4.1.2 (2021-11-01) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Monterey 12.2.1
Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale: 1 en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages: 1 grid stats4 stats graphics grDevices utils datasets methods base
other attached packages:
1 GenomicFeatures_1.46.5 AnnotationDbi_1.56.2 Biobase_2.54.0 rtracklayer_1.54.0 DT_0.21
[6] data.table_1.14.2 genomation_1.26.0 methylKit_1.20.0 GenomicRanges_1.46.1 GenomeInfoDb_1.30.1
[11] IRanges_2.28.0 S4Vectors_0.32.3 BiocGenerics_0.40.0
loaded via a namespace (and not attached):
1 colorspace_2.0-3 rjson_0.2.21 ellipsis_0.3.2 mclust_5.4.9
[5] qvalue_2.26.0 XVector_0.34.0 rstudioapi_0.13 bit64_4.0.5
[9] fansi_1.0.2 mvtnorm_1.1-3 xml2_1.3.3 splines_4.1.2
[13] R.methodsS3_1.8.1 cachem_1.0.6 impute_1.68.0 knitr_1.37
[17] jsonlite_1.8.0 seqPattern_1.26.0 Rsamtools_2.10.0 gridBase_0.4-7
[21] dbplyr_2.1.1 png_0.1-7 R.oo_1.24.0 readr_2.1.2
[25] compiler_4.1.2 httr_1.4.2 assertthat_0.2.1 Matrix_1.4-0
[29] fastmap_1.1.0 limma_3.50.1 cli_3.2.0 prettyunits_1.1.1
[33] htmltools_0.5.2 tools_4.1.2 coda_0.19-4 gtable_0.3.0
[37] glue_1.6.2 GenomeInfoDbData_1.2.7 reshape2_1.4.4 dplyr_1.0.8
[41] rappdirs_0.3.3 Rcpp_1.0.8.2 bbmle_1.0.24 jquerylib_0.1.4
[45] vctrs_0.3.8 Biostrings_2.62.0 nlme_3.1-155 crosstalk_1.2.0
[49] xfun_0.30 stringr_1.4.0 fastseg_1.40.0 lifecycle_1.0.1
[53] restfulr_0.0.13 gtools_3.9.2 XML_3.99-0.9 zlibbioc_1.40.0
[57] MASS_7.3-55 scales_1.1.1 vroom_1.5.7 BSgenome_1.62.0
[61] hms_1.1.1 MatrixGenerics_1.6.0 parallel_4.1.2 SummarizedExperiment_1.24.0
[65] curl_4.3.2 yaml_2.3.5 memoise_2.0.1 ggplot2_3.3.5
[69] emdbook_1.3.12 sass_0.4.0 biomaRt_2.50.3 bdsmatrix_1.3-4
[73] stringi_1.7.6 RSQLite_2.2.10 BiocIO_1.4.0 plotrix_3.8-2
[77] filelock_1.0.2 BiocParallel_1.28.3 rlang_1.0.2 pkgconfig_2.0.3
[81] matrixStats_0.61.0 bitops_1.0-7 evaluate_0.15 lattice_0.20-45
[85] purrr_0.3.4 GenomicAlignments_1.30.0 htmlwidgets_1.5.4 bit_4.0.4
[89] tidyselect_1.1.2 plyr_1.8.6 magrittr_2.0.2 R6_2.5.1
[93] generics_0.1.2 DelayedArray_0.20.0 DBI_1.1.2 pillar_1.7.0
[97] mgcv_1.8-39 KEGGREST_1.34.0 RCurl_1.98-1.6 tibble_3.1.6
[101] crayon_1.5.0 KernSmooth_2.23-20 utf8_1.2.2 BiocFileCache_2.2.1
[105] tzdb_0.2.0 rmarkdown_2.13 progress_1.2.2 blob_1.2.2
[109] digest_0.6.29 numDeriv_2016.8-1.1 R.utils_2.11.0 munsell_0.5.0
[113] bslib_0.3.1
`
Thanks for the reply. I tried using the accessors with this command-
yet, I got the same error.
Did you see the part of my original answer where I explained that error?
Also, what are you trying to do with this code:
That doesn't really do anything since you have already ensured that those two quantities are equal. Well, it does something - note that these days
=
is the same as<-
because we are savages now, and so you are doing the same thing asBut it does the same thing as say
Which is a bit of a tautology.
Hi,
Since the names of the metadata columns were causing the error; I made a data frame from "gene_bodies_hg38", changed the column names and coerced it into GRanges, reran the findOverlaps and mcols step. However, I ran into the same error.
It would be really helpful if you can share the command (with the accessors) that you think will work for me.
And please refrain from using terms like "savages". Everyone in Bioconductor might not be an R savant!