Save monocle objects

The save_monocle_objects() and load_monocle_objects() functions save and load complete cell_data_set objects. The Monocle3 cell_data_set can include UMAP models, nearest neighbor indexes, and BPCells matrix objects, which are not R objects, and cannot be written or read by the R saveRDS() and readRDS() functions. The UMAP models and nearest neighbor indexes are used for projecting data sets and the BPCells matrix objects are used to store count matrices on disk rather than in memory. For convenience, the load_monocle_objects() recognizes and reads cell_data_sets saved using saveRDS().

Save monocle objects

The save_monocle_objects() function saves all of the information in a cell_data_set to files that are stored in a directory with the name specified by the directory_path argument. The optional comment argument stores a memo string with the objects, which is reported when the cell_data_set is loaded with load_monocle_objects().

save_monocle_objects(cds=cds, directory_path='my_cds_objects', comment='This is my example cds. Stored 2022-04-18.')

Load monocle objects

The load_monocle_objects() function loads the complete data set into R from the files in the directory specified by the directory_path argument.

cds <- load_monocle_objects(directory_path='my_cds_objects')

By default, the save_monocle_objects() function makes the monocle objects directory and then makes a tar archive file of the directory so that the directory contents can be copied easily. If you decide to remove the directory, verify that the tar archive was made successfully, in case there was a problem such as running out of disk space. The save_monocle_objects() function has an archive_control parameter that gives some control over making the archive.

The monocle objects directory contains files that may include the following

  • an RDS file of the R cell_data_set, excluding the non-R objects
  • annoy nearest neighbor index files
  • a BPcells counts matrix directory
  • an RDS file of with a table of information about the files in the monocle objects directory

Previous Next