Way to save model directly in R
hsiaoyi0504 opened this issue · comments
Hi there, thanks for providing such a package.
When I preform MOFA, I sometimes need to update the sample metadata after running the model.
Is there a way I could directly save it in R? I trace the code but looks like the model was written into HDF5 in python.
Specifically, the feature I am hoping to have is like
MOFAobject_viewScale <- run_mofa(MOFAobject_viewScale, outfile="./result/MOFA.hdf5", save_data = T,
use_basilisk = TRUE)
samples_metadata(MOFAobject_viewScale) <- sample_annot
save_model(MOFAobject)
Hey @hsiaoyi0504,
This is correct that there's actually no functionality to write or modify the model file in R (natively). The training is done in Python (with mofapy2), and this is the only place where the writing happens.
Generally, if metadata is something that changes but is not reflected in the model itself, a possible workflow here would be to join the metadata from the model upon loading it with the "external" metadata.
A more technical perspective is that having this feature omitted for historical reasons actually helps us to avoid a lot of boilerplate code for making sure write operations in R don't corrupt the file for reading with Python/h5py, across many different versions of both, and vice versa.
This also becomes less of an issue with frameworks like muon, which have interfaces for MOFA and enable (meta)data management separately from the model training.