`MOFAobject@expectations` is empty list
1
1
Entering edit mode
Dan • 0
@63648ae2
Last seen 21 days ago
United States

Hello

I run the tutorial (https://raw.githack.com/bioFAM/MOFA2_tutorials/master/R_tutorials/CLL.html)

library(MOFA2)
library(MOFAdata)
library(data.table)
library(ggplot2)
library(tidyverse)

utils::data("CLL_data") 
MOFAobject <- create_mofa(CLL_data)

MOFAobject

data_opts <- get_default_data_options(MOFAobject)
model_opts <- get_default_model_options(MOFAobject)
model_opts$num_factors <- 15

train_opts <- get_default_training_options(MOFAobject)
train_opts$convergence_mode <- "slow"
train_opts$seed <- 42

MOFAobject <- prepare_mofa(MOFAobject,
                           data_options = data_opts,
                           model_options = model_opts,
                           training_options = train_opts
)

MOFAobject@expectations

only get

list()

sessionInfo()

R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.5.1     stringr_1.5.0     dplyr_1.1.0       purrr_1.0.1       readr_2.1.2       tidyr_1.3.0      
 [7] tibble_3.2.1      tidyverse_1.3.1   ggplot2_3.4.2     data.table_1.14.6 MOFAdata_1.12.0   MOFA2_1.6.0      

loaded via a namespace (and not attached):
 [1] matrixStats_0.63.0   fs_1.5.2             lubridate_1.9.2      filelock_1.0.2       RColorBrewer_1.1-3  
 [6] httr_1.4.4           tools_4.2.3          backports_1.4.1      utf8_1.2.3           R6_2.5.1            
[11] HDF5Array_1.20.0     uwot_0.1.14          DBI_1.1.2            BiocGenerics_0.42.0  colorspace_2.1-0    
[16] rhdf5filters_1.4.0   withr_2.5.0          tidyselect_1.2.0     compiler_4.2.3       cli_3.5.0           
[21] rvest_1.0.2          basilisk.utils_1.8.0 xml2_1.3.3           DelayedArray_0.18.0  scales_1.2.1        
[26] digest_0.6.31        rmarkdown_2.19       basilisk_1.8.1       pkgconfig_2.0.3      htmltools_0.5.4     
[31] MatrixGenerics_1.4.3 dbplyr_2.1.1         fastmap_1.1.0        rlang_1.1.1          readxl_1.3.1        
[36] rstudioapi_0.13      farver_2.1.1         generics_0.1.3       jsonlite_1.8.4       magrittr_2.0.3      
[41] Matrix_1.5-3         Rcpp_1.0.10          munsell_0.5.0        S4Vectors_0.34.0     Rhdf5lib_1.14.2     
[46] fansi_1.0.4          reticulate_1.26      lifecycle_1.0.3      stringi_1.7.12       yaml_2.3.6          
[51] rhdf5_2.36.0         Rtsne_0.16           plyr_1.8.8           grid_4.2.3           parallel_4.2.3      
[56] ggrepel_0.9.3        crayon_1.5.2         dir.expiry_1.4.0     lattice_0.20-45      haven_2.4.3         
[61] cowplot_1.1.1        hms_1.1.1            knitr_1.41           pillar_1.9.0         reshape2_1.4.4      
[66] stats4_4.2.3         reprex_2.0.1         glue_1.6.2           evaluate_0.19        modelr_0.1.8        
[71] png_0.1-8            vctrs_0.5.2          tzdb_0.2.0           cellranger_1.1.0     gtable_0.3.3        
[76] assertthat_0.2.1     xfun_0.36            broom_0.7.12         pheatmap_1.0.12      IRanges_2.30.1      
[81] corrplot_0.92        timechange_0.2.0     ellipsis_0.3.2

Can you please let me know what is wrong with my codes? Thanks

MOFA2 • 709 views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 30 minutes ago
United States

The tutorial you are using may be perfectly fine, but I would caution you against ever using the @ function to dig around in S4 objects. If the authors of a package want you to be able to access data in a particular slot, they should have provided you an accessor function to do so. The rationale for an S4 object is to shield the end user from having to know about the underlying data structure and to provide functions that make interacting with a very complicated structure simple for the end user.

This point is illustrated by the section directly above where they say to look at things using the @ function. It says

# NOTE: The software has evolved since the original publication and the results will not be 100% identical to the original publication, please use the pretrained model if you are running through the vignette for the fist time
# MOFAobject <- run_mofa(MOFAobject, outfile="/Users/ricard/Downloads/MOFA2_CLL.hdf5")
# saveRDS(MOFAobject,"MOFA2_CLL.rds")

# Load precomputed model
MOFAobject <- readRDS(url("http://ftp.ebi.ac.uk/pub/databases/mofa/cll_vignette/MOFA2_CLL.rds"))

Basically they are saying that the underlying S4 object has been changed since they originally wrote this tutorial, and now you have to get an old version of the object in order for the results to be the same. Which is exactly what I am talking about - any accessor that the authors of MOFA2 have created should work identically from version to version, so you as an end user don't have to concern yourself with the complexities of the underlying data structure. It's not super helpful for a new user to have a tutorial that says 'well, we used to be able to do this, but cannot do so any longer, so here is an old object we saved so you can still do what we once did'.

Anyway, if you had read that and downloaded the old object, it would have worked for you.

> MOFAobject <- readRDS(url("http://ftp.ebi.ac.uk/pub/databases/mofa/cll_vignette/MOFA2_CLL.rds"))
> names(MOFAobject@expectations)
[1] "Z" "W"
ADD COMMENT

Login before adding your answer.

Traffic: 950 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6